Tag: video捕获

我的Opencv应用程序处理速度非常慢

我正在构建一个OpenCV应用程序,它可以从相机中捕获video,并在删除背景后将其覆盖在另一个video上。 我无法达到合理的速度,因为它以大约1 fps的速度播放输出,而我的背景移除工作速度为3fps。 有没有办法以正常速度显示背景video并以3fps覆盖已处理的video? 我试着评论我的代码,我意识到问题主要在于渲染部分本身。 我尝试显示video和我的网络摄像头,我注意到用openCV显示的实际fps和video的fps有所下降。 这是示例代码: void main() { CvCapture* capture, *Vcap; capture = cvCaptureFromCAM(0); if(!capture) { printf(“Video Load Error”); } Vcap = cvCaptureFromAVI(“bgDemo.mp4”); //printf(“\nEntered BGR”); if(!Vcap) { printf(“Video Load Error”); } while(1) { IplImage* src = cvQueryFrame(Vcap); if(!src) { Vcap = cvCaptureFromAVI(“bgDemo.mp4”); continue; } IplImage* bck1 = cvCreateImage(cvGetSize(src),8,3); cvResize(src,bck1,CV_INTER_LINEAR); cvShowImage(“BCK”,bck1); cvWaitKey(1); } }

openCV错误:断言失败(scn == 3 || scn == 4)

我在最后一帧有Assertion失败错误,同时逐帧读取和写入video。 错误只显示在最后一帧,不知道为什么。 在这里看到了这个答案,这建议给出waitkey,我的代码已经有了等待键。 我的简单代码如下 int main() { CvCapture *capture=cvCaptureFromFile(“C:\\vid\\op.mp4”); if(capture==NULL) { printf(“can’t open video”); } Mat frame, first_frame,current_frame; char buffer[100]; int frame_count=1,p=1; while(1) { /*Getting the current frame from the video*/ frame=cvQueryFrame(capture); cv::cvtColor(frame,current_frame,1); //saving current frame sprintf(buffer,”C:\\frames\\image%u.jpg”,p); imwrite(buffer,current_frame); p++; waitKey(1); } return 0; } 有人请帮忙 解决方案:我在读完每个文件后添加了一个检查 – if(frame.empty()){ fprinf(“cannot access frame”); return -1; }