|
在树莓派上配置好了opencv,然后连接了摄像头,也可以用。可以从摄像头拍下一帧的照片,但是拍不了第二帧,程序如下:
#include <stdio.h>
#include <stdlib.h>
#include <opencv/highgui.h>
#include <opencv/cv.h>
int main()
{
printf("program has opened\n");
IplImage* img=NULL;//图像结构体
IplImage* img2=NULL;
CvCapture* cam = cvCreateCameraCapture(0);
img = cvQueryFrame(cam);
cvSaveImage("photo.jpg", img, 0);
cvWaitKey(33);
cvReleaseImage(&img);
cvWaitKey(33);
cam=cvCreateCameraCapture(0);
img2 = cvQueryFrame(cam);//这里出错,如果没有上面一行会显示段错误,如果有上面一行显示下文说的错
if (img2==NULL)
{
}
else
{
cvSaveImage("photo2.jpg", img2, 0);
char c2=cvWaitKey(33);
cvReleaseImage(&img2);
}
return 0;
}
然后在那一行出现这个错误:
VIDIOC_REQBUFS: Device or resource busy
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
*** glibc detected *** ./opencv: double free or corruption (fasttop): 0x014cc2e0 ***
Aborted
求大神解答啊,为什么会这样,第一帧可以清晰保存啊
|
|