|
|
|
@ -118,7 +118,7 @@ int CPlateRecognize::plateRecognizeAsText(Mat src, std::vector<CPlate> &licenseV
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int CPlateRecognize::plateRecognize(Mat src, std::vector<CPlate> &licenseVec, int img_index) {
|
|
|
|
|
int CPlateRecognize::plateRecognize(Mat src, std::vector<CPlate> &plateVecOut, int img_index, Mat& output, const vector<CPlate>& plateVecGT) {
|
|
|
|
|
|
|
|
|
|
std::vector<CPlate> plateVec;
|
|
|
|
|
|
|
|
|
@ -155,12 +155,110 @@ int CPlateRecognize::plateRecognize(Mat src, std::vector<CPlate> &licenseVec, in
|
|
|
|
|
if (resultCR == 0) {
|
|
|
|
|
std::string license = plateColor + ":" + plateIdentify;
|
|
|
|
|
item.setPlateStr(license);
|
|
|
|
|
licenseVec.push_back(item);
|
|
|
|
|
plateVecOut.push_back(item);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
std::string license = plateColor;
|
|
|
|
|
item.setPlateStr(license);
|
|
|
|
|
licenseVec.push_back(item);
|
|
|
|
|
plateVecOut.push_back(item);
|
|
|
|
|
if (0) {
|
|
|
|
|
std::cout << "resultCR:" << resultCR << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (getResultShow()) {
|
|
|
|
|
Mat result;
|
|
|
|
|
src.copyTo(result);
|
|
|
|
|
|
|
|
|
|
for (size_t j = 0; j < num; j++) {
|
|
|
|
|
CPlate item = plateVec[j];
|
|
|
|
|
Mat plateMat = item.getPlateMat();
|
|
|
|
|
|
|
|
|
|
int height = 36;
|
|
|
|
|
int width = 136;
|
|
|
|
|
if (height * index + height < result.rows) {
|
|
|
|
|
Mat imageRoi = result(Rect(0, 0 + height * index, width, height));
|
|
|
|
|
addWeighted(imageRoi, 0, plateMat, 1, 0, imageRoi);
|
|
|
|
|
}
|
|
|
|
|
index++;
|
|
|
|
|
|
|
|
|
|
RotatedRect minRect = item.getPlatePos();
|
|
|
|
|
Point2f rect_points[4];
|
|
|
|
|
minRect.points(rect_points);
|
|
|
|
|
|
|
|
|
|
Scalar lineColor = Scalar(255, 255, 255);
|
|
|
|
|
|
|
|
|
|
if (item.getPlateLocateType() == SOBEL) lineColor = Scalar(255, 0, 0);
|
|
|
|
|
if (item.getPlateLocateType() == COLOR) lineColor = Scalar(0, 255, 0);
|
|
|
|
|
if (item.getPlateLocateType() == CMSER) lineColor = Scalar(0, 0, 255);
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
|
line(result, rect_points[j], rect_points[(j + 1) % 4], lineColor, 2, 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (auto plateG : plateVecGT) {
|
|
|
|
|
RotatedRect minRect = plateG.getPlatePos();
|
|
|
|
|
Point2f rect_points[4];
|
|
|
|
|
minRect.points(rect_points);
|
|
|
|
|
|
|
|
|
|
Scalar lineColor = Scalar(255, 255, 255);
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
|
line(result, rect_points[j], rect_points[(j + 1) % 4], lineColor, 2, 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output = showResult(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resultPD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int CPlateRecognize::plateRecognize(Mat src, std::vector<CPlate> &plateVecOut, int img_index) {
|
|
|
|
|
|
|
|
|
|
std::vector<CPlate> plateVec;
|
|
|
|
|
|
|
|
|
|
int resultPD = plateDetect(src, plateVec, img_index);
|
|
|
|
|
|
|
|
|
|
if (resultPD == 0) {
|
|
|
|
|
size_t num = plateVec.size();
|
|
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
|
|
for (size_t j = 0; j < num; j++) {
|
|
|
|
|
CPlate item = plateVec.at(j);
|
|
|
|
|
Mat plateMat = item.getPlateMat();
|
|
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
|
imshow("plate", plateMat);
|
|
|
|
|
waitKey(0);
|
|
|
|
|
destroyWindow("plate");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color color = item.getPlateColor();
|
|
|
|
|
if (color == UNKNOWN) {
|
|
|
|
|
color = getPlateType(plateMat, true);
|
|
|
|
|
item.setPlateColor(color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string plateColor = getPlateColor(color);
|
|
|
|
|
if (0) {
|
|
|
|
|
std::cout << "plateColor:" << plateColor << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string plateIdentify = "";
|
|
|
|
|
int resultCR = charsRecognise(item, plateIdentify);
|
|
|
|
|
|
|
|
|
|
if (resultCR == 0) {
|
|
|
|
|
std::string license = plateColor + ":" + plateIdentify;
|
|
|
|
|
item.setPlateStr(license);
|
|
|
|
|
plateVecOut.push_back(item);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
std::string license = plateColor;
|
|
|
|
|
item.setPlateStr(license);
|
|
|
|
|
plateVecOut.push_back(item);
|
|
|
|
|
if (0) {
|
|
|
|
|
std::cout << "resultCR:" << resultCR << std::endl;
|
|
|
|
|
}
|
|
|
|
@ -200,6 +298,8 @@ int CPlateRecognize::plateRecognize(Mat src, std::vector<CPlate> &licenseVec, in
|
|
|
|
|
showResult(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return resultPD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -263,8 +363,8 @@ int CPlateRecognize::plateRecognize(Mat src, std::vector<std::string> &licenseVe
|
|
|
|
|
Scalar lineColor = Scalar(255, 255, 255);
|
|
|
|
|
|
|
|
|
|
if (item.getPlateLocateType() == SOBEL) lineColor = Scalar(255, 0, 0);
|
|
|
|
|
|
|
|
|
|
if (item.getPlateLocateType() == COLOR) lineColor = Scalar(0, 255, 0);
|
|
|
|
|
if (item.getPlateLocateType() == CMSER) lineColor = Scalar(0, 0, 255);
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < 4; j++)
|
|
|
|
|
line(result, rect_points[j], rect_points[(j + 1) % 4], lineColor, 2,
|
|
|
|
|