Ask Your Question

isOpened() returns false on files

asked 2019-10-28 11:17:17 -0500

Hey everyone, I've been trying to run the following code:

import cv2
cap = cv2.VideoCapture("asdf.mp4")
while cap.isOpened():
    ret, frame =

    cv2.imshow('frame', frame)

However, cap.isOpened() returns false for anything that is not 0 (webcam). I tried to type both relative and absolute path, but none works. Am I missing something?

Thanks, Tal

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2019-10-28 11:41:49 -0500

supra56 gravatar image

updated 2019-10-28 11:42:53 -0500

You are missing waitKey():

import cv2
cap = cv2.VideoCapture("road.avi")
while cap.isOpened():
    ret, frame =
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
edit flag offensive delete link more


Yeah, I know, but my code doesn't even reach to that point since cap.isOpened() returns false.

TalBarami gravatar imageTalBarami ( 2019-10-28 11:52:37 -0500 )edit

Didn't you added cv2.waiKey()?

supra56 gravatar imagesupra56 ( 2019-10-28 12:00:15 -0500 )edit

No, it fails even before I need to. If I type:

cap = cv2.VideoCapture("asdf.mp4") cap.isOpened() ---> returns false

TalBarami gravatar imageTalBarami ( 2019-10-28 12:26:17 -0500 )edit

Is your file is in the same directory? Type ls -l asdf.mp4

supra56 gravatar imagesupra56 ( 2019-10-28 13:02:41 -0500 )edit

Yes, it is. I also tried to I'm using windows and cv2 was installed with Anaconda for python 3.6.

TalBarami gravatar imageTalBarami ( 2019-10-28 16:44:34 -0500 )edit

Question Tools

1 follower


Asked: 2019-10-28 11:17:17 -0500

Seen: 3,323 times

Last updated: Oct 28 '19