cv2.VideoCapture(0).isOpened() returns False all the time

asked 2017-10-19 16:48:49 -0600

tang232 gravatar image

Hi all,

I am new to opencv, and having some problems setting up opencv on my computer. I am using Anaconda 2.7 and PsychoPy for my experiments on a Windows 10 platform. After I put cv2.pyd into both anaconda/lib/site-packages and psychopy/lib/site-packages, when I run cv2.VideoCapture(0), I could get a number indicating a camera connected (I guess), but cv2.VideoCapture(0).isOpened() returns me False all the time. I tried other software to check the camera, and the camera seemed fine.

Anyone could help with this problem? I would appreciate it!

Yu

edit retag flag offensive close merge delete

Comments

Did you ever solve this? I'm having the exact same problem.

roach374 gravatar imageroach374 ( 2018-02-26 01:29:40 -0600 )edit

Try this:

cap = cv2.VideoCapture('chaplin.mp4')

# Check if camera opened successfully
if (cap.isOpened()== False): 
  print("Error opening video stream or file")

# Read until video is completed
while(cap.isOpened()):
  # Capture frame-by-frame
  ret, frame = cap.read()
  if ret == True:

    # Display the resulting frame
    cv2.imshow('Frame',frame)

    # Press Q on keyboard to  exit
    if cv2.waitKey(25) & 0xFF == ord('q'):
      break

  # Break the loop
  else: 
    break

# When everything done, release the video capture object
cap.release()

# Closes all the frames
cv2.destroyAllWindows()
supra56 gravatar imagesupra56 ( 2018-02-26 03:43:57 -0600 )edit

Thanks supra56, I'll try this, but this code is opening a video file. Even if it works, it's not what I need. I need to open the actual camera (so, cv2.VideoCapture(0) ). This is also a headless system, so cv2.imshow won't work. If I comment out the bits that won't work on a headless system, your code above is basically the same as the code that I'm trying to currently run, and I'm getting "Error opening video stream or file".

roach374 gravatar imageroach374 ( 2018-02-26 12:00:26 -0600 )edit

Hi, it's been a long time, but I still did not solve the problem. The camera I'm using is Thorlabs DCC1545M, and I did not have any success in opening it with cv2.VideoCapture() on windows 10. I was wondering if it is because opencv do not have the right driver for it?

tang232 gravatar imagetang232 ( 2019-02-15 13:34:02 -0600 )edit

Did you get the solution, I am having similar problem

Uday gravatar imageUday ( 2019-07-26 07:58:02 -0600 )edit