Using OpenCV for python to capture webcam get white screen grab

847 Views Asked by At

I'm using python 2.7 on DragonBoard 410c with Debian OS to capture webcam Logitech C920 by opencv but get a white sceen result.

Here is my whole code.

import cv2

cap = cv2.VideoCapture(0)
cap.set(3,1280)
cap.set(4,720)

while(cap.isOpened()):
  ret, frame = cap.read()
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
  cv2.imshow('frame', gray)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release()
cv2.destroyAllWindows()

It worked well without the code "cap.set(3,1280)" and "cap.set(4,720)". I can get the frame with 640x480.

but if I added the code to change the resolution, the window would change but the frame is white.

https://i.stack.imgur.com/HDBgR.jpg

By the way, if I set the resolution to 800x600, the frame will flash between white sceen and camera view.

How can I solve this problem?

0

There are 0 best solutions below