Setting Camera Parameters in Opencv/Python

Setting Camera Parameters in OpenCV/Python

Not all parameters are supported by all cameras - actually, they are one of the most troublesome part of the OpenCV library. Each camera type - from android cameras to USB cameras to professional ones offer a different interface to modify its parameters. There are many branches in OpenCV code to support as many of them, but of course not all possibilities are covered.

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

There is also a possibility that your camera does not support your request - most USB cams are cheap and simple. Maybe that parameter is just not available for modifications.

If you are sure the camera supports a given param (you say the camera manufacturer provides some code) and do not want to mess with OpenCV, you can wrap that sample code in C++ with boost::python, to make it available in Python. Then, enjoy using it.

Setting camera resolution in OpenCV - pre-built vs. custom build

So I found out that the final issue had to do with OpenCV not using the MJPEG format rather than defaulting to YUYV. Changing this using:

import cv2

vs = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
vs.set(cv2.CAP_PROP_FOURCC, fourcc)

fixed the problem and I can now set the camera using the vs.set() commands.

OPENCV error while captureing video from webcam in python

I looks like input is 0x0 picture, thats why i cannot show, if you know your camera resolution try this maybe:

camera=0
cap = cv2.VideoCapture(camera, cv2.CAP_DSHOW)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1050)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)

while cap.isOpened():
success, image = cap.read()
if not success:
print("Ignoring empty camera frame.")
# If loading a video, use 'break' instead of 'continue'.
continue
cv2.imshow('Image', image)
if cv2.waitKey(5) & 0xFF == ord("q"):
break
cap.release()

good luck



Related Topics



Leave a reply



Submit