cvCaptureFromFile-从特定路径打开视频 - Raspberry Pi

时间:2015-05-12 09:42:28

标签: c++ c opencv raspberry-pi

我在Raspberry Pi中安装了OpenCV-2.4.9。现在我正在尝试从特定路径加载视频,为此我尝试使用C和C ++ API

C API:cvCaptureFromFile(path);

C ++ API:VideoCapture上限; cap.open(路径)

我收到错误,它说无法打开文件。

它适用于Windows和Linux,但不适用于Raspberry Pi。我错过了什么吗?

C ++代码:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(){
  VideoCapture cap("C:/Users/nava/Videos/file.mp4");
  if (!cap.isOpened()){
    cout << "Error opening video stream" << endl;
    return -1;
  }
while (1){
    Mat Frame;
    if (!cap.read(Frame)){
        cout << "No Frame available" << endl;
        waitKey();
    }
    imshow("output", Frame);
    if (waitKey(33) == 27) break;
}
}

C代码:

#include "highgui.h"

int main(int argc, char** argv)
{
  cvNamedWindow("video",CV_WINDOW_AUTOSIZE);
  CvCapture* capture = cvCreateFileCapture("/home/pi/Desktop/test.mp4");
  IplImage* frame;
  while(1)
  {
   frame = cvQueryFrame(capture);
   if(!frame) break;
   cvShowImage("video", frame);
   char c = cvWaitKey(33);
   if(c == 27) break;
  }
  }

1 个答案:

答案 0 :(得分:0)

您必须安装UV4L驱动程序。请参阅本教程:

  

http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14