cap.read(0) does not work well

asked 2017-05-06 12:25:27 -0500

Hi everyone,

I'm a begginer with opencv and I need a program that uses a webcam. I found the basic code en Google :

import numpy as np
import cv2

cv2.namedWindow("preview")

cap = cv2.VideoCapture(0)


while True:

    ret, frame = cap.read()

    cv2.imshow("preview", frame)



    key = cv2.waitKey(1)
    if key == 27: # exit on ESC
        break


cap.release()
cv2.destroyWindow("preview")

My laptop cam is defined by index 0 and it is switch on by this code (a green LED tells me this). This cam also works for general use.

The problem is that 'frame' is an array that contains mostly black pixels, but not all (ie ~50 of them are non-zeros).

Does someone have an idea of the problem ? Does just OpenCV not support my webcam (..but then where do the few colors come from ?) ?

Thanks !

edit retag flag offensive close merge delete

Comments

You must download an suitable example on internet (with opencv) - you can download from opencv home. You run it and show me result.

hoang anh tuan gravatar imagehoang anh tuan ( 2017-05-07 21:10:59 -0500 )edit

First I don't know python but I think your example is like this one.

Can you give platform name and opencv version and lapttop name? Check if your system is up to date

try to change gain and brightness using opencv http://docs.opencv.org/2.4/modules/hi...

LBerger gravatar imageLBerger ( 2017-05-08 02:22:44 -0500 )edit