OpenCV捕获代码在系统函数中调用时冻结
我正在用OpenCV开发一个应用程序。我正在从相机中拍摄快照,然后关闭捕获 下面是我的捕获代码(capturecam1lowres.c) 有时(不是每次)排队。如何设置此子程序(capturecam1lowres)的超时。如果捕获花费太多时间,它应该放弃并退出。我怎样才能做到这一点 我尝试使用posix线程,但没有达到效果。下面是我的非工作线程代码OpenCV捕获代码在系统函数中调用时冻结,c,opencv,pthreads,system,C,Opencv,Pthreads,System,我正在用OpenCV开发一个应用程序。我正在从相机中拍摄快照,然后关闭捕获 下面是我的捕获代码(capturecam1lowres.c) 有时(不是每次)排队。如何设置此子程序(capturecam1lowres)的超时。如果捕获花费太多时间,它应该放弃并退出。我怎样才能做到这一点 我尝试使用posix线程,但没有达到效果。下面是我的非工作线程代码 #include <cv.h> #include <highgui.h> #include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
void *thread_function(void *arg)
{
sleep(10);
exit(0);
}
int main(int argc, char* argv[])
{
CvCapture* camera = cvCreateCameraCapture(0); // Use the default camera
pthread_t mythread;
IplImage* frame = 0;
if ( pthread_create( &mythread, NULL, thread_function, NULL) )
{
printf("error creating thread.");
abort();
}
if ( pthread_join ( mythread, NULL ) )
{
printf("error joining thread.");
abort();
}
cvSetCaptureProperty(camera,CV_CAP_PROP_FRAME_WIDTH,1024) ;
cvSetCaptureProperty(camera,CV_CAP_PROP_FRAME_HEIGHT,768);
frame = cvQueryFrame(camera); //need to capture at least one extra frame
// frame = cvQueryFrame(camera);
if (frame != NULL) {
printf("Frame extracted from CAM1\n\r");
cvSaveImage("/home/root/Desktop/BBTCP/webcam1.jpg", frame,0);
} else {
printf("Null frame 1\n\r");
}
cvReleaseCapture(&camera);
cvReleaseImage(&frame);
return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
void*thread_函数(void*arg)
{
睡眠(10);
出口(0);
}
int main(int argc,char*argv[])
{
CvCapture*camera=cvCreateCameraCapture(0);//使用默认相机
pthread_t mythread;
IplImage*frame=0;
if(pthread_create(&mythread,NULL,thread_函数,NULL))
{
printf(“创建线程时出错”);
中止();
}
if(pthread_join(mythread,NULL))
{
printf(“连接螺纹时出错”);
中止();
}
cvSetCaptureProperty(摄像头,CV\u CAP\u PROP\u帧宽度,1024);
cvSetCaptureProperty(摄像机,CV_CAP_PROP_FRAME_HEIGHT,768);
frame=cvQueryFrame(照相机);//需要至少捕获一个额外的帧
//帧=cvQueryFrame(摄像机);
如果(帧!=NULL){
printf(“从CAM1提取的帧\n\r”);
cvSaveImage(“/home/root/Desktop/BBTCP/webcam1.jpg”,框架,0);
}否则{
printf(“空帧1\n\r”);
}
cvReleaseCapture(相机和相机);
cvReleaseImage(&frame);
返回0;
}
在代码或系统设计中没有错误,但问题在于嵌入式系统本身的DMA模块。DMA大容量传输损坏,导致此错误。所以没有软件问题。我真的不确定,但您是否在另一个嵌入的程序中执行此程序?如果stdout或errout缓冲区已满且未被正在执行的应用程序读取,则此程序可能会阻塞。
frame = cvQueryFrame(camera);
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#include <stdio.h>
#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
void *thread_function(void *arg)
{
sleep(10);
exit(0);
}
int main(int argc, char* argv[])
{
CvCapture* camera = cvCreateCameraCapture(0); // Use the default camera
pthread_t mythread;
IplImage* frame = 0;
if ( pthread_create( &mythread, NULL, thread_function, NULL) )
{
printf("error creating thread.");
abort();
}
if ( pthread_join ( mythread, NULL ) )
{
printf("error joining thread.");
abort();
}
cvSetCaptureProperty(camera,CV_CAP_PROP_FRAME_WIDTH,1024) ;
cvSetCaptureProperty(camera,CV_CAP_PROP_FRAME_HEIGHT,768);
frame = cvQueryFrame(camera); //need to capture at least one extra frame
// frame = cvQueryFrame(camera);
if (frame != NULL) {
printf("Frame extracted from CAM1\n\r");
cvSaveImage("/home/root/Desktop/BBTCP/webcam1.jpg", frame,0);
} else {
printf("Null frame 1\n\r");
}
cvReleaseCapture(&camera);
cvReleaseImage(&frame);
return 0;
}