IplImage“无” CaptureFromFile() 上的错误 - Python 2.7.1 和 OpenCV 2.2 WinXP

发布于 2024-11-04 05:49:37 字数 954 浏览 0 评论 0原文

我在我的 WinXP 笔记本电脑上运行 Python2.7.1 和 OpenCV 2.2,没有出现任何问题,并编写了一个运行正常的跟踪程序。但由于一些奇怪的原因,我无法在我尝试安装 OpenCV 和 Python 的任何其他计算机上运行相同的程序(使用相同的二进制文件或适当的 64 位二进制文​​件)。在这些计算机中,OpenCV 似乎已正确安装(尽管我只在笔记本电脑的网络摄像头中测试了 CaptureFromCamera() ),但 CaptureFromFile() 返回“无”并在 QueryFrame 之后给出“错误:数组应该是 CvMat 或 IplImage” , 例如。

这个简单的代码:

import cv /
视频文件 = cv.CaptureFromFile('a.avi') /
帧 = cv.QueryFrame(videofile) /
打印类型(视频文件)/
打印类型(帧)

返回:

类型'cv.Capture'/
类型“NoneType”

  • OpenCV 和 Python 在 Windows PATH 中...
  • 我已将 OpenCV 站点包内容来回移动到 Pyhton27 Lib\Site-packages 文件夹。
  • 我尝试了不同的 avi 文件(以防万一是编解码器问题)。此 AVI 使用 MJPEG 编码(GSpot 报道使用 ffdshow Video Decoder 进行读取)。
  • 图像工作正常(我认为):简单的转换代码: im = cv.LoadImageM("c:\tests\colormap3.tif") cv.SaveImage("c:\tests\colormap3-out.png", im) 打开、转换并保存新图像...
  • 我已经使用“c:\”、“c:/”、“c:\”和“c://”在不同文件夹中测试了 AVI 文件。

我在这里迷失了...任何人都知道造成这种情况的原因是什么愚蠢和菜鸟的错误?谢谢

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)

returns:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甚是思念 2024-11-11 05:49:37

这可能听起来很愚蠢,但我只是遇到了同样的问题,对于相同的代码片段(Python 2.7.1、Win 7、OpenCV 2.2.0)具有相同的症状。我将文件路径从

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

更改

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

为 瞧

<type 'cv.Capture'>
<type 'cv.iplimage'>

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')

to

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

and voila

<type 'cv.Capture'>
<type 'cv.iplimage'>
深白境迁sunset 2024-11-11 05:49:37

我遇到了这个问题,这是我解决它的方法。我查看了 OpenCV 的 cmake 命令的输出,它有以下行:

...
--     FFMPEG:                     NO
...

为了解决这个问题,您可能只需安装以下库就可以摆脱困境:

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

重新运行 < code>cmake 现在希望会说:

...
--     FFMPEG:                     YES
...

重新编译 OpenCV,重新安装它,希望您现在可以阅读视频。如果仍有问题,您可以尝试使用 --enable-shared 选项编译 ffmpeg,并使用以下指南:

http://opencv.willowgarage.com/wiki/FFMPEG
http://ubuntuforums.org/showthread.php?t=786095

希望有所帮助。

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:

http://opencv.willowgarage.com/wiki/FFMPEG
http://ubuntuforums.org/showthread.php?t=786095

Hope that helps.

两个我 2024-11-11 05:49:37

这一定是默认编解码器的问题。 OpenCV 使用强力方法打开视频文件或从相机捕获。它以某种合理的顺序对它能找到的所有源/编解码器/api 进行反复试验。 (至少 1.1 是这样做的)。
这意味着在 n 个不同的系统(或几天)上,您可能会以 n 种不同的方式访问同一视频。例如,多个网络摄像头的顺序也是不确定的,并且可能取决于插入顺序或蝴蝶。

找出您的笔记本电脑使用的内容,在所有系统上(重新)安装它并重试。
另外,在c版本中,您可以查看捕获的属性
查找 cvGetCaptureProperty 和 cvSetCaptureProperty,您可以在其中提示格式。

[编辑]
刚刚查看了文档,这些函数在 Python 中也可用。看看吧,应该有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文