Difference between cv2..VideoCapture(0) and imutils VideoStream(src = 0).start()

Hi, I am using opencv VideoCapture() method and imutils VideoStream() functions to capture video from webcam. This two functions output is different. Position of the camera is fixed. However coverage area differs a lot. what functionality behind this functions? I can set the frame resolution in VideoCapture(). Likewise how to set frame resolution in imutils VideoStream()?

snap of image captured via VideoCapture()

!

snap of image captured via imutils VideoStream()
vs.snap.PNG|627x500

Hi,
May be somebody can help you about imutils but this forum is about opencv. You can explore source code too I think it’s here

1 Like

ok @laurent.berger. thank you

VideoStream() can use VideoCapture() or PiCamera() (on Raspberry Pi) and it runs in thread so it can run faster.

In source code you can see it uses resolution=(320, 240) and this may change output but only for PiCamera. For VideoCapture() it should use default resolution.

You would have to show code which you use. Maybe you set different resolutin in VideoCapture and you use non-default value.

Thanks @furas . I have set the resolution(1920, 1080) of VideoCapture. But not for videostream. I think it’s taking default resolution. How to set the resolution in videostream?

I don’t see any method to set resolution for VideoCapture in VideoStream

It assigns VideoCapture to VideoStream.stream so you may try to use

 s = VideoStream()
 s.stream.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
 s.stream.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

but s.stream is already reading one frame and I don’t know if you can change resolution during reading frames.

Eventually: VideoStream uses class WebCamVideoStream which uses VideoCapture - so you can copy source code of WebCamVideoStream add set() in __init__ before first .read() in this class and use this WebCamVideoStream instead of VideoStream

imutils/webcamvideostream.py at master · jrosebr1/imutils · GitHub

I would strongly suggest seeking support for imutils from the imutils author, on the given github. he knows best what his library is doing.

1 Like

I have tried the above method. but it didn’t change width and height.

ok @crackwitz . I will post the question in github imutils page

1 Like

The VideoStream class can be constructed with the new resolution.

VideoStream(src=0, usePiCamera=False, resolution=(320, 240), framerate=32, **kwargs)