【发布时间】:2011-04-25 20:13:06
【问题描述】:
我使用的是 Mac OS X 10.6 机器。我使用 Xcode 及其 GCC 编译器从源代码编译 OpenCV 2.1 x64。
我在使用 OpenCV 的 C++ 视频阅读功能时遇到问题。这是我正在使用的简单测试代码(直接来自 OpenCV 文档):
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat edges;
namedWindow("edges",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
cvtColor(frame, edges, CV_BGR2GRAY);
GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
Canny(edges, edges, 0, 30, 3);
imshow("edges", edges);
if(waitKey(200) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
程序编译正常,但是当我尝试运行它时,我看到网络摄像头上的绿灯亮了几秒钟,然后程序退出并显示错误消息:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /Users/mark/Downloads/OpenCV-2.1.0/src/cxcore/cxarray.cpp, line 2476
terminate called after throwing an instance of 'cv::Exception'
what(): /Users/mark/Downloads/OpenCV-2.1.0/src/cxcore/cxarray.cpp:2476: error: (-206) Unrecognized or unsupported array type in function cvGetMat
在调试模式下,在 cap >> 框架行之后,矩阵似乎仍然是空的。
当我尝试从视频文件或图像中捕捉时,我得到了类似的行为,所以它不是相机。你觉得有什么问题吗?我能做些什么来完成这项工作?
编辑:我想补充一点,如果我使用 C 功能,一切正常。但如果可以的话,我想坚持使用 C++。
谢谢
【问题讨论】: