用opencv打开摄像头时,摄像头打开但不显示图像是怎么回事?
opencv吧
全部回复
仅看楼主
level 1
我用的是opencv1+vc6.0
#include "StdAfx.h"
#include "stdio.h"
#include"string.h"
#include"cv.h"
#include"highgui.h"
int main(int argc, char* argv[])
{
CvCapture *camera=0;
IplImage *frame=0;
int i,n=0;
char filename[256];
char c;
camera=cvCaptureFromCAM(CV_CAP_ANY);
if(!camera)
{
fprintf(stderr,"Can't initialize camera\n");
return -1;
}
cvNamedWindow("video",CV_WINDOW_AUTOSIZE);
cvMoveWindow("video",150,200);
for(i=0;i<600;i++)
{
frame=cvQueryFrame(camera);
if(!frame)
{
fprintf(stderr,"Capture failed.\n");
}
c=cvWaitKey(100);
cvShowImage("video",frame);
if(c>0)
{
sprintf(filename,"F:/image/videoframe%d.jpg",n++);
if(!cvSaveImage(filename,frame))
{
fprintf(stderr,"failed to save frame as '%s'\n",filename);
}else
fprintf(stderr,"Saved frame as 'videoframe%d.jpg'/n",n-1);
}
}
cvReleaseCapture(&camera);
cvWaitKey(0);
return 0;
}
2014年04月01日 15点04分 1
level 4
换个高的版本
2014年04月02日 11点04分 2
我用opencv2.4.8也出现这种问题,应该不是版本的问题
2014年04月12日 15点04分
回复 poijo3083 :他用的是opencv1.0,那就是版本问题。不清楚你的
2014年04月13日 06点04分
level 2
你用这个试试
cvNamedWindow("video",CV_WINDOW_AUTOSIZE);
CvCapture* capture = NULL;
capture=cvCreateCameraCapture(0);
IplImage*frame;
while(1){
frame=cvQueryFrame(capture);
if(!frame)break;
cvShowImage("video",frame);
char c=cvWaitKey(33);
if(c==27)break;
}
cvReleaseCapture(&capture);
2014年04月15日 02点04分 3
level 1
camera=cvCaptureFromCAM(CV_CAP_ANY);用-1或者0或者1挨个试一试,有时候会出问题,比如你摄像头换过口,就会出问题,我曾经用两个摄像头做测试,然后拔掉一个之后另外那个的序号不变,用-1识别不出来。
2014年04月16日 08点04分 4
level 1
我用USB摄像头也是这个问题,改成-1能打开但就是显示灰色,后来就改成0忽然就可以了,难道电脑没摄像头将外接的USB摄像头默认为内部的
2017年10月11日 12点10分 6
1