python - OpenCV VideoCapture 无法在 Python 中读取视频,但可以在 VS11 中读取

标签 python opencv ffmpeg

如标题所示,我无法使用以下代码在 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/

相关文章:

python - 如果识别出汽车拍照

java - Imgproc.drawContours(....) 未显示

bash - 循环动画时将 PNG 序列转换为 MP4

ffmpeg - 使用 FFmpeg 的 NVENC 编码器进行 HEVC 10 位编码后的灰色平方伪影

android - ffmpeg android图像和音频合并不起作用

python - 如何从 Catch 状态的前一个函数访问 Step Function 中的错误信息

python - Django 更新而不是插入新记录

python - 无法匹配 url 正则表达式中电子邮件地址后的尾随斜杠

python - OS X 蓝牙编程

c++ - tesseract-ocr是否执行任何图像预处理?