mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 10:20:53 +08:00
Added try/catch to image loading. Resolves issue #196
This commit is contained in:
@@ -409,13 +409,23 @@ namespace alpr
|
|||||||
}
|
}
|
||||||
|
|
||||||
AlprResults AlprImpl::recognize( std::vector<char> imageBytes)
|
AlprResults AlprImpl::recognize( std::vector<char> imageBytes)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
|
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
|
||||||
|
|
||||||
return this->recognize(img);
|
return this->recognize(img);
|
||||||
}
|
}
|
||||||
|
catch (cv::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Caught exception in OpenALPR recognize: " << e.msg << std::endl;
|
||||||
|
AlprResults emptyresults;
|
||||||
|
return emptyresults;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AlprResults AlprImpl::recognize(std::vector<char> imageBytes, std::vector<AlprRegionOfInterest> regionsOfInterest)
|
AlprResults AlprImpl::recognize(std::vector<char> imageBytes, std::vector<AlprRegionOfInterest> regionsOfInterest)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
|
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
|
||||||
|
|
||||||
@@ -424,10 +434,19 @@ namespace alpr
|
|||||||
AlprFullDetails fullDetails = recognizeFullDetails(img, rois);
|
AlprFullDetails fullDetails = recognizeFullDetails(img, rois);
|
||||||
return fullDetails.results;
|
return fullDetails.results;
|
||||||
}
|
}
|
||||||
|
catch (cv::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Caught exception in OpenALPR recognize: " << e.msg << std::endl;
|
||||||
|
AlprResults emptyresults;
|
||||||
|
return emptyresults;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AlprResults AlprImpl::recognize( unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight, std::vector<AlprRegionOfInterest> regionsOfInterest)
|
AlprResults AlprImpl::recognize( unsigned char* pixelData, int bytesPerPixel, int imgWidth, int imgHeight, std::vector<AlprRegionOfInterest> regionsOfInterest)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
int arraySize = imgWidth * imgHeight * bytesPerPixel;
|
int arraySize = imgWidth * imgHeight * bytesPerPixel;
|
||||||
cv::Mat imgData = cv::Mat(arraySize, 1, CV_8U, pixelData);
|
cv::Mat imgData = cv::Mat(arraySize, 1, CV_8U, pixelData);
|
||||||
cv::Mat img = imgData.reshape(bytesPerPixel, imgHeight);
|
cv::Mat img = imgData.reshape(bytesPerPixel, imgHeight);
|
||||||
@@ -441,6 +460,13 @@ namespace alpr
|
|||||||
|
|
||||||
return this->recognize(img, this->convertRects(regionsOfInterest));
|
return this->recognize(img, this->convertRects(regionsOfInterest));
|
||||||
}
|
}
|
||||||
|
catch (cv::Exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "Caught exception in OpenALPR recognize: " << e.msg << std::endl;
|
||||||
|
AlprResults emptyresults;
|
||||||
|
return emptyresults;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
AlprResults AlprImpl::recognize(cv::Mat img)
|
AlprResults AlprImpl::recognize(cv::Mat img)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user