python thumbnail
Python hosting: Host, run, and code Python in the cloud!
Inspired by Netflix, we decided to implement a focal point algorithm. If you use the generated thumbnails on mobile websites, it may increase your click-through-rate (CTR) for YouTube videos. Eiterway, it’s a fun experiment.
Related course:
Master Computer Vision with OpenCV
Focal Point
All images have a region of interest, usually a person or face.
This algorithm that finds the region of interest is called a focal point algorithm. Given an input image, a new image (thumbnail) will be created based on the region of interest.
Start with an snapshot image that you want to use as a thumbnail. We use Haar features to find the most interesting region in an image. The haar cascade files can be found here:
- https://raw.githubusercontent.com/Itseez/opencv/master/data/lbpcascades/lbpcascade_frontalface.xml
- https://github.com/adamhrv/HaarcascadeVisualizer
Download these files in a /data/ directory.
|
We load the haar cascade file using cv2.CascadeClassifier() and we load the image using cv2.imread()
Then bodyCascade.detectMultiScale() detects regions of interest using the loaded haar features.
The image is saved as thumbnail using cv2.imwrite() and finally we show the image and highlight the region of interest with a rectangle. After running you will have a nice thumbnail for mobile webpages or apps.
If you also want to detect both body and face you can use:
|
Related course:
Master Computer Vision with OpenCV
Leave a Reply: