86 lines
2.0 KiB
C++
86 lines
2.0 KiB
C++
#include "readcameraimagethread.h"
|
|
|
|
ReadCameraImageThread::ReadCameraImageThread(QObject *parent)
|
|
:QThread(parent)
|
|
{
|
|
myImage = new QImage();
|
|
}
|
|
|
|
ReadCameraImageThread::~ReadCameraImageThread()
|
|
{
|
|
delete myImage;
|
|
if(NULL == cameraPtr)
|
|
{
|
|
delete cameraPtr;
|
|
}
|
|
if(NULL == imagePtr)
|
|
{
|
|
delete imagePtr;
|
|
}
|
|
}
|
|
|
|
void ReadCameraImageThread::run()
|
|
{
|
|
if(NULL==cameraPtr)
|
|
{
|
|
return;
|
|
}
|
|
if(NULL==imagePtr)
|
|
{
|
|
return;
|
|
}
|
|
|
|
while(!isInterruptionRequested())
|
|
{
|
|
// qDebug()<<"SoftTrigger:"<<cameraPtr->CommandExecute("TriggerSoftware");
|
|
// qDebug()<<"ReadBuffer:"<<cameraPtr->ReadBuffer(*imagePtr);
|
|
//cameraPtr->CommandExecute("TriggerSoftware");
|
|
//cameraPtr->ReadBuffer(*imagePtr);
|
|
cameraPtr->GetImage(*imagePtr,false);
|
|
if(isEnableCrossHairLine)
|
|
{
|
|
drawCrossHairLine();
|
|
}
|
|
|
|
if(imagePtr->channels()>1)
|
|
{
|
|
*myImage = QImage((const unsigned char*)(imagePtr->data),imagePtr->cols,imagePtr->rows,QImage::Format_RGB888);
|
|
}
|
|
else
|
|
{
|
|
*myImage = QImage((const unsigned char*)(imagePtr->data),imagePtr->cols,imagePtr->rows,QImage::Format_Indexed8);
|
|
}
|
|
|
|
emit messageImageSGL(*myImage);
|
|
msleep(10);
|
|
}
|
|
}
|
|
|
|
void ReadCameraImageThread::getCameraPtr(CMvCamera *camera)
|
|
{
|
|
cameraPtr = camera;
|
|
}
|
|
|
|
void ReadCameraImageThread::getImagePtr(cv::Mat *image)
|
|
{
|
|
imagePtr = image;
|
|
}
|
|
|
|
void ReadCameraImageThread::drawCrossHairLine(Scalar lineColor,int lineWidth)
|
|
{
|
|
int heigh = imagePtr->rows;
|
|
int width = imagePtr->cols;
|
|
// 水平线
|
|
Point startPH(0,int(heigh/2)),endPH(int(width),int(heigh/2));
|
|
line(*imagePtr,startPH,endPH,lineColor,lineWidth);
|
|
// 垂直线
|
|
Point startPV(int(width/2),0),endPV(int(width/2),int(heigh));
|
|
line(*imagePtr,startPV,endPV,lineColor,lineWidth);
|
|
}
|
|
|
|
void ReadCameraImageThread::setEnableCrossHairLine(bool value )
|
|
{
|
|
isEnableCrossHairLine = value;
|
|
|
|
}
|