如标题所示,我无法使用以下代码在 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
我不知道还有什么没做。
请帮帮我。非常感谢。
最佳答案
我已经通过安装来自 download link 的二进制文件解决了这个问题由 this 提供回答。
它将所有 opencv DLL 复制到 C:\Python27(或其他文件)。但我不明白为什么它不能更早工作,因为我已经将这些 DLL 包含到我的 PATH 中
关于python - OpenCV VideoCapture 无法在 Python 中读取视频,但可以在 VS11 中读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16374633/