#include "TGAirthProcess.h" #include "Logger.h" #include TGAirthProcess::TGAirthProcess(QObject *parent) : QObject(parent) { m_MixMapOut.Y8_Mean = 0; m_MixMapOut.Y16_Max = 0; m_MixMapOut.Y16_Mean = 0; m_MixMapOut.Y16_Min = 0; m_MixMapOut.Y16_Range = 0; m_ptrThread_Airth_0_PreDeal= nullptr; m_ptrThread_Airth_1_DeGuoGai= nullptr; m_ptrThread_Airth_2_DeBadPixel= nullptr; m_ptrThread_Airth_3_Destrip= nullptr; m_ptrThread_Airth_4_Y16Denoise_0= nullptr; m_ptrThread_Airth_4_Y16Denoise_1= nullptr; m_ptrThread_Airth_5_Y16DDE= nullptr; m_ptrThread_Airth_6_Y16IDE= nullptr; m_ptrThread_Airth_7_Y8Map = nullptr; m_varY16Data_IN.InitQueue(DefaultMaxImageSize, 6); m_varAirth_0_PreDeal.InitQueue(DefaultMaxImageSize, 6); m_varAirth_1_DeGuoGai.InitQueue(DefaultMaxImageSize, 6); m_varAirth_2_DeBadPixel.InitQueue(DefaultMaxImageSize, 6); m_varAirth_3_Destrip_0.InitQueue(DefaultMaxImageSize, 6); m_varAirth_3_Destrip_1.InitQueue(DefaultMaxImageSize, 6); m_varAirth_4_Y16Denois_0.InitQueue(DefaultMaxImageSize, 6); m_varAirth_4_Y16Denois_1.InitQueue(DefaultMaxImageSize, 6); m_varAirth_5_Y16DDE.InitQueue(DefaultMaxImageSize, 6); m_varAirth_6_Y16IDE.InitQueue(DefaultMaxImageSize, 6); m_varY8Data_OUT.InitQueue(DefaultMaxImageSize, 6); m_bThreadRunning_MappingData = false; } TGAirthProcess::~TGAirthProcess() { Stop(); } void TGAirthProcess::Start() { Stop(); //通过开关控制线程是否启动 m_bThreadRunning_MappingData = true; m_ptrThread_Airth_0_PreDeal = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_0_PreDeal, (void*)this)); m_ptrThread_Airth_1_DeGuoGai = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_1_DeGuoGai, (void*)this)); m_ptrThread_Airth_2_DeBadPixel = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_2_DeBadPixel, (void*)this)); m_ptrThread_Airth_3_Destrip = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_3_Destrip, (void*)this)); m_ptrThread_Airth_4_Y16Denoise_0 = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_4_Y16Denoise_0, (void*)this)); m_ptrThread_Airth_4_Y16Denoise_1 = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_4_Y16Denoise_1, (void*)this)); m_ptrThread_Airth_5_Y16DDE = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_5_Y16DDE, (void*)this)); m_ptrThread_Airth_6_Y16IDE = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_6_Y16IDE, (void*)this)); m_ptrThread_Airth_7_Y8Map = new std::thread(std::bind(&TGAirthProcess::ThreadEntry, &TGAirthProcess::ThreadFun_MappingData_Airth_7_Y8Map, (void*)this)); } void TGAirthProcess::Stop() { m_bThreadRunning_MappingData = false; if(nullptr != m_ptrThread_Airth_0_PreDeal) { m_ptrThread_Airth_0_PreDeal->join(); delete m_ptrThread_Airth_0_PreDeal; m_ptrThread_Airth_0_PreDeal = nullptr; } if(nullptr != m_ptrThread_Airth_1_DeGuoGai) { m_ptrThread_Airth_1_DeGuoGai->join(); delete m_ptrThread_Airth_1_DeGuoGai; m_ptrThread_Airth_1_DeGuoGai = nullptr; } if(nullptr != m_ptrThread_Airth_2_DeBadPixel) { m_ptrThread_Airth_2_DeBadPixel->join(); delete m_ptrThread_Airth_2_DeBadPixel; m_ptrThread_Airth_2_DeBadPixel = nullptr; } if(nullptr != m_ptrThread_Airth_3_Destrip) { m_ptrThread_Airth_3_Destrip->join(); delete m_ptrThread_Airth_3_Destrip; m_ptrThread_Airth_3_Destrip = nullptr; } if(nullptr != m_ptrThread_Airth_4_Y16Denoise_0) { m_ptrThread_Airth_4_Y16Denoise_0->join(); delete m_ptrThread_Airth_4_Y16Denoise_0; m_ptrThread_Airth_4_Y16Denoise_0 = nullptr; } if(nullptr != m_ptrThread_Airth_4_Y16Denoise_1) { m_ptrThread_Airth_4_Y16Denoise_1->join(); delete m_ptrThread_Airth_4_Y16Denoise_1; m_ptrThread_Airth_4_Y16Denoise_1 = nullptr; } if(nullptr != m_ptrThread_Airth_5_Y16DDE) { m_ptrThread_Airth_5_Y16DDE->join(); delete m_ptrThread_Airth_5_Y16DDE; m_ptrThread_Airth_5_Y16DDE = nullptr; } if(nullptr != m_ptrThread_Airth_6_Y16IDE) { m_ptrThread_Airth_6_Y16IDE->join(); delete m_ptrThread_Airth_6_Y16IDE; m_ptrThread_Airth_6_Y16IDE = nullptr; } if(nullptr != m_ptrThread_Airth_7_Y8Map) { m_ptrThread_Airth_7_Y8Map->join(); delete m_ptrThread_Airth_7_Y8Map; m_ptrThread_Airth_7_Y8Map = nullptr; } } bool TGAirthProcess::PushData(unsigned char *pFrameData, int nFrameSize) { int nRes = 0; return m_varY16Data_IN.PushBack(pFrameData,nFrameSize,nRes); } bool TGAirthProcess::GetData(unsigned char *pFrameData, int nFrameSize) { return m_varY8Data_OUT.GetFront(pFrameData,nFrameSize); } void TGAirthProcess::SetImgFormat(GFrameFormat& p_ImgFormat) { m_varGFrameFormat = p_ImgFormat; } void TGAirthProcess::ThreadEntry(ThreadRunFunPtr pRunFun, void* pOwner) { TGAirthProcess* pThis = reinterpret_cast(pOwner); if (NULL == pThis) { return; } (pThis->*pRunFun)(); } void TGAirthProcess::ImgProcess(unsigned short *pSrc, unsigned char *pDst, int nWidth, int nHeight) { GLogger::GetInstance()->WriteInfo("Airth Start"); switch (m_varGFrameFormat.ePT) { case ePT_Y16U: { ImgDeMean((ushort*)pSrc, (ushort*)pDst ,nWidth,nHeight); //TODO: //其他机芯算法 } break; case ePT_Y16: { ImgPreProcess((short*)pSrc, (ushort*)pDst ,nWidth,nHeight); ImgDeMean((ushort*)pDst, (ushort*)pDst ,nWidth,nHeight); //TODO: //其他机芯算法 } break; default: break; } GLogger::GetInstance()->WriteInfo("PreDeal"); } void TGAirthProcess::ThreadFun_MappingData_Airth_0_PreDeal() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; byte* pDst = new byte[DefaultMaxImageSize]; std::chrono::system_clock::time_point tmPrevious = std::chrono::system_clock::now(); std::chrono::system_clock::time_point tmNow; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { // 控制调光速度(结束) int nRes = 0; int nFrameSize = 0; if(!m_varY16Data_IN.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } // 控制调光速度(开始) wzy:可能丢帧 tmNow = std::chrono::system_clock::now(); if((tmNow - tmPrevious).count() < 40*10000) { std::this_thread::sleep_for(std::chrono::milliseconds(5) ); continue; } tmPrevious = tmNow; ImgProcess((ushort*)pSrc,pDst,m_varGFrameFormat.nImageWidth,m_varGFrameFormat.nImageHeight); m_varAirth_0_PreDeal.PushBack(pDst, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel, nRes); } delete [] pSrc; pSrc = nullptr; delete [] pDst; pDst = nullptr; timeEndPeriod(1); std::this_thread::sleep_for(std::chrono::milliseconds(5) ); } void TGAirthProcess::ThreadFun_MappingData_Airth_1_DeGuoGai() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; // byte* pDst = new byte[c_nWMemSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; if(!m_varAirth_0_PreDeal.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } //时域滤波 if (m_TGInfo.IsTimeFilter) { TimeNoiseFliterDll((ushort*)pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight,m_TGInfo.TFSigma, 5); GLogger::GetInstance()->WriteInfo("TimeNoiseFliter"); } //去锅盖 if (m_TGInfo.DeGuoGaiArith) { DeGuoGai((ushort*)pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight,m_TGInfo.GuoGaiModel, m_TGInfo.GuogaiB); GLogger::GetInstance()->WriteInfo("DeGuoGaiArith"); } m_varAirth_1_DeGuoGai.PushBack(pSrc, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel, nRes); } delete [] pSrc; pSrc = nullptr; // delete [] pDst; // pDst = nullptr; timeEndPeriod(1); } void TGAirthProcess::ThreadFun_MappingData_Airth_2_DeBadPixel() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; byte* pDst = new byte[DefaultMaxImageSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; if(!m_varAirth_1_DeGuoGai.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } //单帧去坏点 if (m_TGInfo.DeBadPixel) { int nBadPoint = 0; BadPixelDeTect((ushort*)pSrc, pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight, 5, 30,nBadPoint); GLogger::GetInstance()->WriteInfo("DeBadPixel"); } m_varAirth_2_DeBadPixel.PushBack(pSrc, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel, nRes); } delete [] pSrc; pSrc = nullptr; delete [] pDst; pDst = nullptr; timeEndPeriod(1); } void TGAirthProcess::ThreadFun_MappingData_Airth_3_Destrip() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; // byte* pDst = new byte[c_nWMemSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; if(!m_varAirth_2_DeBadPixel.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } //去竖条纹 switch (m_TGInfo.DestripArithIdx) { case 1: //传统 RemoveVecStripeNoise((ushort*)pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight,m_TGInfo.StripStd,9,m_TGInfo.StripWeight,15); break; case 2: //4段 RemoveVecStripeNoiseByFourPart((ushort*)pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight,m_TGInfo.StripStd,9,m_TGInfo.StripWeight,15); break; // case 3: //改进 // RemoveVecStripeNoiseRowColFilter((ushort*)pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight,m_TGInfo.StripStd,9,m_TGInfo.StripWeight,15,false); // break; default: //无算法 break; } GLogger::GetInstance()->WriteInfo("DestripArithIdx"); m_mutex0.lock(); m_varAirth_3_Destrip_0.PushBack(pSrc, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2, nRes); m_varAirth_3_Destrip_1.PushBack(pSrc+m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2, nRes); m_mutex0.unlock(); } delete [] pSrc; pSrc = nullptr; // delete [] pDst; // pDst = nullptr; timeEndPeriod(1); } void TGAirthProcess::ThreadFun_MappingData_Airth_4_Y16Denoise_0() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; byte* pDst = new byte[DefaultMaxImageSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; if(!m_varAirth_3_Destrip_0.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } //去噪 switch (m_TGInfo.DenoiseArith) { case 1: //NLM Y16 NlMeansDll(16, (ushort*)pSrc, pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight/2, 7, 3, 1,m_TGInfo.DenoiseStd); GLogger::GetInstance()->WriteInfo("DenoiseArith0"); break; default: break; } m_varAirth_4_Y16Denois_0.PushBack(pSrc, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2, nRes); } delete [] pSrc; pSrc = nullptr; delete [] pDst; pDst = nullptr; timeEndPeriod(1); } void TGAirthProcess::ThreadFun_MappingData_Airth_4_Y16Denoise_1() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; byte* pDst = new byte[DefaultMaxImageSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; if(!m_varAirth_3_Destrip_1.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } //去噪 switch (m_TGInfo.DenoiseArith) { case 1: //NLM Y16 NlMeansDll(16, (ushort*)pSrc, pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight/2, 7, 3, 1,m_TGInfo.DenoiseStd); GLogger::GetInstance()->WriteInfo("DenoiseArith1"); break; default: break; } m_varAirth_4_Y16Denois_1.PushBack(pSrc, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2, nRes); } delete [] pSrc; pSrc = nullptr; delete [] pDst; pDst = nullptr; timeEndPeriod(1); } void TGAirthProcess::ThreadFun_MappingData_Airth_5_Y16DDE() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; byte* pSrc1 = new byte[DefaultMaxImageSize]; // byte* pDst = new byte[c_nWMemSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; if(!m_varAirth_4_Y16Denois_0.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } while(m_bThreadRunning_MappingData && !m_varAirth_4_Y16Denois_1.GetFront(pSrc1, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } memcpy_s(pSrc+m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2,m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2,pSrc1,m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel/2); //DDE if (m_TGInfo.DDEArith == 0) { LaplaceSharpenDll((ushort*)pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight, 1, 1, m_TGInfo.DDEParam); GLogger::GetInstance()->WriteInfo("Y16DDEArith"); } m_varAirth_5_Y16DDE.PushBack(pSrc, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight*m_varGFrameFormat.nBytesOfPixel, nRes); } delete [] pSrc; pSrc = nullptr; delete [] pSrc1; pSrc1 = nullptr; timeEndPeriod(1); } void TGAirthProcess::ThreadFun_MappingData_Airth_6_Y16IDE() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; //byte* pSrc1 = new byte[DefaultMaxImageSize]; byte* pDst = new byte[DefaultMaxImageSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; // if(m_varGFrameFormat.ePT != ePT_Y8) // { if(!m_varAirth_5_Y16DDE.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } //IDE if (m_TGInfo.IDEArith) { // switch (m_TGInfo.IDEArith) // { // case 1: // // IDE_MultiScaleEnhanceDll((ushort*)pSrc,pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight, 5, 0.0, 0.2, 0.1, m_MixMapPara, m_MixMapOut, false, m_MixMapPara.MapMethod, m_TGInfo.Clahe); // break; // case 2: IDE_MSR_BFDll((ushort*)pSrc, pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight,5,m_MixMapPara, m_MixMapOut); // break; // default: // break; // } } else { if(m_varGFrameFormat.ePT == ePT_Y16U || m_varGFrameFormat.ePT == ePT_Y16\ || m_varGFrameFormat.ePT == ePT_X16 || m_varGFrameFormat.ePT == ePT_XMix16) //Y8数据不调光 { //调光(此算法横向滚动灰阶图像有黑宽线)(DDE接口导致) // MixTiaoGuangDll((ushort*)pSrc, pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight, m_MixMapPara, m_MixMapOut); //先调用ImgDeMean // ImgDeMean((ushort*)pSrc, (ushort*)pSrc1, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight); // m_MixMapPara.LeftDiscard = 1; // m_MixMapPara.RightDiscard = 1; // m_MixMapPara.MixMedthod = 0; BBHE_MixTiaoGuangDll((ushort*)pSrc, pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight,m_MixMapPara, m_MixMapOut); if (m_TGInfo.Clahe) { ClaheMappingDll((ushort*)pSrc, pDst, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight, 1, m_MixMapPara.nClaheWinSize, m_MixMapPara.nClaheLimit, m_MixMapPara); } } } GLogger::GetInstance()->WriteInfo("Y16IDEArith"); m_varAirth_6_Y16IDE.PushBack(pDst, m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight, nRes); // } } if(pSrc) { delete [] pSrc; pSrc = nullptr; } if(pDst) { delete [] pDst; pDst = nullptr; } // if(pSrc1) // { // delete [] pSrc1; // pSrc1 = nullptr; // } timeEndPeriod(1); } void TGAirthProcess::ThreadFun_MappingData_Airth_7_Y8Map() { timeBeginPeriod(1); byte* pSrc = new byte[DefaultMaxImageSize]; // byte* pDst = new byte[c_nWMemSize]; //GLogger::GetInstance()->WriteInfo("Dev-Ch1 start Mapping"); while(m_bThreadRunning_MappingData) { int nRes = 0; int nFrameSize = 0; if(!m_varAirth_6_Y16IDE.GetFront(pSrc, nFrameSize) ) { std::this_thread::sleep_for(std::chrono::milliseconds(10) ); continue; } //Y8纠偏 // ManualAdjustBC(pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight, 55, 90); // GLogger::GetInstance()->WriteInfo("ManualAdjustBC"); //Y8映射 // Y8ImgMapping(pSrc, m_varGFrameFormat.nImageWidth, m_varGFrameFormat.nImageHeight, m_TGInfo.Y8MapIdx); // GLogger::GetInstance()->WriteInfo("Y8ImgMapping"); m_varY8Data_OUT.PushBack(pSrc,m_varGFrameFormat.nImageWidth*m_varGFrameFormat.nImageHeight, nRes); } if(pSrc) { delete [] pSrc; pSrc = nullptr; } timeEndPeriod(1); }