问题描述
- VS2010opencv写qt5界面显示视频,必须cvShowImage先显示,否则QT中视频不显示
-
运行时界面如下:
代码如下:
void QT5video::showvideo() { ui.startBtn->setEnabled(false); ui.closeBtn->setEnabled(true); //声明IplImage指针 IplImage* pFrame = NULL; IplImage * return_frame; //获取摄像头 CvCapture* pCapture = cvCreateCameraCapture(0); //创建窗口 cvNamedWindow("监控视频",1); // cvNamedWindow("缺陷监测", 1); //显示视屏 while(1) { pFrame=cvQueryFrame( pCapture ); if(!pFrame)break; IplImage *img = pFrame; QImage qImage=QImage((const uchar*)img->imageData, img->width, img->height,img->widthStep, QImage::Format_RGB888).rgbSwapped(); ui.label_JK->setPixmap(QPixmap::fromImage(qImage)); return_frame=ControlsCountours(pFrame); IplImage *return_img = return_frame; QImage return_qImage=QImage((unsigned char * )return_img->imageDataOrigin,return_img->width,return_img->height,return_img->widthStep,QImage::Format_RGB888); ui.label_QX->setPixmap(QPixmap::fromImage(return_qImage,0)); cvShowImage("监控视频",pFrame); // cvShowImage("缺陷监测",return_frame); char c=cvWaitKey(330); if(c==27)break; } //cvWaitKey(0); cvReleaseCapture(&pCapture); cvReleaseImage(&return_frame); cvDestroyWindow("监控视频"); //cvDestroyWindow("缺陷监测"); }
要是把 cvNamedWindow("监控视频",1); cvShowImage("监控视频",pFrame); cvDestroyWindow("监控视频"); 这三条语句全部注释掉的话,那么运行之后只会出现QT界面,此时点击任何按钮都是不好使的,而且还使程序卡死了,如下图:
请求好心大神们解答~
解决方案
时间: 2024-09-26 19:10:09