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>
|
2021-07-31 03:12:53 +00:00
|
|
|
|
static int imgindex = 0;
|
|
|
|
|
ImageMatQueue::ImageMatQueue(void)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
pixType = -1;
|
|
|
|
|
DevModel = -1;
|
|
|
|
|
bScanning = false;
|
|
|
|
|
imageremain = 0;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageMatQueue::run()
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
if (m_threadProc.joinable())
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
|
|
|
|
bRun = false;
|
|
|
|
|
m_threadProc.join();
|
|
|
|
|
}
|
|
|
|
|
bRun = true;
|
2021-07-31 03:12:53 +00:00
|
|
|
|
imgindex = 0;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
m_threadProc = std::thread(&ImageMatQueue::proc, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageMatQueue::setmultioutputR(bool canoutput/*=false*/)
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
can_multi_outputR = canoutput;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageMatQueue::SetDevModel(int dev/*=-1*/)
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
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();
|
|
|
|
|
}
|
2021-07-31 03:12:53 +00:00
|
|
|
|
if (m_threadProc.joinable())
|
|
|
|
|
{
|
|
|
|
|
bRun = false;
|
|
|
|
|
m_threadProc.join();
|
|
|
|
|
}
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageMatQueue::pushMat(JpegBuffer& data)
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
imageremain++;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
m_pImages.Put(data);
|
|
|
|
|
int k = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 03:12:53 +00:00
|
|
|
|
std::string ImageMatQueue::popMat(int num)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
return m_images.Take();
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ImageMatQueue::valid()
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
return m_images.Size();
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageMatQueue::clear()
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
while (m_images.Size()>0)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
m_images.Take();
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
2021-07-31 03:12:53 +00:00
|
|
|
|
while (m_pImages.Size()>0)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
2021-07-31 03:12:53 +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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 03:12:53 +00:00
|
|
|
|
bool ImageMatQueue::isScanning()
|
|
|
|
|
{
|
|
|
|
|
return (imageremain != 0 )|| (m_pImages.Size() != 0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 08:08:50 +00:00
|
|
|
|
bool ImageMatQueue::empty()
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
return m_images.Size()==0 && imageremain ==0 && !bScanning;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ImageMatQueue::proc()
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
while (bRun)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
|
|
|
|
this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
if (m_pImages.Size()>0)//m_images.empty() &&
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
if (pixType != -1)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
std::string csName;
|
|
|
|
|
SYSTEMTIME st = { 0 };
|
|
|
|
|
GetLocalTime(&st); //<2F><>ȡ<EFBFBD><C8A1>ǰʱ<C7B0><CAB1> <20>ɾ<EFBFBD>ȷ<EFBFBD><C8B7>ms
|
|
|
|
|
//csName.Format("%02d%02d%02d-%d.bmp", st.wHour, st.wMinute, st.wSecond,++imgindex);
|
|
|
|
|
|
2020-08-31 08:08:50 +00:00
|
|
|
|
cv::Mat matPicImage;
|
2021-07-31 03:12:53 +00:00
|
|
|
|
cv::Mat matFront, matBack;
|
|
|
|
|
//vector<cv::Mat> mats;
|
|
|
|
|
switch (DevModel)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
|
|
|
|
case 0://G100
|
|
|
|
|
case 1://G200//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD>ֿ<EFBFBD><D6BF><EFBFBD>
|
2021-07-31 03:12:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (m_pImages.Size() >= 2)
|
2020-08-31 08:08:50 +00:00
|
|
|
|
{
|
2021-07-31 03:12:53 +00:00
|
|
|
|
matFront = m_pImages.Take().getMat(pixType);
|
|
|
|
|
matBack = m_pImages.Take().getMat(pixType);
|
|
|
|
|
//mats.push_back(matFront);
|
|
|
|
|
//mats.push_back(matBack);
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
2021-07-31 03:12:53 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
case 2://G300
|
|
|
|
|
case 3://G400
|
|
|
|
|
case 4://G500 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ͼ<EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>
|
2021-07-31 03:12:53 +00:00
|
|
|
|
{
|
|
|
|
|
std::string csImage;
|
|
|
|
|
csImage = csPath + "\\G300" + csName;
|
|
|
|
|
//cv::Mat mat = m_pImages.Take().getMat(pixType);
|
|
|
|
|
//matPicImage = mat(cv::Rect(0, 0, mat.cols, mat.rows));
|
|
|
|
|
////mats.push_back(matPicImage);
|
|
|
|
|
//IplImage qqImg;
|
|
|
|
|
//qqImg = IplImage(matPicImage); // cv::Mat -> IplImage
|
|
|
|
|
//cvSaveImage(csImage, &qqImg);
|
|
|
|
|
m_images.Put(csImage);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-31 03:12:53 +00:00
|
|
|
|
imageremain--;
|
2020-08-31 08:08:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|