From 838997925a8c4f0518b7bb2d64f9e1e7be994001 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Wed, 18 Mar 2015 18:50:21 -0400 Subject: [PATCH] Fixed a crash caused by detected regions that were beyond the beyond of the image --- src/openalpr/detection/detectormorph.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/openalpr/detection/detectormorph.cpp b/src/openalpr/detection/detectormorph.cpp index f4697cc..d6dd178 100644 --- a/src/openalpr/detection/detectormorph.cpp +++ b/src/openalpr/detection/detectormorph.cpp @@ -116,13 +116,23 @@ namespace alpr { PlateRegion PlateReg; PlateReg.rect = PlateRect.boundingRect(); - + + if (PlateReg.rect.x < 0) + PlateReg.rect.x = 0; + if (PlateReg.rect.y < 0) + PlateReg.rect.y = 0; + if (PlateReg.rect.x + PlateReg.rect.width > frame.cols) + PlateReg.rect.width = frame.cols - PlateReg.rect.x; + if (PlateReg.rect.y + PlateReg.rect.height > frame.rows) + PlateReg.rect.height = frame.rows - PlateReg.rect.y; + + detectedRegions.push_back(PlateReg); } } - + return detectedRegions; }