diff --git a/src/openalpr/alpr.cpp b/src/openalpr/alpr.cpp index a2e4d66..c42b101 100644 --- a/src/openalpr/alpr.cpp +++ b/src/openalpr/alpr.cpp @@ -95,6 +95,10 @@ namespace alpr impl->setPrewarp(prewarp_config); } + void Alpr::setMask(unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight) + { + impl->setMask(pixelData, bytesPerPixel, imgWidth, imgHeight); + } void Alpr::setDetectRegion(bool detectRegion) { diff --git a/src/openalpr/alpr.h b/src/openalpr/alpr.h index c34f369..ac6fd43 100644 --- a/src/openalpr/alpr.h +++ b/src/openalpr/alpr.h @@ -142,6 +142,8 @@ namespace alpr // Update the prewarp setting without reloading the library void setPrewarp(std::string prewarp_config); + // Update the detection mask without reloading the library + void setMask(unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight); void setDetectRegion(bool detectRegion); void setTopN(int topN); diff --git a/src/openalpr/alpr_impl.cpp b/src/openalpr/alpr_impl.cpp index 22286de..e930b6c 100644 --- a/src/openalpr/alpr_impl.cpp +++ b/src/openalpr/alpr_impl.cpp @@ -680,6 +680,25 @@ namespace alpr else prewarp->initialize(prewarp_config); } + + void AlprImpl::setMask(unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight) { + + try + { + int arraySize = imgWidth * imgHeight * bytesPerPixel; + cv::Mat imgData = cv::Mat(arraySize, 1, CV_8U, pixelData); + cv::Mat mask = imgData.reshape(bytesPerPixel, imgHeight); + + typedef std::map::iterator it_type; + for (it_type iterator = recognizers.begin(); iterator != recognizers.end(); iterator++) + iterator->second.plateDetector->setMask(mask); + } + catch (cv::Exception& e) + { + std::cerr << "Caught (and ignoring) error in setMask: " << e.msg << std::endl; + } + } + void AlprImpl::setDetectRegion(bool detectRegion) diff --git a/src/openalpr/alpr_impl.h b/src/openalpr/alpr_impl.h index 2aa0da0..0cfd85a 100644 --- a/src/openalpr/alpr_impl.h +++ b/src/openalpr/alpr_impl.h @@ -92,6 +92,7 @@ namespace alpr void setCountry(std::string country); void setPrewarp(std::string prewarp_config); + void setMask(unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight); void setDetectRegion(bool detectRegion); void setTopN(int topn);