mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 07:06:54 +08:00
Fixed performance bugs related to character position lookup
This commit is contained in:
@@ -195,6 +195,7 @@ namespace alpr
|
|||||||
|
|
||||||
int bestPlateIndex = 0;
|
int bestPlateIndex = 0;
|
||||||
|
|
||||||
|
cv::Mat charTransformMatrix = getCharacterTransformMatrix(&pipeline_data);
|
||||||
for (unsigned int pp = 0; pp < ppResults.size(); pp++)
|
for (unsigned int pp = 0; pp < ppResults.size(); pp++)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -216,7 +217,7 @@ namespace alpr
|
|||||||
character_details.character = ppResults[pp].letter_details[c_idx].letter;
|
character_details.character = ppResults[pp].letter_details[c_idx].letter;
|
||||||
character_details.confidence = ppResults[pp].letter_details[c_idx].totalscore;
|
character_details.confidence = ppResults[pp].letter_details[c_idx].totalscore;
|
||||||
cv::Rect char_rect = pipeline_data.charRegions[ppResults[pp].letter_details[c_idx].charposition];
|
cv::Rect char_rect = pipeline_data.charRegions[ppResults[pp].letter_details[c_idx].charposition];
|
||||||
std::vector<AlprCoordinate> charpoints = getCharacterPoints(char_rect, &pipeline_data );
|
std::vector<AlprCoordinate> charpoints = getCharacterPoints(char_rect, charTransformMatrix );
|
||||||
for (int cpt = 0; cpt < 4; cpt++)
|
for (int cpt = 0; cpt < 4; cpt++)
|
||||||
character_details.corners[cpt] = charpoints[cpt];
|
character_details.corners[cpt] = charpoints[cpt];
|
||||||
aplate.character_details.push_back(character_details);
|
aplate.character_details.push_back(character_details);
|
||||||
@@ -585,22 +586,7 @@ namespace alpr
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<AlprCoordinate> AlprImpl::getCharacterPoints(cv::Rect char_rect, PipelineData* pipeline_data ) {
|
cv::Mat AlprImpl::getCharacterTransformMatrix(PipelineData* pipeline_data ) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Point2f> points;
|
|
||||||
points.push_back(Point2f(char_rect.x, char_rect.y));
|
|
||||||
points.push_back(Point2f(char_rect.x + char_rect.width, char_rect.y));
|
|
||||||
points.push_back(Point2f(char_rect.x + char_rect.width, char_rect.y + char_rect.height));
|
|
||||||
points.push_back(Point2f(char_rect.x, char_rect.y + char_rect.height));
|
|
||||||
|
|
||||||
Mat img = pipeline_data->colorImg;
|
|
||||||
Mat debugImg(img.size(), img.type());
|
|
||||||
img.copyTo(debugImg);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<Point2f> crop_corners;
|
std::vector<Point2f> crop_corners;
|
||||||
crop_corners.push_back(Point2f(0,0));
|
crop_corners.push_back(Point2f(0,0));
|
||||||
crop_corners.push_back(Point2f(pipeline_data->crop_gray.cols,0));
|
crop_corners.push_back(Point2f(pipeline_data->crop_gray.cols,0));
|
||||||
@@ -609,6 +595,19 @@ namespace alpr
|
|||||||
|
|
||||||
// Transform the points from the cropped region (skew corrected license plate region) back to the original image
|
// Transform the points from the cropped region (skew corrected license plate region) back to the original image
|
||||||
cv::Mat transmtx = cv::getPerspectiveTransform(crop_corners, pipeline_data->plate_corners);
|
cv::Mat transmtx = cv::getPerspectiveTransform(crop_corners, pipeline_data->plate_corners);
|
||||||
|
|
||||||
|
return transmtx;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<AlprCoordinate> AlprImpl::getCharacterPoints(cv::Rect char_rect, cv::Mat transmtx ) {
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<Point2f> points;
|
||||||
|
points.push_back(Point2f(char_rect.x, char_rect.y));
|
||||||
|
points.push_back(Point2f(char_rect.x + char_rect.width, char_rect.y));
|
||||||
|
points.push_back(Point2f(char_rect.x + char_rect.width, char_rect.y + char_rect.height));
|
||||||
|
points.push_back(Point2f(char_rect.x, char_rect.y + char_rect.height));
|
||||||
|
|
||||||
cv::perspectiveTransform(points, points, transmtx);
|
cv::perspectiveTransform(points, points, transmtx);
|
||||||
|
|
||||||
// If using prewarp, remap the points to the original image
|
// If using prewarp, remap the points to the original image
|
||||||
|
@@ -107,7 +107,8 @@ namespace alpr
|
|||||||
bool detectRegion;
|
bool detectRegion;
|
||||||
std::string defaultRegion;
|
std::string defaultRegion;
|
||||||
|
|
||||||
std::vector<AlprCoordinate> getCharacterPoints(cv::Rect char_rect, PipelineData* pipeline_data);
|
cv::Mat getCharacterTransformMatrix(PipelineData* pipeline_data );
|
||||||
|
std::vector<AlprCoordinate> getCharacterPoints(cv::Rect char_rect, cv::Mat transmtx);
|
||||||
std::vector<cv::Rect> convertRects(std::vector<AlprRegionOfInterest> regionsOfInterest);
|
std::vector<cv::Rect> convertRects(std::vector<AlprRegionOfInterest> regionsOfInterest);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user