简体   繁体   中英

Python OpenCV - Webcam capture returns blank screen

Im using pycharm to run the following code.But Im getting a black screen with no output. cv2 version - 4.0.0 (intall by pycharm installer) Python - 3.6 windows 10 64bit

   import cv2

   print(cv2.__version__)
   video_capture = cv2.VideoCapture(0)


   while (video_capture.isOpened()):
      ret, frame = video_capture.read()
      if ret == True:
        cv2.imshow('win', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
      print(frame)

I just printed the frame and I got following output with lot of zeros. Note that I have used the same webcam in same machine with Opencv and Java and it works fine.

[[[ 80   1   9]
  [114 120   1]
  [  0   0 176]
  ...
  [  0   0   0]
  [  0   0   0]
  [  0   0   0]]

Please see the blank output screenshot hear

Found the issues, It was my Kaspersky Virus scanner which was blocking it. This is really strange since it light up the Webcam so I never thought it was blocked. Once I disabled virus scanner it worked like a charm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM