Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create thumbnails using opencv-python?

I'm trying to downsample my image(using anti-aliasing) using Python-Pillow's im.thumbnail() method.

My code looks like:

MAXSIZE = 1024
im.thumbnail(MAXSIZE, Image.ANTIALIAS)

Can you tell me some alternative in opencv-python to perform this re-sizing operation ?

like image 891
Kaushik Ramachandran Avatar asked Jun 16 '15 07:06

Kaushik Ramachandran


People also ask

How do I create a thumbnail from a video in Python?

You can use ffmpeg-python to create a thumbnail and upload it for use with your video. If you don't want to get into learning FFMPEG, you can also use api. video's endpoint that allows you to pick a time from the video, and have it set as the video thumbnail for you automatically.


1 Answers

You can use cv2.resize . Documentation here: http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#resize

In your case, assuming the input image im is a numpy array:

maxsize = (1024,1024) 
imRes = cv2.resize(im,maxsize,interpolation=cv2.CV_INTER_AREA)

There are different types of interpolation available (INTER_CUBIC, INTER_NEAREST, INTER_AREA,...) but according to the documentation if you need to shrink the image, you should get better results with CV_INTER_AREA.

like image 74
Algold Avatar answered Oct 06 '22 09:10

Algold