暗场临时不使用AI定位

dev_lsy
liusiyang 3 weeks ago
parent 9f5ea55415
commit e102fc5edd

@ -200,7 +200,7 @@ private:
int BLobToDetResult(); int BLobToDetResult();
//自适应参数区域更新 //自适应参数区域更新
int Adapt_Config(Mat img, Rect roi, bool b_update); int Adapt_Config(Mat img, Rect roi, bool b_update, cv::RotatedRect &rot_cur_roi);
std::shared_ptr<AIFactory> AI_Factory; std::shared_ptr<AIFactory> AI_Factory;

@ -451,7 +451,7 @@ Point2f GetCoorPoint(Point2f point, Mat img_mat)
return new_point; return new_point;
} }
int GetEdgeRoi(Mat img, Rect &new_roi, cv::RotatedRect &rotated_roi, float scale_x, float scale_y){ int GetEdgeRoi(Mat img, Rect &new_roi, cv::RotatedRect &rotated_roi, float scale_x, float scale_y, string cur_channel){
if (img.empty()) if (img.empty())
{ {
return 1; return 1;
@ -465,9 +465,22 @@ int GetEdgeRoi(Mat img, Rect &new_roi, cv::RotatedRect &rotated_roi, float scale
// 二值化找最大连通域 // 二值化找最大连通域
Mat r_img_bin; Mat r_img_bin;
threshold(r_img, r_img_bin, 15, 255, THRESH_BINARY); if(cur_channel == "BCA" || cur_channel == "BTA")
{
threshold(r_img, r_img_bin, 35, 255, THRESH_BINARY);
}
else
{
threshold(r_img, r_img_bin, 35, 255, THRESH_BINARY);
}
// 做一步开运算
Mat r_img_bin_close;
morphologyEx(r_img_bin, r_img_bin_close, MORPH_CLOSE, Mat::ones(15, 15, CV_8U));
// imwrite("r_img_bin.tif", r_img_bin);
// imwrite("r_img_bin_close.tif", r_img_bin_close);
// imwrite("r_img.tif", r_img);
std::vector<std::vector<cv::Point>> contours; std::vector<std::vector<cv::Point>> contours;
cv::findContours(r_img_bin, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE); cv::findContours(r_img_bin_close, contours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
if (contours.empty()) if (contours.empty())
{ {
return 2; return 2;
@ -599,7 +612,7 @@ std::vector<cv::Point2f> sort_vertices(cv::RotatedRect rrect) {
return vertices; return vertices;
} }
int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, bool b_update){ int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, bool b_update, cv::RotatedRect &rot_cur_roi){
if (img.empty()) { if (img.empty()) {
std::cerr << "Error: Input image 'img' is empty!" << std::endl; std::cerr << "Error: Input image 'img' is empty!" << std::endl;
return -1; return -1;
@ -607,8 +620,8 @@ int ImgCheckAnalysisy::Adapt_Config(Mat img, Rect cur_roi, bool b_update){
if(!b_update){ if(!b_update){
return 1; return 1;
} }
cv::RotatedRect rot_cur_roi; // cv::RotatedRect rot_cur_roi;
int get_edge_roi = GetEdgeRoi(img, cur_roi, rot_cur_roi, 20, 20); int get_edge_roi = GetEdgeRoi(img, cur_roi, rot_cur_roi, 20, 20, m_CheckResult_shareP->basicResult.strChannel);
if(get_edge_roi != 0){ if(get_edge_roi != 0){
return 2; return 2;
} }
@ -798,7 +811,11 @@ int ImgCheckAnalysisy::CheckRun()
m_strCurDetChannel = m_CheckResult_shareP->basicResult.strChannel; m_strCurDetChannel = m_CheckResult_shareP->basicResult.strChannel;
/*自适应更新参数*/ /*自适应更新参数*/
Adapt_Config(m_CheckResult_shareP->in_shareImage->img, m_CutRoi, m_pbaseCheckFunction->markLine.badapt_region); long time_adapt_s = CheckUtil::getcurTime();
cv::RotatedRect rot_cur_roi;
Adapt_Config(m_CheckResult_shareP->in_shareImage->img, m_CutRoi, m_pbaseCheckFunction->markLine.badapt_region, rot_cur_roi);
long time_adapt_e = CheckUtil::getcurTime();
m_pdetlog->AddCheckstr(PrintLevel_0, "Adapt_Config", "time = %ld", time_adapt_e - time_adapt_s);
// 2、参数检查 // 2、参数检查
int rec = ConfigCheck(DetImgInfo_shareP->img); int rec = ConfigCheck(DetImgInfo_shareP->img);
@ -811,14 +828,25 @@ int ImgCheckAnalysisy::CheckRun()
} }
long time_edge_s = CheckUtil::getcurTime(); long time_edge_s = CheckUtil::getcurTime();
// 3、AI 边缘定位 // 3、AI 边缘定位
int reedge = AI_Edge(m_CheckResult_shareP->in_shareImage->img, m_CutRoi); if(m_CheckResult_shareP->basicResult.strChannel == "DCA" || m_CheckResult_shareP->basicResult.strChannel == "DTA")
if (reedge != 0)
{ {
m_pdetlog->AddCheckstr(PrintLevel_0, "Error", "AI_Edge is error type = %d", reedge); m_pdetlog->AddCheckstr(PrintLevel_0, "Edge", "Not Use AI_Edge %s", m_CheckResult_shareP->basicResult.strChannel.c_str());
m_nErrorCode = reedge; m_CutRoi = cv::Rect(rot_cur_roi.boundingRect().x - 50 , rot_cur_roi.boundingRect().y - 50, rot_cur_roi.boundingRect().width + 100, rot_cur_roi.boundingRect().height + 100)
m_nCheckResultErrorCode = m_nErrorCode; & cv::Rect(0, 0, m_CheckResult_shareP->in_shareImage->img.cols, m_CheckResult_shareP->in_shareImage->img.rows);
return m_nErrorCode;
} }
else
{
m_pdetlog->AddCheckstr(PrintLevel_0, "Edge", "Use AI_Edge %s", m_CheckResult_shareP->basicResult.strChannel.c_str());
int reedge = AI_Edge(m_CheckResult_shareP->in_shareImage->img, m_CutRoi);
if (reedge != 0)
{
m_pdetlog->AddCheckstr(PrintLevel_0, "Error", "AI_Edge is error type = %d", reedge);
m_nErrorCode = reedge;
m_nCheckResultErrorCode = m_nErrorCode;
return m_nErrorCode;
}
}
long time_edge_e = CheckUtil::getcurTime(); long time_edge_e = CheckUtil::getcurTime();
m_pdetlog->AddCheckstr(PrintLevel_0, "2、pre detect", "-------------------------AI_Edge------------succ---time %ld----\n", time_edge_e - time_edge_s); m_pdetlog->AddCheckstr(PrintLevel_0, "2、pre detect", "-------------------------AI_Edge------------succ---time %ld----\n", time_edge_e - time_edge_s);

Loading…
Cancel
Save