#include "StdAfx.h" #include "ImageMatQueue.h" #include "PublicFunc.h" #include "filetools.h" #include "imageprocess.h" #include static int imgindex = 0; ImageMatQueue::ImageMatQueue(void) { pixType = -1; DevModel = -1; bScanning = false; imageremain = 0; } void ImageMatQueue::run() { if (m_threadProc.joinable()) { bRun = false; m_threadProc.join(); } bRun = true; imgindex = 0; m_threadProc = std::thread(&ImageMatQueue::proc, this); } void ImageMatQueue::setmultioutputR(bool canoutput/*=false*/) { can_multi_outputR = canoutput; } void ImageMatQueue::SetDevModel(int dev/*=-1*/) { DevModel = dev; } 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(); } } void ImageMatQueue::pushMat(JpegBuffer& data) { imageremain++; m_pImages.Put(data); int k = 0; } std::string ImageMatQueue::popMat(int num) { return m_images.Take(); } bool ImageMatQueue::valid() { return m_images.Size(); } void ImageMatQueue::clear() { while (m_images.Size()>0) { m_images.Take(); } while (m_pImages.Size()>0) { m_pImages.Clear(); } } int ImageMatQueue::getMatSum() { int iSum = 0; iSum = m_images.Size(); return iSum; } bool ImageMatQueue::isScanning() { return (imageremain != 0 )|| (m_pImages.Size() != 0); } bool ImageMatQueue::empty() { return m_images.Size()==0 && imageremain ==0 && !bScanning; } void ImageMatQueue::proc() { while (bRun) { this_thread::sleep_for(std::chrono::milliseconds(5)); { if (m_pImages.Size()>0)//m_images.empty() && { if (pixType != -1) { std::string csName; SYSTEMTIME st = { 0 }; GetLocalTime(&st); //获取当前时间 可精确到ms //csName.Format("%02d%02d%02d-%d.bmp", st.wHour, st.wMinute, st.wSecond,++imgindex); cv::Mat matPicImage; cv::Mat matFront, matBack; //vector mats; switch (DevModel) { case 0://G100 case 1://G200//正反面图像分开的 { if (m_pImages.Size() >= 2) { matFront = m_pImages.Take().getMat(pixType); matBack = m_pImages.Take().getMat(pixType); //mats.push_back(matFront); //mats.push_back(matBack); } } break; case 2://G300 case 3://G400 case 4://G500 正反面图像在一副图上,需要均分图像 { 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; default: break; } } imageremain--; } } } }