我在 Raspberry Pi 中安装了 OpenCV-2.4.9。现在我正在尝试从特定路径加载视频,为此我尝试使用 C 和 C++ API
C API:cvCaptureFromFile(路径);
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;
}
}
最佳答案
您必须安装 UV4L 驱动程序。按照本教程操作:
http://www.linux-projects.org/modules/sections/index.php?op=viewarticle&artid=14
关于c++ - cvCaptureFromFile-从特定路径打开视频-Raspberry Pi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30187093/