Python: OpencV: resize image

23 11 2012

20121123

resize image with opencv [cv2]

“can’t show full image?” yes, because your image bigger than monitor resolution.
let scale it down.

this sample is show how to resize image down 4 times

code:

import cv2
 filename = "panorama_00098.jpg"
 oriimage = cv2.imread(filename)
 newx,newy = oriimage.shape[1]/4,oriimage.shape[0]/4 #new size (w,h)
 newimage = cv2.resize(oriimage,(newx,newy))
 cv2.imshow("original image",oriimage)
 cv2.imshow("resize image",newimage)
 cv2.waitKey(0)

Image

I added more example, try to see
resize image by width


Actions

Information

2 responses

23 03 2013
sa

Thanks! By the way, line 4 should read newimage = cv2.resize(….)

23 03 2013
enumap

thanks SA , yes it should be “newimage = cv2.resize(oriimage,(newx,newy))”

so I corrected code above.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: