From 6d9d8201e197b34535fc2652c295bcce08cd1837 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Mon, 29 Jun 2015 23:41:33 -0400 Subject: [PATCH] Fixed classify-chars misc utility bug caused by cropping outside of bounds of image --- src/misc_utilities/classifychars.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/misc_utilities/classifychars.cpp b/src/misc_utilities/classifychars.cpp index d034d31..76c7c5d 100644 --- a/src/misc_utilities/classifychars.cpp +++ b/src/misc_utilities/classifychars.cpp @@ -248,7 +248,13 @@ int main( int argc, const char** argv ) continue; stringstream filename; - Mat cropped = pipeline_data.thresholds[t](pipeline_data.charRegions[c]); + + // Ensure that crop rect does not extend beyond extent of image. + cv::Rect char_region = expandRect(pipeline_data.charRegions[c], 0, 0, + pipeline_data.thresholds[t].cols, + pipeline_data.thresholds[t].rows); + + Mat cropped = pipeline_data.thresholds[t](char_region); filename << outDir << "/" << humanInputs[c] << "-" << t << "-" << files[i]; imwrite(filename.str(), cropped); cout << "Writing char image: " << filename.str() << endl;