11#include " DimensionDetector.h"
2+ #include " ../common/Logger.h"
23#include < QElapsedTimer>
34
45DimensionDetector::DimensionDetector () {
@@ -54,10 +55,14 @@ DetectionResult DimensionDetector::detect(const cv::Mat& image) {
5455 timer.start ();
5556
5657 if (image.empty ()) {
58+ LOG_ERROR (" DimensionDetector::detect - Input image is empty" );
5759 return makeErrorResult (" Empty input image" );
5860 }
5961
6062 updateParameters ();
63+
64+ LOG_DEBUG (" DimensionDetector::detect - Input: {}x{}, target: {:.2f}x{:.2f}mm, tolerance: {:.2f}mm, calibration: {:.4f}mm/px" ,
65+ image.cols , image.rows , m_targetWidth, m_targetHeight, m_tolerance, m_calibration);
6166
6267 // 预处理
6368 cv::Mat binary = preprocessImage (image);
@@ -66,6 +71,21 @@ DetectionResult DimensionDetector::detect(const cv::Mat& image) {
6671 std::vector<DefectInfo> defects = measureDimensions (binary, image);
6772
6873 double timeMs = timer.elapsed ();
74+
75+ // 日志输出测量结果
76+ if (defects.empty ()) {
77+ LOG_INFO (" DimensionDetector::detect - OK, all dimensions within tolerance, time:{:.1f}ms" , timeMs);
78+ } else {
79+ for (const auto & d : defects) {
80+ if (d.attributes .contains (" measureType" ) && d.attributes .contains (" deviation" ) && d.attributes .contains (" actualValue" )) {
81+ std::string type = d.attributes .value (" measureType" ).toDouble () > 0.5 ? " height" : " width" ;
82+ LOG_WARN (" DimensionDetector::detect - NG {}: actual={:.2f}mm, deviation={:.2f}mm (tolerance={:.2f}mm), severity={:.2f}" ,
83+ type, d.attributes .value (" actualValue" ).toDouble (), d.attributes .value (" deviation" ).toDouble (), m_tolerance, d.severity );
84+ }
85+ }
86+ LOG_INFO (" DimensionDetector::detect - Result: {} dimension errors, time:{:.1f}ms" , defects.size (), timeMs);
87+ }
88+
6989 return makeSuccessResult (defects, timeMs);
7090}
7191
0 commit comments