mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-07 01:42:49 +08:00
Added try/catch to image loading. Resolves issue #196
This commit is contained in:
@@ -410,36 +410,62 @@ namespace alpr
|
|||||||
|
|
||||||
AlprResults AlprImpl::recognize( std::vector<char> imageBytes)
|
AlprResults AlprImpl::recognize( std::vector<char> imageBytes)
|
||||||
{
|
{
|
||||||
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
|
try
|
||||||
|
{
|
||||||
return this->recognize(img);
|
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)
|
AlprResults AlprImpl::recognize(std::vector<char> imageBytes, std::vector<AlprRegionOfInterest> regionsOfInterest)
|
||||||
{
|
{
|
||||||
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
|
try
|
||||||
|
{
|
||||||
|
cv::Mat img = cv::imdecode(cv::Mat(imageBytes), 1);
|
||||||
|
|
||||||
std::vector<cv::Rect> rois = convertRects(regionsOfInterest);
|
std::vector<cv::Rect> rois = convertRects(regionsOfInterest);
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
||||||
int arraySize = imgWidth * imgHeight * bytesPerPixel;
|
try
|
||||||
cv::Mat imgData = cv::Mat(arraySize, 1, CV_8U, pixelData);
|
|
||||||
cv::Mat img = imgData.reshape(bytesPerPixel, imgHeight);
|
|
||||||
|
|
||||||
if (regionsOfInterest.size() == 0)
|
|
||||||
{
|
{
|
||||||
AlprRegionOfInterest fullFrame(0,0, img.cols, img.rows);
|
int arraySize = imgWidth * imgHeight * bytesPerPixel;
|
||||||
|
cv::Mat imgData = cv::Mat(arraySize, 1, CV_8U, pixelData);
|
||||||
|
cv::Mat img = imgData.reshape(bytesPerPixel, imgHeight);
|
||||||
|
|
||||||
regionsOfInterest.push_back(fullFrame);
|
if (regionsOfInterest.size() == 0)
|
||||||
|
{
|
||||||
|
AlprRegionOfInterest fullFrame(0,0, img.cols, img.rows);
|
||||||
|
|
||||||
|
regionsOfInterest.push_back(fullFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->recognize(img, this->convertRects(regionsOfInterest));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AlprResults AlprImpl::recognize(cv::Mat img)
|
AlprResults AlprImpl::recognize(cv::Mat img)
|
||||||
|
Reference in New Issue
Block a user