Sorry, this content is no longer available

Ask Your Question
0

How can I set webcam resolution with opencv in python?

asked Nov 21 '18

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)

...

Preview: (hide)

Comments

Read doc : set and properties

LBerger gravatar imageLBerger (Nov 21 '18)edit
1

VideoStream is not even from opencv ;(

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

berak gravatar imageberak (Nov 21 '18)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 (Nov 21 '18)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 (Nov 21 '18)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 (Nov 22 '18)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 (Nov 23 '18)edit

2 answers

Sort by » oldest newest most voted
0

answered Nov 23 '18

Kafan gravatar image

updated Nov 23 '18

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

Preview: (hide)
-2

answered Nov 22 '18

supra56 gravatar image
Correct way like this:
vs = VideoStream(src="http://192.168.75.203/video/mjpg.cgi").start()
while True:
      frame = vs.read()
:
:
:
:
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Nov 21 '18

Seen: 8,026 times

Last updated: Nov 23 '18