【发布时间】:2019-04-03 06:48:49
【问题描述】:
我正在开发一个应用程序,该应用程序需要使用来自单个摄像机的实时视频源来检查某些工业过程。我想知道是否可以仅使用一台相机创建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.
}
}
}
谁能告诉我哪里出错了?
【问题讨论】:
标签: c++ qt opencv ubuntu-16.04