[英]How to enable Multiple Windows in Qt using OpenCV?
我正在開發一個應用程序,該應用程序需要使用來自單個攝像機的實時視頻提要來檢查某些工業過程。 我想知道是否可以僅使用一台攝像機創建multiple windows
。 同樣,每個window
將具有不同的關注Region Of Interest
。 我在QThread
運行此代碼
這是我一直在嘗試的代碼,但是一旦運行它就會崩潰。
mythread.cpp
#include "mythread.h"
#include "mainwindow.h"
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
char key;
MyThread::MyThread(QObject *parent, bool b) : QThread(parent), Stop(b)
{
}
// run() will be called when a thread starts
void MyThread::run()
{
cvNamedWindow("Camera_Output", 1); //Create window
cvNamedWindow("Camera_Output1", 1);
CvCapture* capture = cvCaptureFromCAM(0); //Capture using camera 0 connected to system
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH, 640 );
cvSetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT, 480 );
CvCapture* capture1 = cvCaptureFromCAM(0); //Capture using camera 0 connected to system
cvSetCaptureProperty( capture1, CV_CAP_PROP_FRAME_WIDTH, 640 );
cvSetCaptureProperty( capture1, CV_CAP_PROP_FRAME_HEIGHT, 480 );
//Create loop for live streaming
while(1){
IplImage* framein = cvQueryFrame(capture); //Create image frames from capture
IplImage* framein1 = cvQueryFrame(capture1);
/* sets the Region of Interest - rectangle area has to be __INSIDE__ the image */
cvSetImageROI(framein, cvRect(200, 200, 320, 240));
cvSetImageROI(framein1, cvRect(500, 500, 320, 240));
/* create destination image - cvGetSize will return the width and the height of ROI */
IplImage *frameout = cvCreateImage(cvGetSize(framein), framein->depth, framein->nChannels);
IplImage *frameout1 = cvCreateImage(cvGetSize(framein1), framein1->depth, framein1->nChannels);
/* copy subimage */
cvCopy(framein, frameout, NULL);
cvCopy(framein1, frameout1, NULL);
/* always reset the Region of Interest */
cvResetImageROI(framein);
cvResetImageROI(framein1);
cvShowImage("Camera_Output", frameout); //Show image frames on created window
cvShowImage("Camera_Output1", frameout1);
key = cvWaitKey(10); //Capture Keyboard stroke
if (char(key) == 27){
break; //ESC key loop will break.
}
}
}
誰能告訴我我要去哪里錯了?
您絕對可以做到。 只需創建多個視圖,即可將攝像機的輸出(通過一些更新信號)鏈接到您想要的窗口中的顯示功能(通過一些更新和渲染槽)。 因此,從概念上講:
然后,每個視圖都會運行自己的事件循環,所以應該沒問題。 一般說明:AFAIK子類化QThread
或做類似的事情被認為是不好的做法。 我更喜歡這里的工人方法 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.