IplImage 'None' error on CaptureFromFile() - Python 2.7.1 and OpenCV 2.2 WinXP


I am running Python2.7.1 and OpenCV 2.2 without problems in my WinXP laptop and wrote a tracking program that is working without a glitch. But for some strange reason I cannot get the same program to run in any other computer where I tried to install OpenCV and Python (using the same binaries or appropriate 64 bit binaries). In those computers OpenCV seems to be correctly installed (although I have only tested and CaptureFromCamera() in the webcam of the laptop), but CaptureFromFile() return 'None' and give "error: Array should be CvMat or IplImage" after a QueryFrame, for example.

This simple code:

import cv /
videofile = cv.CaptureFromFile('a.avi') /
frame = cv.QueryFrame(videofile) /
print type(videofile) /
print type(frame)


type 'cv.Capture' /
type 'NoneType'

  • OpenCV and Python are in the windows PATH...
  • I have moved the OpenCV site-packages content back and forth to the Pyhton27 Lib\Site-packages folder.
  • I tried different avi files (just in case it was some CODEC problem). This AVI uses MJPEG encoding (and GSpot reports that ffdshow Video Decoder is used for reading).
  • Images work fine (I think): the simple convert code: im = cv.LoadImageM("c:\tests\colormap3.tif") cv.SaveImage("c:\tests\colormap3-out.png", im) opens, converts and saves the new image...
  • I have tested with AVI files in different folders, using "c:\", "c:/", "c:\" and "c://".

I am lost here... Anyone has any idea of what stupid and noob mistake may be the cause of this? Thanks

By : vag_porto


This must be an issue with the default codecs. OpenCV uses brute force methods to open video files or capture from camera. It goes by trial and error through all sources/codecs/apis it can find in some reasonable order. (at least 1.1 did so). That means that on n different systems (or days) you may get n different ways of accessing the same video. The order of multiple webcams for instance, is also non-deterministic and may depend on plugging order or butterflies.

Find out what your laptop uses, (re)install that on all the systems and retry. Also, in the c version, you can look at the capture's properties look for cvGetCaptureProperty and cvSetCaptureProperty where you might be able to hint to the format.

[EDIT] Just looked i tup in the docs, these functions are also available in Python. Take a look, it should help.

By : AndreasT

It may sound stupid, but I just had the same issue with the same symptoms for the same code snippet (Python 2.7.1, Win 7, OpenCV 2.2.0). I changed file path from

capture = cv.CaptureFromFile('C:\Misc\tree.avi')


capture = cv.CaptureFromFile('C:/Misc/tree.avi')

and voila

By : ilya

I was having this problem, and here is how I fixed it. I took a look at the output of OpenCV's cmake command, and it had the following line:

--     FFMPEG:                     NO

In order to fix this, you might be able to get away with simply installing the following libraries:

sudo apt-get install libavformat-dev libavcodec-dev libavfilter-dev libswscale-dev

Re-running cmake will hopefully now say:

--     FFMPEG:                     YES

Re-compile OpenCV, re-install it, and hopefully you can now read videos. If you still have problems, you can try to compile ffmpeg using the --enable-shared option, using these as guides:


Hope that helps.

By : DrPython

This video can help you solving your question :)
By: admin