繁体   English   中英

如何使用OpenCV在Qt中启用多个Windows?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM