@ -197,10 +197,6 @@ deal::deal()
m_nProductReadThreadNum = READ_PRODUCT_THREAD_NUM ;
m_nProductReadThreadNum = READ_PRODUCT_THREAD_NUM ;
m_nProductQueueMaxSize = PRODUCT_QUEUE_MAX_SIZE ;
m_nProductQueueMaxSize = PRODUCT_QUEUE_MAX_SIZE ;
m_nCheckNotifiedCount = 0 ;
m_nCheckNotifiedCount = 0 ;
// ✅ 图片尺寸一致性保护
m_nExpectedImgWidth = - 1 ;
m_nExpectedImgHeight = - 1 ;
}
}
deal : : ~ deal ( )
deal : : ~ deal ( )
@ -1490,10 +1486,6 @@ int deal::CheckProduct(const LoadProductImages &product)
m_ProductFailedList . clear ( ) ;
m_ProductFailedList . clear ( ) ;
m_nCheckNotifiedCount = 0 ;
m_nCheckNotifiedCount = 0 ;
// ✅ 重置图片期望尺寸(每个产品批次独立)
m_nExpectedImgWidth = - 1 ;
m_nExpectedImgHeight = - 1 ;
// ✅ 修复内存泄漏: 清理上一个产品累积的原始图像数据( cv::Mat)
// ✅ 修复内存泄漏: 清理上一个产品累积的原始图像数据( cv::Mat)
// 注意: m_DetResult 是统计结果(轻量字符串/数字),不清除,跨产品累积
// 注意: m_DetResult 是统计结果(轻量字符串/数字),不清除,跨产品累积
m_ImageInfoList . clear ( ) ;
m_ImageInfoList . clear ( ) ;
@ -1675,42 +1667,6 @@ int deal::SendCheckImg(const CheckImgNotifyInfo &info, IN_IMG_Status_ status, bo
m_nProductSuccessCount . fetch_add ( 1 ) ;
m_nProductSuccessCount . fetch_add ( 1 ) ;
// ✅ 图片尺寸一致性保护:获取当前图片的有效图像
cv : : Mat curImg ;
if ( ! info . left_img . empty ( ) )
{
curImg = info . left_img ;
}
else if ( ! info . right_img . empty ( ) )
{
curImg = info . right_img ;
}
if ( ! curImg . empty ( ) )
{
// 首次设置期望尺寸
if ( m_nExpectedImgWidth < 0 | | m_nExpectedImgHeight < 0 )
{
m_nExpectedImgWidth = curImg . cols ;
m_nExpectedImgHeight = curImg . rows ;
printf ( " [尺寸基准] 产品 %s 首张图片尺寸: %dx%d (channel: %s) \n " ,
info . productId . c_str ( ) , m_nExpectedImgWidth , m_nExpectedImgHeight ,
info . channelName . c_str ( ) ) ;
}
// 尺寸不一致时, resize 到期望尺寸
else if ( curImg . cols ! = m_nExpectedImgWidth | | curImg . rows ! = m_nExpectedImgHeight )
{
printf ( " [尺寸修正] 产品 %s 图片尺寸不一致: 期望 %dx%d, 实际 %dx%d (channel: %s), 正在resize... \n " ,
info . productId . c_str ( ) ,
m_nExpectedImgWidth , m_nExpectedImgHeight ,
curImg . cols , curImg . rows ,
info . channelName . c_str ( ) ) ;
cv : : Mat resizedImg ;
cv : : resize ( curImg , resizedImg , cv : : Size ( m_nExpectedImgWidth , m_nExpectedImgHeight ) ) ;
curImg = resizedImg ;
}
}
std : : shared_ptr < shareImage > tem = std : : make_shared < shareImage > ( ) ;
std : : shared_ptr < shareImage > tem = std : : make_shared < shareImage > ( ) ;
tem - > strChannel = info . channelName ;
tem - > strChannel = info . channelName ;
@ -1745,9 +1701,13 @@ int deal::SendCheckImg(const CheckImgNotifyInfo &info, IN_IMG_Status_ status, bo
{
{
if ( ! curImg . empty ( ) )
if ( ! info . left_img . empty ( ) )
{
tem - > img = info . left_img ;
}
else if ( ! info . right_img . empty ( ) )
{
{
tem - > img = curImg ;
tem - > img = info. right_i mg;
}
}
}
}