【问题标题】:Cannot read video from file while can read from camera无法从文件中读取视频,但可以从相机中读取
【发布时间】:2019-06-22 07:19:42
【问题描述】:

我的问题是我无法从我尝试使用.mp4.mov 在带有库opencv3.4.0 的Windows 上使用cpp 代码读取文件。我试图从相机中读取它正在工作。 可能是什么原因?

cv::VideoCapture cap("001.mp4");

// Check if camera opened successfully

if (!cap.isOpened()) {

    std::cout << "Error opening video stream or file" << std::endl;

    break;  //==>hits here

} 


/// while below code part works correctly

cv::VideoCapture cap(0);

// Check if camera opened successfully

if (!cap.isOpened()) {

    std::cout << "Error opening video stream or file" << std::endl;

    break;  

} 

【问题讨论】:

  • 用你的exe复制opencv_ffmpeg到文件夹
  • 问题是关于我复制到包含我的 exe 的文件夹中的 opencv_ffmpeg 库。问题已解决。

标签: c++ windows opencv video-capture


【解决方案1】:

复制并尝试下面的代码,如果它也不起作用。这完全是关于你的opencv安装或目录错误。

#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <stdio.h>
#include "opencv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;


   int main(){

  VideoCapture cap("videoname.mp4"); 
  if(!cap.isOpened()){
    cout << "Error opening video stream or file" << endl;
    return -1;
  }

  while(1){

    Mat frame;

    cap >> frame;

    if (frame.empty())
      break;

    imshow( "Frame", frame );

    char c=(char)waitKey(25);
    if(c==27)
      break;
  }

  cap.release();

  destroyAllWindows();

  return 0;
}

【讨论】:

  • 感谢@Yunus Temurlenk,正如我上面提到的,当我复制 opencv_ffmpeg 库时,问题已得到解决。不知道如何选择评论作为答案。
猜你喜欢
  • 2018-07-22
  • 2013-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-04
  • 1970-01-01
相关资源
最近更新 更多