我不能用下面的OpenCV代码从我的摄像头捕捉图像。
代码可以显示来自本地AVI文件或视频设备的图像。它在"test.avi“文件上工作得很好。
当我使用默认的摄像头(CvCapture* capture =cvCreateCameraCapture(0))时,程序可以从摄像头中检测到图像的大小,但只有无法显示图像。
/I忘记提到,我可以看到iSight正在工作,因为LED指示灯是打开的/
有人遇到同样的问题吗?
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
CvCapture* capture =cvCreateFileCapture( "C:\\test.avi" ) ;// display images from avi file, works well
// CvCapture* capture =cvCreateCameraCapture(0); //display the frame(images) from default webcam not work
assert( capture );
IplImage* image;
while(1) {
image = cvQueryFrame( capture );
if( !image ) break;
cvShowImage( "Example2", image );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "Example2" );发布于 2011-03-19 18:09:48
最新更新!问题解决了!
这恰好是OpenCV 2.2的一个bug。
下面是如何修复它:
http://dusijun.wordpress.com/2011/01/11/opencv-unable-to-capture-image-from-isight-webcam/
发布于 2012-11-14 09:06:10
我正在使用Macbook pro Mid 2012开发opencv 2.3,我在Isight摄像机上遇到了这个问题。不知何故,我通过简单地调整Cvcapture的参数和调整帧的宽度和高度,成功地使它在opencv上工作:
CvCapture* capture = cvCaptureFromCAM(0);
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 500 );
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 600 );还可以将这些数字更改为所需的帧宽和高度。
发布于 2011-01-11 16:07:57
您试过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(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}为我在macbook上工作(虽然在OS上)。如果它不能工作,某种错误信息将是有帮助的。
https://stackoverflow.com/questions/4658764
复制相似问题