【发布时间】:2015-07-23 02:29:42
【问题描述】:
我在 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;
}
}
【问题讨论】:
-
对 opencv 的神秘 c-api 的支持正在迅速消失,请避免使用 c。
-
是的,但是我不明白为什么它在 C++ API 案例中也会失败?
-
仅在树莓派上也是如此,但在 Windows 和 Linux 上则不然。
标签: c++ c opencv raspberry-pi