Ask Your Question
0

How can I set webcam resolution with opencv in python?

asked 2018-11-21 02:45:04 -0600

sangeun gravatar image

I'm trying to get the maximum resolution that my webcam has..! But I have no idea how to do it.. Does anyone had this problem before? Please give me some comments below. Thanks. Here's my codes.

vs = VideoStream(src=0).start()

fileStream = False

time.sleep(1.0)

total = 0

pre = 0

while True:

if fileStream and not vs.more():

    break

frame = vs.read()
frame = cv2.flip(frame,1)
frame = imutils.resize(frame, width=1280)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

...

edit retag flag offensive close merge delete

Comments

Read doc : set and properties

LBerger gravatar imageLBerger ( 2018-11-21 02:50:14 -0600 )edit
1

VideoStream is not even from opencv ;(

https://github.com/jrosebr1/imutils/b...

berak gravatar imageberak ( 2018-11-21 03:09:27 -0600 )edit

so,unless it's using the picam (we can't help with that), we're here: https://github.com/jrosebr1/imutils/b...

and it's vs.stream.set(something)

berak gravatar imageberak ( 2018-11-21 03:14:04 -0600 )edit

@sangeun , you should be careful with 3rdparty wrappers using opencv code, even if it's from adrian ..

at some point, noone will be able or willing, to dig through layers and layers of wrapping

berak gravatar imageberak ( 2018-11-21 03:16:21 -0600 )edit

@sangeun, there's no way to choose the resolution from an ip capture, using opencv.

please lookup your camera's manual, and try to find out, if they offer a different URL for this

berak gravatar imageberak ( 2018-11-22 14:20:19 -0600 )edit

Thanks for your comments! I should find out the other options from camera setting. Actually I just started to learn both python and opencv, so I'm kind of struggling now haha Thank you again :)

sangeun gravatar imagesangeun ( 2018-11-22 19:16:06 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2018-11-23 00:24:44 -0600

Kafan gravatar image

updated 2018-11-23 00:26:20 -0600

video_capture = cv2.VideoCapture(videoDeviceIndex) video_capture.set(3,640) #Setting webcam's image width video_capture.set(4,480) #Setting webcam' image height

Make sure that the webcam supports the resolution that you are setting to using v4l2-ctl command

edit flag offensive delete link more
-2

answered 2018-11-22 14:15:01 -0600

supra56 gravatar image
Correct way like this:
vs = VideoStream(src="http://192.168.75.203/video/mjpg.cgi").start()
while True:
      frame = vs.read()
:
:
:
:
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-11-21 02:45:04 -0600

Seen: 7,751 times

Last updated: Nov 23 '18