尝试捕获默认iSight摄像机时,OpenCV崩溃 [英] OpenCV crash when attempting to capture default iSight camera
问题描述
我想在我的Macbook Pro(10.8.5,视网膜模型)上运行openCV,我想使用默认的iSight摄像头进行输入,因为我不想随身携带或购买一个USB摄像头if我不需要。
我使用OpenCV用户文档中的示例程序:
#includecv.h
#includehighgui.h
using namespace cv;
int main(int,char **)
{
VideoCapture cap(0);
if(!cap.isOpened())return -1;
垫框架,边缘;
namedWindow(edges,1);
for(;;)
{
cap>>帧;
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(30)> = 0)break;
}
return 0;
}
当我运行此程序时,程序无法通过断言:
cvtColor,file / Users / dadair / opencv / src / OpenCV中的OpenCV错误:断言失败(scn == 3 || scn == 4)< modules / imgproc / src / color.cpp,第3402行
libc ++ abi.dylib:terminate调用抛出异常
任何人都可以解释为什么这是失败,我可以做什么来解决这个问题?我正在运行OpenCV 2.4.6。
谢谢!
问题是使用openCV的版本(2.4.6)。对于访问iSight摄像头,你必须使用2.4.5,直到2.4.6中引入的任何错误是固定的。从Homebrew获得2.4的OSX:
$ brew版本opencv
$ cd / usr / local / Library / taps / homebrew-science
checkout git版本到旧版本:
$ git checkout ae74fe9 opencv.rb
删除原始版本的opencv(可能为2.4.6)
$ brew unlink opencv
安装2.4.5版本:
$ brew install opencv
I am trying to get openCV running on my Macbook Pro (10.8.5, retina model), and I want to use the default iSight camera for input, as I don't want to carry around or buy a USB camera if I don't need to.
I am using the example program from OpenCV's user documentation:
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0);
if(!cap.isOpened()) return -1;
Mat frame, edges;
namedWindow("edges",1);
for(;;)
{
cap >> frame;
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(30) >= 0) break;
}
return 0;
}
When I run this program, the program fails an assertion:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /Users/dadair/opencv/src/modules/imgproc/src/color.cpp, line 3402
libc++abi.dylib: terminate called throwing an exception
Can anyone explain why this is failing, and what I can do to fix the issue? I am running OpenCV 2.4.6.
Thanks!
The problem was with the version of openCV used (2.4.6). For access to the iSight camera, you have to use 2.4.5, until whatever bug was introduced in 2.4.6 is fixed. To get 2.4.5 on OSX from Homebrew:
$ brew versions opencv
$ cd /usr/local/Library/Taps/homebrew-science
checkout git version to older version:
$ git checkout ae74fe9 opencv.rb
remove the original version of opencv (probably 2.4.6)
$ brew unlink opencv
install 2.4.5 version:
$ brew install opencv
这篇关于尝试捕获默认iSight摄像机时,OpenCV崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!