update 同步修改

main
liusiyang 2 weeks ago
parent a948ff6c9b
commit 3e51c2ea47

@ -122,6 +122,9 @@ private:
int MergeShowImg(std::shared_ptr<Product> product); // 合并图片 int MergeShowImg(std::shared_ptr<Product> product); // 合并图片
// 清理产品list
void Clear_m_ProductList();
// 异常返回 // 异常返回
int ErrorReturn(std::shared_ptr<shareImage> p); int ErrorReturn(std::shared_ptr<shareImage> p);
@ -156,6 +159,9 @@ private:
std::shared_ptr<DetLog> m_pdetlog; std::shared_ptr<DetLog> m_pdetlog;
// 当前检测产品的个数
int m_CurProductIdx = 0;
std::queue<std::shared_ptr<CheckResult>> m_CheckResultList; // 检测结果 std::queue<std::shared_ptr<CheckResult>> m_CheckResultList; // 检测结果
std::mutex mtx_CheckResult; // 互斥锁,用于保护数据队列 std::mutex mtx_CheckResult; // 互斥锁,用于保护数据队列
std::condition_variable CheckResult_cond; // 条件变量,用于同步生产者和消费者线程 std::condition_variable CheckResult_cond; // 条件变量,用于同步生产者和消费者线程

@ -47,6 +47,8 @@ public:
std::shared_ptr<ProductBaseResult> productBaseResult; std::shared_ptr<ProductBaseResult> productBaseResult;
// 图片是否都送完了。 // 图片是否都送完了。
bool bIsImgComplete = false; bool bIsImgComplete = false;
// product使用计数
int productUseCount = 0;
// 日志 // 日志
std::vector<std::string> LogList; std::vector<std::string> LogList;
std::mutex mtx_CameraResultList; std::mutex mtx_CameraResultList;

@ -545,9 +545,14 @@ int ALLImgCheckAnalysisy::PushInImg_New(std::shared_ptr<shareImage> p)
strlog += "isnot exist"; strlog += "isnot exist";
//设置其他m_ProductList送图状态设置为结束 //设置其他m_ProductList送图状态设置为结束
cout << "-------set m_ProductList other product to end-------" << endl ; cout << "-------set m_ProductList other product to end-------" << endl ;
std::lock_guard<std::mutex> lock(mtx_ProductList);
for(auto &tem:m_ProductList){ for(auto &tem:m_ProductList){
tem->bIsImgComplete = true; tem->bIsImgComplete = true;
} }
if(-1 == p->Status)
{
return CHECK_ERROR_PushImg_ID_Error;
}
} }
// 产品不存在 新建一个 // 产品不存在 新建一个
@ -557,13 +562,19 @@ int ALLImgCheckAnalysisy::PushInImg_New(std::shared_ptr<shareImage> p)
{ {
if (m_ProductList.size() > 50) if (m_ProductList.size() > 50)
{ {
Clear_m_ProductList();
return CHECK_ERROR_PushImg_ListSize; return CHECK_ERROR_PushImg_ListSize;
} }
} }
strlog += " | create new product"; strlog += " | create new product";
product = std::make_shared<Product>(); product = std::make_shared<Product>();
product->productBaseResult->strproductName = p->strImgProductID; product->productBaseResult->strproductName = p->strImgProductID;
if (m_CurProductIdx > 999999)
{
m_CurProductIdx = 0;
}
product->productUseCount = m_CurProductIdx;
m_CurProductIdx++;
m_ProductList.push_back(product); m_ProductList.push_back(product);
std::string strTimg = CheckUtil::getCurTimeHMS(); std::string strTimg = CheckUtil::getCurTimeHMS();
product->productBaseResult->detlog->bPrintStr = true; product->productBaseResult->detlog->bPrintStr = true;
@ -687,7 +698,26 @@ int ALLImgCheckAnalysisy::MergeShowImg(std::shared_ptr<Product> product)
return 0; return 0;
} }
void ALLImgCheckAnalysisy::Clear_m_ProductList(){
int num = m_ProductList.size();
string strlog = "";
printf("******************\n\n m_ProductImgDetResultList %ld \n", m_ProductList.size());
std::lock_guard<std::mutex> lock(mtx_ProductList);
int idx = -1;
for (int i = 0; i < m_ProductList.size(); i++)
{
int sub = std::abs(m_CurProductIdx - m_ProductList.at(i)->productUseCount);
if (sub > 50)
{
// 删除指定位置的元素
// m_ProductList.at(i)->productBaseResult->detlog->AddCheckstr(PrintLevel_0, "PushInImg", "%s Delete size > %d; m_CurProductIdx %d - nNotDetCount %d > 50",
// m_ProductList.at(i)->,
// m_ProductList.size(), m_CurProductIdx,
// m_ProductList.at(i)->productUseCount);
m_ProductList.erase(m_ProductList.begin() + i);
}
}
}
int ALLImgCheckAnalysisy::Run() int ALLImgCheckAnalysisy::Run()
{ {

@ -255,7 +255,7 @@ int CameraCheckAnalysisy::Detect_Images()
} }
else else
{ {
printf("Cam Detect_Images %s ==================No send end\n", strBasic.c_str()); // printf("Cam Detect_Images %s ==================No send end\n", strBasic.c_str());
} }
} }
} }
@ -344,7 +344,7 @@ int CameraCheckAnalysisy::ResultParamJudge()
long t2 = CheckUtil::getcurTime(); long t2 = CheckUtil::getcurTime();
m_imageResultJudge.DrawResult(m_pCheck_Result->ImageALLDetResultList.at(imgidx)); m_imageResultJudge.DrawResult(m_pCheck_Result->ImageALLDetResultList.at(imgidx));
long t3 = CheckUtil::getcurTime(); long t3 = CheckUtil::getcurTime();
m_pdetlog->AddCheckstr(PrintLevel_1, "ResultParamJudge", " det time %ld ms judge %ld draw %ld", t3 - t1, t2 - t1, t3 - t2); // m_pdetlog->AddCheckstr(PrintLevel_1, "ResultParamJudge", " det time %ld ms judge %ld draw %ld", t3 - t1, t2 - t1, t3 - t2);
// 把结果转成 json 保存。 用以复测 // 把结果转成 json 保存。 用以复测
std::shared_ptr<CheckResult> m_CheckResult_shareP = m_pCheck_Result->ImageALLDetResultList.at(imgidx)->result; std::shared_ptr<CheckResult> m_CheckResult_shareP = m_pCheck_Result->ImageALLDetResultList.at(imgidx)->result;
@ -767,7 +767,7 @@ int CameraCheckAnalysisy::CheckImgRun()
m_pdetlog->bPrintStr = false; m_pdetlog->bPrintStr = false;
m_pdetlog->AddCheckstr(PrintLevel_1, "CheckImgRun", "Cam %s ------Product_Off_X_mm %f ", m_pdetlog->AddCheckstr(PrintLevel_1, "CheckImgRun", "Cam %s ------Product_Off_X_mm %f ",
m_strcameraName.c_str(), m_AnalysisyConfig.commonCheckConfig.baseConfig.fProduct_Off_X_mm); m_strcameraName.c_str(), m_AnalysisyConfig.commonCheckConfig.baseConfig.fProduct_Off_X_mm);
m_pdetlog->bPrintStr = true;
// 如果是未检测状态,则开始预处理 // 如果是未检测状态,则开始预处理
if (curcheckStep == Check_Step_NODet) if (curcheckStep == Check_Step_NODet)
{ {

@ -64,7 +64,7 @@ int CameraResult::AddDetImage(std::shared_ptr<shareImage> p)
} }
} }
std::string strTimg = CheckUtil::getCurTimeHMS(); std::string strTimg = CheckUtil::getCurTimeHMS();
detlog->bPrintStr = false; detlog->bPrintStr = true;
detlog->AddCheckstr(PrintLevel_0, "PushInImg", " product %s Cam %s add new image channel = %s sum img %ld %s", detlog->AddCheckstr(PrintLevel_0, "PushInImg", " product %s Cam %s add new image channel = %s sum img %ld %s",
productBaseResult->strproductName.c_str(), productBaseResult->strproductName.c_str(),
cameraBaseResult->strCameraName.c_str(), imgResult->strChannel.c_str(), ImageALLDetResultList.size(), strTimg.c_str()); cameraBaseResult->strCameraName.c_str(), imgResult->strChannel.c_str(), ImageALLDetResultList.size(), strTimg.c_str());

@ -38,7 +38,7 @@ int Edge_Search::Detect(const cv::Mat &detimg, DetConfigResult *pDetConfig, std:
m_pdetlog = pDetConfig->pdetlog; m_pdetlog = pDetConfig->pdetlog;
if (pDetConfig->bDebugsaveImg) if (pDetConfig->bDebugsaveImg)
{ {
m_pdetlog->bPrintStr = false; m_pdetlog->bPrintStr = true;
} }
int re = 0; int re = 0;
bool bdraw = pDetConfig->pEdgeROI->Use_DrawROI; bool bdraw = pDetConfig->pEdgeROI->Use_DrawROI;

@ -423,7 +423,7 @@ int ImgCheckAnalysisy::CheckRun()
{ {
m_pdetlog->bPrintStr = true; m_pdetlog->bPrintStr = true;
} }
m_pdetlog->bPrintStr = false; m_pdetlog->bPrintStr = true;
m_pdetlog->AddCheckstr(PrintLevel_0, "1、basic Info", "---------------------------1、basic Info---------------------------------"); m_pdetlog->AddCheckstr(PrintLevel_0, "1、basic Info", "---------------------------1、basic Info---------------------------------");
m_pdetlog->AddCheckstr(PrintLevel_0, "Version", "%s", GetVersion().c_str()); m_pdetlog->AddCheckstr(PrintLevel_0, "Version", "%s", GetVersion().c_str());
@ -441,9 +441,9 @@ int ImgCheckAnalysisy::CheckRun()
m_strCurDetChannel = m_CheckResult_shareP->basicResult.strChannel; m_strCurDetChannel = m_CheckResult_shareP->basicResult.strChannel;
m_strCurDetCamChannel = m_pImageAllResult->cameraBaseResult->strCameraName + "_" + m_strCurDetChannel; m_strCurDetCamChannel = m_pImageAllResult->cameraBaseResult->strCameraName + "_" + m_strCurDetChannel;
cout << "Version: " << GetVersion() << endl; // cout << "Version: " << GetVersion() << endl;
cout << "CameraName: " << m_pImageAllResult->cameraBaseResult->strCameraName << endl; // cout << "CameraName: " << m_pImageAllResult->cameraBaseResult->strCameraName << endl;
cout << "strChannel: " << m_CheckResult_shareP->basicResult.strChannel<< endl; // cout << "strChannel: " << m_CheckResult_shareP->basicResult.strChannel<< endl;
// 2、参数检查 // 2、参数检查
int rec = ConfigCheck(DetImgInfo_shareP->img); int rec = ConfigCheck(DetImgInfo_shareP->img);

@ -34,7 +34,7 @@ std::shared_ptr<CameraResult> Product::GetCameraResult(std::string strcameraName
return ptr; return ptr;
} }
} }
productBaseResult->detlog->bPrintStr = false; productBaseResult->detlog->bPrintStr = true;
// 不存在,创建新的 CameraResult 并插入 map // 不存在,创建新的 CameraResult 并插入 map
std::shared_ptr<CameraResult> newResult = std::make_shared<CameraResult>(); std::shared_ptr<CameraResult> newResult = std::make_shared<CameraResult>();
newResult->productBaseResult = productBaseResult; newResult->productBaseResult = productBaseResult;

Loading…
Cancel
Save