@ -465,9 +465,12 @@ int GetEdgeRoi(Mat img, Rect &new_roi, cv::RotatedRect &rotated_roi, float scale
// 二值化找最大连通域
Mat r_img_bin ;
threshold ( r_img , r_img_bin , 15 , 255 , THRESH_BINARY ) ;
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 ) ) ;
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 ( ) )
{
return 2 ;
@ -779,7 +782,6 @@ int ImgCheckAnalysisy::CheckRun()
{
m_pdetlog - > bPrintStr = true ;
}
m_pdetlog - > bPrintStr = true ;
m_pdetlog - > AddCheckstr ( PrintLevel_0 , " 1、basic Info " , " ---------------------------1、basic Info--------------------------------- " ) ;
m_pdetlog - > AddCheckstr ( PrintLevel_0 , " Version " , " %s " , GetVersion ( ) . c_str ( ) ) ;
@ -2509,9 +2511,43 @@ int ImgCheckAnalysisy::BLobToDetResult()
long t1 = CheckUtil : : getcurTime ( ) ;
m_pdetlog - > AddCheckstr ( PrintLevel_1 , DET_LOG_LEVEL_3 , " BLobToDetResult " , " Start old qx num %ld " , m_pDetResult - > pQx_ErrorList - > size ( ) ) ;
// 传统检测:按 nAreaFilter( 原图面积) + nCountFilter( 个数) 直接卡控最终上报。
// 对 blobs.blobTab 按面积降序,过滤 area <= nAreaFilter 的 blob, 再取前 nCountFilter 个。
// AI 路径( bOpen=false) 不做此过滤, 保持原有全量上报。
const bool bTcsCountFilter = ( m_pbaseCheckFunction ! = nullptr & & m_pbaseCheckFunction - > traditionDet . bOpen ) ;
const float fAreaFilter = bTcsCountFilter ? m_pbaseCheckFunction - > traditionDet . nAreaFilter : 0.0f ;
const int nCountFilter = bTcsCountFilter ? m_pbaseCheckFunction - > traditionDet . nCountFilter : blobs . blobCount ;
int nFiltered = 0 ;
// 传统路径:构造按面积降序的索引,用于面积 + 个数卡控
std : : vector < int > sortedIdx ;
int nReport = blobs . blobCount ; // 实际需要遍历上报的 blob 数量
if ( bTcsCountFilter )
{
sortedIdx . resize ( blobs . blobCount ) ;
for ( int j = 0 ; j < blobs . blobCount ; j + + ) sortedIdx [ j ] = j ;
std : : sort ( sortedIdx . begin ( ) , sortedIdx . end ( ) , [ & ] ( int a , int b ) {
return blobs . blobTab [ a ] . area > blobs . blobTab [ b ] . area ;
} ) ;
// 已按面积降序:第一个 area <= nAreaFilter 的 blob 即为有效区间终点
nReport = 0 ;
while ( nReport < blobs . blobCount & & blobs . blobTab [ sortedIdx [ nReport ] ] . area > fAreaFilter )
{
nReport + + ;
}
if ( nReport > nCountFilter )
{
nReport = nCountFilter ;
}
nFiltered = blobs . blobCount - nReport ;
}
// 遍历每个检测blob
for ( int i = 0 ; i < blobs . blobCount ; i + + )
for ( int i dx = 0 ; i dx < nRepor t; i dx + + )
{
const int i = bTcsCountFilter ? sortedIdx [ idx ] : idx ;
cv : : Rect roi ;
roi . x = blobs . blobTab [ i ] . minx ;
roi . y = blobs . blobTab [ i ] . miny ;
@ -2591,7 +2627,7 @@ int ImgCheckAnalysisy::BLobToDetResult()
}
}
long t2 = CheckUtil : : getcurTime ( ) ;
m_pdetlog - > AddCheckstr ( PrintLevel_1 , DET_LOG_LEVEL_3 , " BLobToDetResult " , " end qx num %ld use time %ld" , m_pDetResult - > pQx_ErrorList - > size ( ) , t2 - t1 ) ;
m_pdetlog - > AddCheckstr ( PrintLevel_1 , DET_LOG_LEVEL_3 , " BLobToDetResult " , " end qx num %ld filtered %d use time %ld" , m_pDetResult - > pQx_ErrorList - > size ( ) , nFiltered , t2 - t1 ) ;
return 0 ;
}