OpenCV camera just showing black output

asked 2014-03-27 11:51:07 -0500

Aakash Jolly gravatar image

updated 2014-03-27 13:00:29 -0500

berak gravatar image

I am following these tutorials Although the code functions properly, but it doesn't show anything except black screen on the frame window. I don't know why is this happening.

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

    ret, frame =
    if cap.isOpened() == 0:

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    if cv2.waitKey(1) & 0xFF == ord('q'):


I have read in some posts that OpenCV might not be supporting my camera. So i don't know what is happening exactly?

edit retag flag offensive close merge delete


why don't you check to see if it is open before you read? And flag an error if it is not?

Will Stewart gravatar imageWill Stewart ( 2014-03-27 14:34:21 -0500 )edit

@Will Stewart i tried changing cv2.VideoCapture('path of some video') then it works fine so i guess that's not the problem

Aakash Jolly gravatar imageAakash Jolly ( 2014-03-27 15:23:51 -0500 )edit

Is this a webcam or an IPcam? If the former, do you see anything at /dev/ttyUSB0? Or other, if that is already taken?

Will Stewart gravatar imageWill Stewart ( 2014-03-27 21:11:10 -0500 )edit

It's just a webcam. Tried running my code in Linux works completely fine, i don't know why it doesn't work in Windows.. makes me hate Windows more.

Aakash Jolly gravatar imageAakash Jolly ( 2014-03-29 05:59:31 -0500 )edit