From 68ec0022f926688c7bc8b8b5b0e1d1da1eeab8e3 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Sun, 27 Mar 2016 13:46:49 -0400 Subject: [PATCH] Fixed region_is_masked function to correctly respond if region is masked --- src/openalpr/detection/detectormask.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/openalpr/detection/detectormask.cpp b/src/openalpr/detection/detectormask.cpp index d293574..6bd1768 100644 --- a/src/openalpr/detection/detectormask.cpp +++ b/src/openalpr/detection/detectormask.cpp @@ -111,14 +111,23 @@ namespace alpr // Checks if the provided region is partially covered by the mask // If so, it is disqualified bool DetectorMask::region_is_masked(cv::Rect region) { - int MIN_WHITENESS = 253; + int MIN_WHITENESS = 248; // If the mean pixel value over the crop is very white (e.g., > 253 out of 255) // then this is in the white area of the mask and we'll use it - Mat mask_crop = mask(region); + + // Make sure the region doesn't extend beyond the bounds of our image + expandRect(region, 0, 0, resized_mask.cols, resized_mask.rows); + Mat mask_crop = resized_mask(region); double mean_value = mean(mask_crop)[0]; - return mean_value >= MIN_WHITENESS; + if (config->debugDetector) + { + cout << "region_is_masked: Mean whiteness: " << mean_value << endl; + } + return mean_value < MIN_WHITENESS; + } + } Mat DetectorMask::apply_mask(Mat image) {