OpenCVQT
::OpenCVQT(QWidget *parent, Qt
::WFlags flags
)
{
ui.setupUi(this);
myLabel
= new QLabel("Fuckasdasd");
mainLayout->addWidget(myLabel);
mainWgt->setLayout(mainLayout);
this->setCentralWidget(mainWgt);
camMenu = menuBar()->addMenu(tr("Web Camera"));
webCamAct
= new QAction(tr
("Start Web Camera"),
this );
camMenu->addAction(webCamAct);
connect(webCamAct, SIGNAL(triggered()), this,
SLOT(WebCamSlot() ));
myCamThread = new cameraThread();
}
// =============================================
OpenCVQT::~OpenCVQT()
{
}
// =============================================
{
return myLabel;
}
void OpenCVQT::WebCamSlot()
{
myCamThread->run();
}
class cameraThread
: public QThread{
public:
cameraThread();
~cameraThread();
void run();
void StreamCamera();
void ConvertImage();
void CreateQImage();
private:
CvCapture* myCaptureHandler;
IplImage* myOriginalIplImage, *myRGBIplImage;
uchar* ImageData;
};
cameraThread::cameraThread()
: myCaptureHandler(),
myOriginalIplImage(&IplImage() ),
myRGBIplImage(&IplImage() ),
ImageData()
{
myCaptureHandler = cvCreateCameraCapture(0);
myOriginalIplImage = cvCreateImage(cvSize(320, 240),
IPL_DEPTH_8U, 3);
myRGBIplImage = cvCreateImage(cvSize(320,240),
IPL_DEPTH_8U, 3 );
}
// =============================================
cameraThread::~cameraThread()
{
}
// =============================================
void cameraThread::run()
{
StreamCamera();
exec();
}
// =============================================
void cameraThread::StreamCamera()
{
myOriginalIplImage = cvQueryFrame(myCaptureHandler);
ConvertImage();
CreateQImage();
//resize(myRGBIplImage->width, myRGBIplImage->height);
(OpenCVQT
::myLabel)->setPixmap
(QPixmap::fromImage(myQImage
) );
}
// =============================================
void cameraThread::ConvertImage()
{
cvCvtColor(myOriginalIplImage,
myRGBIplImage, CV_BGR2RGB);
if (!myRGBIplImage)
{
errMsg->showMessage("Error Convert Image");
}
else
{
ImageData = (uchar*) myRGBIplImage->imageData;
}
}
// =============================================
void cameraThread::CreateQImage()
{
myRGBIplImage->width, myRGBIplImage->height,
myRGBIplImage->widthStep,
}
OpenCVQT::OpenCVQT(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
myLabel = new QLabel("Fuckasdasd");
mainLayout = new QVBoxLayout;
mainLayout->addWidget(myLabel);
mainWgt = new QWidget(this);
mainWgt->setLayout(mainLayout);
this->setCentralWidget(mainWgt);
camMenu = menuBar()->addMenu(tr("Web Camera"));
webCamAct = new QAction(tr("Start Web Camera"), this );
camMenu->addAction(webCamAct);
connect(webCamAct, SIGNAL(triggered()), this,
SLOT(WebCamSlot() ));
myCamThread = new cameraThread();
}
// =============================================
OpenCVQT::~OpenCVQT()
{
}
// =============================================
QLabel*& OpenCVQT::getLabel()
{
return myLabel;
}
void OpenCVQT::WebCamSlot()
{
myCamThread->run();
}
class cameraThread : public QThread
{
public:
cameraThread();
~cameraThread();
void run();
void StreamCamera();
void ConvertImage();
void CreateQImage();
private:
CvCapture* myCaptureHandler;
IplImage* myOriginalIplImage, *myRGBIplImage;
QImage myQImage;
uchar* ImageData;
};
cameraThread::cameraThread()
: myCaptureHandler(),
myOriginalIplImage(&IplImage() ),
myRGBIplImage(&IplImage() ),
myQImage(QImage()),
ImageData()
{
myCaptureHandler = cvCreateCameraCapture(0);
myOriginalIplImage = cvCreateImage(cvSize(320, 240),
IPL_DEPTH_8U, 3);
myRGBIplImage = cvCreateImage(cvSize(320,240),
IPL_DEPTH_8U, 3 );
}
// =============================================
cameraThread::~cameraThread()
{
}
// =============================================
void cameraThread::run()
{
StreamCamera();
exec();
}
// =============================================
void cameraThread::StreamCamera()
{
myOriginalIplImage = cvQueryFrame(myCaptureHandler);
ConvertImage();
CreateQImage();
//resize(myRGBIplImage->width, myRGBIplImage->height);
(OpenCVQT::myLabel)->setPixmap(QPixmap::fromImage(myQImage) );
}
// =============================================
void cameraThread::ConvertImage()
{
cvCvtColor(myOriginalIplImage,
myRGBIplImage, CV_BGR2RGB);
if (!myRGBIplImage)
{
QErrorMessage* errMsg = new QErrorMessage;
errMsg->showMessage("Error Convert Image");
}
else
{
ImageData = (uchar*) myRGBIplImage->imageData;
}
}
// =============================================
void cameraThread::CreateQImage()
{
myQImage = QImage(ImageData,
myRGBIplImage->width, myRGBIplImage->height,
myRGBIplImage->widthStep,
QImage::Format_RGB888);
}
To copy to clipboard, switch view to plain text mode
Bookmarks