Ask Your Question
5

cv2.VideoCapture: Cannot read from file

asked 2012-08-31 09:54:08 -0600

slychief gravatar image

Hi!

I try to process videos using the Python interface. I downloaded OpenCV 2.4.2 and copied the cv2.py file to the Python27\Lib\site-packages folder on Windows 7.

Using the following code, I'm not able to read video files. capture.isOpened() always returns false. Reading images from Webcam using cv2.VideoCapture(0) works fine, but not from files.

Did I miss to copy some importtant files to the Python directory?

import cv2

if __name__ == '__main__':


    capture = cv2.VideoCapture("test.mpg")

    if capture.isOpened():
            print("Device Opened\n")
    else:
            print("Failed to open Device\n")

    (ret, imageMat) = capture.read()

Cheers, Sly

edit retag flag offensive close merge delete

Comments

How you run your app? Try absolute path for test.

Victor1234 gravatar imageVictor1234 ( 2012-09-02 07:10:17 -0600 )edit

is your test.mpg in the same folder of your code?

Mahdi gravatar imageMahdi ( 2012-11-26 14:29:09 -0600 )edit
1

I'm having the same issue: VideoCapture works well with webcam, but no success with files - absolute path and otherwise.

I tried the solutions from here: http://stackoverflow.com/questions/11699298/opencv-2-4-videocapture-not-working-on-windows, but it still doesn't work. I added the folder to the PATH, and copied the dlls around.

errollw gravatar imageerrollw ( 2013-01-09 18:13:15 -0600 )edit

Did you ever find a solution to this?

loughnane gravatar imageloughnane ( 2013-08-13 14:45:53 -0600 )edit

There might be a problem with the ffmpeg dll that is being used. Which build are you following? x86 or x86_64?

prakharmohan gravatar imageprakharmohan ( 2014-02-18 03:54:48 -0600 )edit

DId anyone get the solution of this problem? I am facing the same problem for so many days and still couldn't fix it

AnjaliChanglani gravatar imageAnjaliChanglani ( 2015-02-18 07:47:38 -0600 )edit

Did anyone solved it? I am having the same problem. After added path and copied dll still not working. I am on win 8; 64x.

Vashaman gravatar imageVashaman ( 2017-02-23 07:58:35 -0600 )edit

This post is too old you should ask a new question

LBerger gravatar imageLBerger ( 2017-02-23 08:08:10 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2015-07-17 12:16:33 -0600

wunjo gravatar image

Try including the full file path in cv2.VideoCapture and be sure to change the "\" to "/". OpenCV doesn't like the forward slashes for some reason. Example: cv2.VideoCapture('C:/Project/Videos/test.mpg')Also, see my answer here for more clarification on proper codecs to use: (http://answers.opencv.org/question/66...). Hope this helps!

edit flag offensive delete link more

Comments

Changing "\" to "/" fixed the problem for me!

Fredericco gravatar imageFredericco ( 2019-04-24 09:53:03 -0600 )edit
-1

answered 2018-10-24 01:41:55 -0600

I was getting the same error while using opencv in anaconda3 virtual environment. I checked the buildinformation (cv2.getBuildInformation()) for current opencv version and ffmpeg wasn't marked "yes". To resolve this

  1. I uninstalled opencv from my conda environment ( conda uninstall opencv)

  2. Installed latest ffmpeg using conda-forge channel

  3. Then installed opencv again using conda-forge channel ( conda install -c conda-forge opencv) . Don't install using menpo channel

Doing this resolved the issue for me.

edit flag offensive delete link more

Question Tools

3 followers

Stats

Asked: 2012-08-31 09:54:08 -0600

Seen: 40,048 times

Last updated: Jul 17 '15