我已经坚持这个问题几天了,我以为我会求助。 我写了这个测试代码来显示我的问题
这是我的拍照功能
cv::Mat takePicture(){
cv::Mat pic;
VideoCapture cam(0);
if(!cam.isOpened()){
std::cout << "Failed to make connection to Cam" << std::endl;
exit(1);
}
cam.set(CV_CAP_PROP_FRAME_WIDTH, 320);
cam.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
cam >> pic;
cvWaitKey(100);
return pic.clone();
}
这是我的main函数中的一个循环,会导致崩溃
if(test_mode == true){
while(true){
Mat testImg;
char fileName[50];
sprintf(fileName, "testFile%d", threadNo);
testImg = takePicture();
cout << "current pic is " << threadNo << endl;
threadNo++;
testImg.release();
}
}
程序运行正常,直到图像27它会变慢,而图像30我会得到各种各样的错误
mmap: Cannot allocate memory
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
libv4l1: error allocating v4l1 buffers: Cannot allocate memory
HIGHGUI ERROR: V4L: Mapping Memmory from video source error: Invalid argument
HIGHGUI ERROR: V4L: Initial Capture Error: Unable to load initial memory buffers
*** glibc detected *** ./Cam: free(): invalid pointer: 0x0076ab88 ***
Aborted
我一直认为这必须是由泄漏造成的。在此先感谢您的帮助。