4

作为标题,我无法使用以下代码在 python 中使用 VideoCapture 读取视频:

v = 'C:\\test.mp4'
import cv2
cap = cv2.VideoCapture(v)
if cap.isOpened():
  print "Finally"
else:
  print "BOOM"

BOOM 总是被打印出来。

而在 VS11 中,以下代码有效:

#include "stdafx.h"

#include <opencv2\highgui\highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    string v = "C:\\test.mp4";
    VideoCapture cap;
    cap.open(v);
    if (cap.isOpened()) {
        cout << "Yes!" << endl;
    } else {
        cout << "BOOM" << endl;
    }

    return 0;
}

我确实意识到SO中有一个数字解决方案,但对我没有任何作用。我在 C:\Python27 和 C:\Python27\DLLs 以及 PATH 中有以下 dll

  • opencv_ffmpeg.dll
  • opencv_ffmpeg_64.dll
  • opencv_ffmpeg_245_64.dll
  • opencv_ffmpeg_245.dll

我不知道什么还没有做。

请帮我。非常感谢。

4

1 回答 1

7

我已经通过从这个答案提供的这个下载链接安装二进制文件解决了这个问题。

它将所有 opencv DLL 复制到 C:\Python27 (或者可能是其他文件)。但我不明白为什么它不能更早地工作,因为我已经将这些 DLL 包含在我的 PATH 中

于 2013-05-07T02:46:59.570 回答