Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - CV2 change dimension and quality

I managed to take a picture with Python and CV2 library, but I'd like to change the dimension of the image and get something not high quality and resize it down at 640.

My code is:

cam = VideoCapture(0)   # 0 -> index of camera
s, img = cam.read()
    if s:    # frame captured without any errors
             imwrite(filename,img) #save image

I have tried to use the method set but it doesn't work.

like image 234
max246 Avatar asked Oct 25 '25 22:10

max246


1 Answers

You can resize using opencv:

img = cv2.resize(img, (640, 640))

to set the resolution to 640x640, or

img = cv2.resize(img, (0,0), fx = 0.5, fy = 0.5)

to half each dimention of the image.

If you want worse quality, you can use a blur (I would recommend Gaussian):

img = cv2.GaussianBlur(img, (15,15), 0)

If you want more or less blurry, change the (15,15) (which is the Kernel size).

If you want to learn more about image processing, I found these quite useful:

OpenCV tutorials,

OpenCV image processing

like image 67
tituszban Avatar answered Oct 28 '25 11:10

tituszban