Added try/catch to image loading. Resolves issue #196

This commit is contained in:
Matt Hill
2015-10-17 08:56:18 -04:00
parent 06cc808560
commit 756234beb6

View File

@@ -409,13 +409,23 @@ namespace alpr
}
AlprResults AlprImpl::recognize( std::vector<char> imageBytes)
{
try
{
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
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)
{
try
{
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
@@ -424,10 +434,19 @@ namespace alpr
AlprFullDetails fullDetails = recognizeFullDetails(img, rois);
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)
{
try
{
int arraySize = imgWidth * imgHeight * bytesPerPixel;
cv::Mat imgData = cv::Mat(arraySize, 1, CV_8U, pixelData);
cv::Mat img = imgData.reshape(bytesPerPixel, imgHeight);
@@ -441,6 +460,13 @@ namespace alpr
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)
{