From ff6ebffc711866259a7a7496b4fd67c912a222e3 Mon Sep 17 00:00:00 2001 From: Joakim Roubert Date: Thu, 29 Aug 2024 10:57:30 +0200 Subject: [PATCH] Add debug image with marker shown on whole picture (#14) When building & running in debug mode (DEBUG_WRITE=y), sometimes you need to see the marker drawn on the whole picture to get more info on where the crop is done. This patch adds that functionality. Signed-off-by: Joakim Roubert --- manifest.json | 2 +- src/colorarea.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index a33a175..bbcd69c 100644 --- a/manifest.json +++ b/manifest.json @@ -12,7 +12,7 @@ }, "vendorUrl": "https://www.axis.com/", "runMode": "respawn", - "version": "1.0.4" + "version": "1.0.5" }, "configuration": { "settingPage": "settings.html", diff --git a/src/colorarea.cpp b/src/colorarea.cpp index f783e8f..e477fe7 100644 --- a/src/colorarea.cpp +++ b/src/colorarea.cpp @@ -139,6 +139,18 @@ ColorAreaEllipse::ColorAreaEllipse( const uint8_t tolerance) : ColorArea(img, point_center, color, markerwidth, markerheight, tolerance) { +#if defined(DEBUG_WRITE) + // Create a debug image tho show the marker + auto marker_img = img.clone(); + + // Draw the ellipse + Size axes(markerwidth / 2, markerheight / 2); + ellipse(marker_img, point_center, axes, 0, 0, 360, cv::Scalar(0, 0, 0), 3); + ellipse(marker_img, point_center, axes, 0, 0, 360, cv::Scalar(255, 255, 255), 1); + + DBG_WRITE_IMG("marker_img.jpg", marker_img); +#endif + // Create color mask colorarea_mask = Mat::zeros(Size(croprange_x.size(), croprange_y.size()), CV_8U); ellipse( @@ -165,6 +177,20 @@ ColorAreaRectangle::ColorAreaRectangle( const uint8_t tolerance) : ColorArea(img, point_center, color, markerwidth, markerheight, tolerance) { +#if defined(DEBUG_WRITE) + // Create a debug image tho show the marker + auto marker_img = img.clone(); + + // Draw the rectangle + auto pt1 = point_center - Point(markerwidth / 2, markerheight / 2); + auto pt2 = point_center + Point(markerwidth / 2, markerheight / 2); + rectangle(marker_img, pt1, pt2, Scalar(0, 0, 0), 3); + rectangle(marker_img, pt1, pt2, Scalar(255, 255, 255), 1); + + DBG_WRITE_IMG("marker_img.jpg", marker_img); +#endif + + // Create color mask colorarea_mask = Mat::ones(Size(croprange_x.size(), croprange_y.size()), CV_8U) * 255; DBG_WRITE_IMG("mask_img.jpg", colorarea_mask); LOG_I("%s/%s: Rectancular colorarea created", __FILE__, __FUNCTION__);