huago-corrcet_tools/HuaGoCorrect/ImageMatQueue.cpp

158 lines
2.8 KiB
C++
Raw Normal View History

2020-08-31 08:08:50 +00:00
#include "StdAfx.h"
#include "ImageMatQueue.h"
#include "PublicFunc.h"
#include "filetools.h"
#include "imageprocess.h"
#include <atlconv.h>
static int imgindex = 0;
ImageMatQueue::ImageMatQueue(void)
2020-08-31 08:08:50 +00:00
{
pixType = -1;
DevModel = -1;
bScanning = false;
imageremain = 0;
2020-08-31 08:08:50 +00:00
}
void ImageMatQueue::run()
{
if (m_threadProc.joinable())
2020-08-31 08:08:50 +00:00
{
bRun = false;
m_threadProc.join();
}
bRun = true;
imgindex = 0;
2020-08-31 08:08:50 +00:00
m_threadProc = std::thread(&ImageMatQueue::proc, this);
}
void ImageMatQueue::setmultioutputR(bool canoutput/*=false*/)
{
can_multi_outputR = canoutput;
2020-08-31 08:08:50 +00:00
}
void ImageMatQueue::SetDevModel(int dev/*=-1*/)
{
DevModel = dev;
2020-08-31 08:08:50 +00:00
}
ImageMatQueue::~ImageMatQueue(void)
{
if (m_images.Size() > 0)
{
m_images.Clear();
m_images.ShutDown();
}
if (m_pImages.Size() > 0)
{
m_pImages.Clear();
m_pImages.ShutDown();
}
if (m_threadProc.joinable())
{
bRun = false;
m_threadProc.join();
}
2020-08-31 08:08:50 +00:00
}
void ImageMatQueue::pushMat(JpegBuffer& data)
{
imageremain++;
2020-08-31 08:08:50 +00:00
m_pImages.Put(data);
int k = 0;
}
std::string ImageMatQueue::popMat(int num)
2020-08-31 08:08:50 +00:00
{
return m_images.Take();
2020-08-31 08:08:50 +00:00
}
bool ImageMatQueue::valid()
{
return m_images.Size();
2020-08-31 08:08:50 +00:00
}
void ImageMatQueue::clear()
{
while (m_images.Size()>0)
2020-08-31 08:08:50 +00:00
{
m_images.Take();
2020-08-31 08:08:50 +00:00
}
while (m_pImages.Size()>0)
2020-08-31 08:08:50 +00:00
{
m_pImages.Clear();
2020-08-31 08:08:50 +00:00
}
}
int ImageMatQueue::getMatSum()
{
int iSum = 0;
iSum = m_images.Size();
return iSum;
}
bool ImageMatQueue::isScanning()
{
return (imageremain != 0 )|| (m_pImages.Size() != 0);
}
2020-08-31 08:08:50 +00:00
bool ImageMatQueue::empty()
{
return m_images.Size()==0 && imageremain ==0 && !bScanning;
2020-08-31 08:08:50 +00:00
}
void ImageMatQueue::proc()
{
while (bRun)
2020-08-31 08:08:50 +00:00
{
this_thread::sleep_for(std::chrono::milliseconds(5));
{
if (m_pImages.Size()>0)//m_images.empty() &&
2020-08-31 08:08:50 +00:00
{
if (pixType != -1)
2020-08-31 08:08:50 +00:00
{
SYSTEMTIME st = { 0 };
GetLocalTime(&st); //获取当前时间 可精确到ms
time_t timp;
tm* p;
time(&timp);
p = localtime(&timp);
std::string csName = std::to_string(p->tm_hour) + "_" + std::to_string(p->tm_min) + "_" + std::to_string(p->tm_sec)+".png";
2020-08-31 08:08:50 +00:00
cv::Mat matPicImage;
cv::Mat matFront, matBack;
//vector<cv::Mat> mats;
switch (DevModel)
2020-08-31 08:08:50 +00:00
{
case 0://G100
case 1://G200//正反面图像分开的
{
if (m_pImages.Size() >= 2)
2020-08-31 08:08:50 +00:00
{
matFront = m_pImages.Take().getMat(pixType==1 ? 1 : 6);//bgr or gray
matBack = m_pImages.Take().getMat(pixType == 1 ? 1 : 6);
//mats.push_back(matFront);
//mats.push_back(matBack);
2020-08-31 08:08:50 +00:00
}
}
break;
2020-08-31 08:08:50 +00:00
case 2://G300
case 3://G400
case 4://G500 正反面图像在一副图上,需要均分图像
{
std::string csImage;
csImage = csPath+"//" + csName;
cv::Mat mat = m_pImages.Take().getMat(pixType == 1 ? 1 : 6);
cv::imwrite(csImage, mat);
m_images.Put(csImage);
}
break;
2020-08-31 08:08:50 +00:00
default:
break;
}
}
imageremain--;
2020-08-31 08:08:50 +00:00
}
}
}
}