5

There is a huge number of questions and corresponding answers of people asking how to set the frame height / width. A small sample below:

I get it OpenCV has issues sometimes with setting frame height / width. In my case I can set a range of widths/heights up to 640 x 512. The drivers for the camera are provided by the manufacturer (i.e. not v4l2 or something similar). What debugging information can I provide or how can I help them understand why I can't set higher widths / frames. Is it a problem with the drivers, with OpenCV with both?

import cv2
c = cv2.VideoCapture(1)
c.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
c.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 1024)

I'm using Ubuntu 14.04 and using OpenCV 2.4.8 in Python.

I found this question which has an accepted answer suggesting that I should be able to make it work. I don't know how to do this part:

What you can do is to investigate your camera driver, make a patch to OpenCV and send it to code.opencv.org. This way others will enjoy your work, the same way you enjoy other's.

double-beep
  • 5,031
  • 17
  • 33
  • 41
evan54
  • 3,585
  • 5
  • 34
  • 61

1 Answers1

0

You could try resizing each frame before displaying, please see code below.

Determine scaling


scale_percent = 40 # percent of original size
width = int(img.shape[1] * scale_percent / 100) 
height = int(img.shape[0] * scale_percent / 100) 
dim = (width, height) 

Apply desired scaling using the cv2.resize, before displaying.


# resize output window
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) 

#show resized frame
cv2.imshow("base_img", resized)

Hope this helps. :)

Dylan Freeman
  • 221
  • 3
  • 12
  • This is what I am trying. Setting the camera parameters seems to have some effect but isn't exact. Perhaps do to how this interacts directly with the camera, which may have a few pre-set resolutions (https://stackoverflow.com/questions/11420748/setting-camera-parameters-in-opencv-python). For my needs this resize method should work. – ArduinoBen Mar 22 '22 at 06:48