PhD Task: Geometrically transform the stereoscopic 2D image (object position) to a new position based on the photographic composition rules.
For this task, I used the
rule of thirdsto transform the image to a new position.The rule of thirds is a composition guideline that places your subject in the left or right third of an image, leaving the other two thirds more open. While there are other forms of composition, the rule of thirds generally leads to compelling and well-composed shots.
The task was completed on October 13, 2019. Video demo: 2dGeoTrans_poc
Install jupyter notebook:
pip install jupyter notebookClone the repository:
git clone https://github.com/IMSoley/2dGeoTransInstall dependencies:
pip install -r requirements.txtOpen command prompt and type the following:
C:\Users\YourName> python>>>importcv2>>>frompathlibimportPath>>> (Path(cv2.__file__) /'../../../../share/OpenCV/haarcascades/').resolve() # If necessary, create the directory as shown here.>>>exit()
Copy haarcascade files to the above path
Run the notebook:
jupyter notebookin the 2dGeoTrans directory
- OpenCV - Computer Vision Library
- Python - Programming Language
- Jupyter Notebook - Notebook Environment
- PyTest - Unit Testing Framework
- Javascript - For formatting the output
Detecting the keypoints and descriptors of the object in the image with ORB detector. ORB is short for Oriented FAST and Rotated BRIEF.
# creating the numpy image arrayimage_array=cv2.imread(input_image) # creating the orb detectororb_detector=cv2.ORB_create(3) # detecting keypoints and descriptorskeypoints=orb_detector.detect(image_array)
Face detection with Viola-Jones
image_array=cv2.imread(panda_image) cascade_file=''# Path to the cascade fileviola_jones_classifier=cv2.CascadeClassifier(cascade_file) viola_jones_classifier.detectMultiScale(image_array)
Face detection with Haar Cascade
feature_detect_and_show('img/panda1.jpg', g_face_detector)
Combined feature detector: this detector combines the power of both algorithms
FaceDetectorandKeypointDetectorthrough the photographic composition rules.classHybridDetector(FeatureDetector): BREAKPOINT=0.15def__init__(self, n=10) ->None: self.primary=FaceDetector(n, padding=1.5) self.fallback=KeypointDetector(n, padding=1.2) self.breakpoint=self.BREAKPOINTself._number=ndefdetect_features(self, fn: FileName) ->List[Feature]: faces=self.primary.detect_features(fn) iffacesandsum(faces).size>self.breakpoint: returnfacesfeatures=faces+self.fallback.detect_features(fn) returnfeatures[:self._number]
feature_detect_and_show('img/panda1.jpg', HybridDetector())
images= [ 'img/panda1.jpg',
'img/panda2.jpg',
'img/panda3.jpg'
]
detector=HybridDetector()
feature_detect_and_show(images, HybridDetector(), preview=True)For better results, it is recommended to use human images as the haarcascades are very accurate for human faces.





