2

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.

Junuxx
  • 14,011
  • 5
  • 41
  • 71
max246
  • 568
  • 2
  • 5
  • 11

2 Answers2

11

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

ksyrium
  • 104
  • 2
  • 3
  • 10
tituszban
  • 4,797
  • 2
  • 19
  • 30
0

Resize using cv2: How to resize an image with OpenCV2.0 and Python2.6

Resize using the Python Imaging Library (PIL): How do I resize an image using PIL and maintain its aspect ratio?

Community
  • 1
  • 1
ljk07
  • 952
  • 5
  • 13