add slideChineseWindow to chars_segment.

v1.6alpha
liuruoze 9 years ago
parent 2509bfe296
commit 9acd40213c

@ -2117,3 +2117,28 @@ Recall:72.5576%, Precise:70.7495%, Fscore:71.6422%.
Recall:72.5576%, Precise:70.7495%, Fscore:71.6422%.
0-error:59.4595%, 1-error:72.973%, Chinese-precise:75.6757%
总时间:232秒, 平均执行时间:4.64秒
2016-06-30 16:24:58
总图片数:50, Plates count:52, 未识出图片:10, 定位率:80.7692%
Recall:72.5823%, Precise:70.7733%, Fscore:71.6664%.
0-error:58.3333%, 1-error:72.2222%, Chinese-precise:75%
总时间:229秒, 平均执行时间:4.58秒
2016-06-30 17:18:44
总图片数:50, Plates count:52, 未识出图片:10, 定位率:80.7692%
Recall:72.5576%, Precise:70.7495%, Fscore:71.6422%.
0-error:56.7568%, 1-error:70.2703%, Chinese-precise:70.2703%
总时间:233秒, 平均执行时间:4.66秒
2016-06-30 17:25:39
总图片数:50, Plates count:52, 未识出图片:10, 定位率:80.7692%
Recall:72.5576%, Precise:70.7495%, Fscore:71.6422%.
0-error:56.7568%, 1-error:70.2703%, Chinese-precise:70.2703%
总时间:234秒, 平均执行时间:4.68秒
2016-06-30 17:30:14
总图片数:50, Plates count:52, 未识出图片:10, 定位率:80.7692%
Recall:72.5576%, Precise:70.7495%, Fscore:71.6422%.
0-error:56.7568%, 1-error:70.2703%, Chinese-precise:75.6757%
总时间:251秒, 平均执行时间:5.02秒
2016-06-30 17:41:53
总图片数:50, Plates count:52, 未识出图片:10, 定位率:80.7692%
Recall:72.5576%, Precise:70.7495%, Fscore:71.6422%.
0-error:62.1622%, 1-error:72.973%, Chinese-precise:72.973%
总时间:240秒, 平均执行时间:4.8秒

@ -3,6 +3,7 @@
#include <opencv2/opencv.hpp>
#include "easypr/core/plate.hpp"
#include "easypr/core/character.hpp"
using namespace cv;
@ -63,6 +64,10 @@ bool verifyCharSizes(Rect r);
bool verifyPlateSize(Rect mr);
bool verifyRotatedPlateSizes(RotatedRect mr, bool showDebug = false);
//! 非极大值抑制
void NMStoCharacter(std::vector<CCharacter> &inVec, double overlap);
// draw rotatedRectangle
void rotatedRectangle(InputOutputArray img, RotatedRect rect,
const Scalar& color, int thickness = 1,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 KiB

After

Width:  |  Height:  |  Size: 68 KiB

@ -21,7 +21,7 @@
<image>
<imageName>´¨A113YP</imageName>
<taggedRectangles>
<taggedRectangle x="346" y="207" width="138" height="33" rotation="0" locateType="2">À¶ÅÆ:¶õA113YP</taggedRectangle>
<taggedRectangle x="346" y="207" width="138" height="33" rotation="0" locateType="2">À¶ÅÆ:Ô¥A113YP</taggedRectangle>
</taggedRectangles>
</image>
<image>
@ -45,7 +45,7 @@
<image>
<imageName>´¨AE8H60</imageName>
<taggedRectangles>
<taggedRectangle x="412" y="335" width="123" height="40" rotation="-2" locateType="2">À¶ÅÆ:´¨AE8H6</taggedRectangle>
<taggedRectangle x="412" y="335" width="123" height="40" rotation="-2" locateType="2">À¶ÅÆ:ÇàAE8H6</taggedRectangle>
</taggedRectangles>
</image>
<image>
@ -99,7 +99,7 @@
<image>
<imageName>´¨AUU093</imageName>
<taggedRectangles>
<taggedRectangle x="406" y="200" width="121" height="32" rotation="1" locateType="2">À¶ÅÆ:ÇàAUU093</taggedRectangle>
<taggedRectangle x="406" y="200" width="121" height="32" rotation="1" locateType="2">À¶ÅÆ:´¨AUU093</taggedRectangle>
</taggedRectangles>
</image>
<image>
@ -133,7 +133,7 @@
<image>
<imageName>»¦B683J8</imageName>
<taggedRectangles>
<taggedRectangle x="365" y="226" width="129" height="37" rotation="5" locateType="2">À¶ÅÆ:¶õR683J8</taggedRectangle>
<taggedRectangle x="365" y="226" width="129" height="37" rotation="5" locateType="2">À¶ÅÆ:¹óR683J8</taggedRectangle>
</taggedRectangles>
</image>
<image>
@ -187,7 +187,7 @@
<imageName>ÔÁA2HQ34</imageName>
<taggedRectangles>
<taggedRectangle x="1443" y="804" width="241" height="58" rotation="-1" locateType="2">À¶ÅÆ:ÔÁA2HQ34</taggedRectangle>
<taggedRectangle x="1699" y="894" width="243" height="49" rotation="0" locateType="2">À¶ÅÆ:»¦38CZC</taggedRectangle>
<taggedRectangle x="1699" y="894" width="243" height="49" rotation="0" locateType="2">À¶ÅÆ:ÁÉ38CZC</taggedRectangle>
</taggedRectangles>
</image>
<image>
@ -289,7 +289,7 @@
<image>
<imageName>Ô¥U00000</imageName>
<taggedRectangles>
<taggedRectangle x="888" y="650" width="112" height="28" rotation="0" locateType="2">À¶ÅÆ:Ô¥1DQPQU</taggedRectangle>
<taggedRectangle x="888" y="650" width="112" height="28" rotation="0" locateType="2">À¶ÅÆ:¶õ1DQPQU</taggedRectangle>
<taggedRectangle x="1278" y="84" width="297" height="51" rotation="15" locateType="2">»ÆÅÆ:Óå1QXT11</taggedRectangle>
<taggedRectangle x="211" y="28" width="125" height="28" rotation="0" locateType="2">À¶ÅÆ:ÁÉ0T507</taggedRectangle>
<taggedRectangle x="208" y="104" width="94" height="28" rotation="0" locateType="2">À¶ÅÆ</taggedRectangle>

@ -134,6 +134,102 @@ void CCharsSegment::judgeChinese(Mat in, Mat& out, Color plateType) {
}
bool slideChineseWindow(Mat& image, Rect mr, Mat& newRoi, Color plateType, float slideLengthRatio) {
std::vector<CCharacter> charCandidateVec;
Rect maxrect = mr;
Point tlPoint = mr.tl();
bool isChinese = true;
int slideLength = int(slideLengthRatio * maxrect.width);
int slideStep = 1;
int fromX = 0;
fromX = tlPoint.x;
for (int slideX = -slideLength; slideX < slideLength; slideX += slideStep) {
float x_slide = 0;
x_slide = float(fromX + slideX);
float y_slide = (float)tlPoint.y;
Point2f p_slide(x_slide, y_slide);
//cv::circle(image, p_slide, 2, Scalar(255), 1);
int chineseWidth = int(maxrect.width);
int chineseHeight = int(maxrect.height);
Rect rect(Point2f(x_slide, y_slide), Size(chineseWidth, chineseHeight));
if (rect.tl().x < 0 || rect.tl().y < 0 || rect.br().x >= image.cols || rect.br().y >= image.rows)
continue;
Mat auxRoi = image(rect);
Mat roiOstu, roiAdap;
if (1) {
if (BLUE == plateType) {
threshold(auxRoi, roiOstu, 0, 255, CV_THRESH_BINARY + CV_THRESH_OTSU);
}
else if (YELLOW == plateType) {
threshold(auxRoi, roiOstu, 0, 255, CV_THRESH_BINARY_INV + CV_THRESH_OTSU);
}
else if (WHITE == plateType) {
threshold(auxRoi, roiOstu, 0, 255, CV_THRESH_BINARY_INV + CV_THRESH_OTSU);
}
else {
threshold(auxRoi, roiOstu, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
}
roiOstu = preprocessChar(roiOstu, kChineseSize);
}
if (1) {
if (BLUE == plateType) {
adaptiveThreshold(auxRoi, roiAdap, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 3, 0);
}
else if (YELLOW == plateType) {
adaptiveThreshold(auxRoi, roiAdap, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 3, 0);
}
else if (WHITE == plateType) {
adaptiveThreshold(auxRoi, roiAdap, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 3, 0);
}
else {
adaptiveThreshold(auxRoi, roiAdap, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 3, 0);
}
roiAdap = preprocessChar(roiAdap, kChineseSize);
}
CCharacter charCandidateOstu;
charCandidateOstu.setCharacterPos(rect);
charCandidateOstu.setCharacterMat(roiOstu);
charCandidateOstu.setIsChinese(isChinese);
charCandidateVec.push_back(charCandidateOstu);
CCharacter charCandidateAdap;
charCandidateAdap.setCharacterPos(rect);
charCandidateAdap.setCharacterMat(roiAdap);
charCandidateAdap.setIsChinese(isChinese);
charCandidateVec.push_back(charCandidateAdap);
}
CharsIdentify::instance()->classifyChinese(charCandidateVec);
double overlapThresh = 0.1;
NMStoCharacter(charCandidateVec, overlapThresh);
if (charCandidateVec.size() >= 1) {
std::sort(charCandidateVec.begin(), charCandidateVec.end(),
[](const CCharacter& r1, const CCharacter& r2) {
return r1.getCharacterScore() > r2.getCharacterScore();
});
newRoi = charCandidateVec.at(0).getCharacterMat();
return true;
}
return false;
}
//! 字符分割与排序
int CCharsSegment::charsSegment(Mat input, vector<Mat>& resultVec, Color color) {
@ -275,7 +371,7 @@ int CCharsSegment::charsSegment(Mat input, vector<Mat>& resultVec, Color color)
if (newSortedRect.size() == 0) return 0x05;
// 开始截取每个字符
bool useSlideWindow = true;
for (size_t i = 0; i < newSortedRect.size(); i++) {
Rect mr = newSortedRect[i];
@ -287,22 +383,20 @@ int CCharsSegment::charsSegment(Mat input, vector<Mat>& resultVec, Color color)
Mat newRoi;
if (i == 0) {
judgeChinese(auxRoi, newRoi, plateType);
if (useSlideWindow) {
float slideLengthRatio = 0.1f;
if (!slideChineseWindow(input_grey, mr, newRoi, plateType, slideLengthRatio))
judgeChinese(auxRoi, newRoi, plateType);
}
else
judgeChinese(auxRoi, newRoi, plateType);
}
else {
if (BLUE == plateType) {
//newRoi = auxRoi.clone();
//spatial_ostu(newRoi, 5, 5, plateType);
if (i != 0) {
threshold(auxRoi, newRoi, 0, 255, CV_THRESH_BINARY + CV_THRESH_OTSU);
}
else {
adaptiveThreshold(auxRoi, newRoi, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 3, 0);
}
if (BLUE == plateType) {
threshold(auxRoi, newRoi, 0, 255, CV_THRESH_BINARY + CV_THRESH_OTSU);
}
else if (YELLOW == plateType) {
threshold(auxRoi, newRoi, 0, 255, CV_THRESH_BINARY_INV + CV_THRESH_OTSU);
}
else if (WHITE == plateType) {
threshold(auxRoi, newRoi, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY_INV);
@ -317,9 +411,14 @@ int CCharsSegment::charsSegment(Mat input, vector<Mat>& resultVec, Color color)
if (0) {
if (i == 0) {
imshow("chinese", newRoi);
imshow("input_grey", input_grey);
waitKey(0);
destroyWindow("input_grey");
}
if (i == 0) {
imshow("newRoi", newRoi);
waitKey(0);
destroyWindow("chinese");
destroyWindow("newRoi");
}
}

Loading…
Cancel
Save