add centerPoint, fitToLines, searchRect

v1.6alpha
liuruoze 10 years ago
parent e12bdbb488
commit 2b4ea5800e

@ -1589,3 +1589,7 @@
总图片数:200, 未识出图片:7, 定位率:96.5%
平均字符差距:0.689119, 完全匹配数:132, 完全匹配率:68.3938%
总时间:297秒, 平均执行时间:1.485秒
2016-06-16 20:26:00
总图片数:200, 未识出图片:7, 定位率:96.5%
平均字符差距:0.689119, 完全匹配数:132, 完全匹配率:68.3938%
总时间:178秒, 平均执行时间:0.89秒

@ -29,7 +29,7 @@ Mat colorMatch(const Mat& src, Mat& match, const Color r,
const bool adaptive_minsv);
Mat mserMatch(const Mat& src, Mat& match, const Color r,
std::vector<RotatedRect>& plateRect);
std::vector<RotatedRect>& plateRect, std::vector<Rect>& out_charRect);
//! 判断一个车牌的颜色
//! 输入车牌mat与颜色模板

Binary file not shown.

Before

Width:  |  Height:  |  Size: 62 KiB

After

Width:  |  Height:  |  Size: 26 KiB

@ -954,7 +954,7 @@ bool verifyRotatedPlateSizes(RotatedRect mr) {
Mat mserMatch(const Mat &src, Mat &match, const Color r,
std::vector<RotatedRect>& out_plateRect) {
std::vector<RotatedRect>& out_plateRect, std::vector<Rect>& out_charRect) {
std::vector<Mat> channelImages;
std::vector<int> flags;
@ -1051,7 +1051,12 @@ Mat mserMatch(const Mat &src, Mat &match, const Color r,
match(rect) = 255;
cv::rectangle(result, rect, Scalar(255, 0, 0));
Point center(rect.tl().x + rect.width / 2, rect.tl().y + rect.height / 2);
cv::circle(result, center, 3, Scalar(0, 255, 0), 2);
charRects.push_back(rect);
out_charRect.push_back(rect);
//CCharacter character;
//character.setCharacterPos(rect);
//character.setCharacterMat(binary_region);

@ -93,10 +93,14 @@ int CPlateLocate::mserSearch(const Mat &src, const Color r, Mat &out,
const int color_morph_height = 5;
std::vector<RotatedRect> plateRects;
std::vector<Rect> charRects;
std::vector<RotatedRect> contourRects;
std::vector<Rect> mergedRects;
// 进行颜色查找
mserMatch(src, match_grey, r, plateRects);
mserMatch(src, match_grey, r, plateRects, charRects);
if (m_debug) {
utils::imwrite("resources/image/tmp/match_grey.jpg", match_grey);
@ -151,7 +155,7 @@ int CPlateLocate::mserSearch(const Mat &src, const Color r, Mat &out,
calcSafeRect(candRect, src, outputRect);
cv::rectangle(result, outputRect, Scalar(0, 0, 255));
mergedRects.push_back(outputRect);
if (0) {
imshow("outputRect", src(outputRect));
waitKey(0);
@ -159,6 +163,56 @@ int CPlateLocate::mserSearch(const Mat &src, const Color r, Mat &out,
}
}
for (auto mergeRect : mergedRects) {
std::vector<Point> points;
Vec4f line;
int maxarea = 0;
Rect maxrect;
for (auto charRect : charRects) {
Rect interRect = mergeRect & charRect;
if (interRect == charRect) {
Point center(charRect.tl().x + charRect.width / 2, charRect.tl().y + charRect.height / 2);
points.push_back(center);
if (charRect.area() - maxarea > 0.1f) {
maxrect = charRect;
maxarea = charRect.area();
}
}
}
if (points.size() < 5)
continue;
int left = mergeRect.tl().x - maxrect.width / 8 * 9;
left = left > 0 ? left : 0;
int right = mergeRect.br().x + maxrect.width / 8;
right = right + maxrect.width < src_threshold.cols - 1 ? right : src_threshold.cols - (maxrect.width + 1);
fitLine(Mat(points), line, CV_DIST_L2, 0, 0.01, 0.01);
float k = line[1] / line[0];
float step = 100;
cv::line(result, Point2f(line[2] - step, line[3] - k*step), Point2f(line[2] + step, k*step + line[3]), Scalar(255, 255, 255));
Point2f leftPoint((float)left, k * (left - line[2]) + line[3]);
Point2f rightPoint((float)right, k * (right - line[2]) + line[3]);
Rect leftRect(Point2f(leftPoint.x, leftPoint.y - maxrect.height / 2), maxrect.size());
Rect rightRect(Point2f(rightPoint.x, rightPoint.y - maxrect.height / 2), maxrect.size());
cv::rectangle(result, leftRect, Scalar(255, 255, 0));
cv::rectangle(result, rightRect, Scalar(255, 255, 0));
}
for (auto prect : plateRects) {
outRects.push_back(prect);

Loading…
Cancel
Save