Improve: more readable PlateColor.

1.3
Micooz 10 years ago
parent 41269d0010
commit eb1f565074

@ -90,7 +90,7 @@ Mat CCharsSegment::histeq(Mat in)
//getPlateType //getPlateType
//判断车牌的类型1为蓝牌2为黄牌0为未知默认蓝牌 //判断车牌的类型1为蓝牌2为黄牌0为未知默认蓝牌
//通过像素中蓝色所占比例的多少来判断大于0.3为蓝牌,否则为黄牌 //通过像素中蓝色所占比例的多少来判断大于0.3为蓝牌,否则为黄牌
int CCharsSegment::getPlateType(Mat input) PlateColor CCharsSegment::getPlateType(Mat input)
{ {
Mat img; Mat img;
input.copyTo(img); input.copyTo(img);
@ -121,11 +121,11 @@ int CCharsSegment::getPlateType(Mat input)
double percentWhite = countWhite/nums; double percentWhite = countWhite/nums;
if (percentBlue - m_BluePercent > 0 && percentWhite - m_WhitePercent > 0) if (percentBlue - m_BluePercent > 0 && percentWhite - m_WhitePercent > 0)
return 1; return PlateColor::Blue;
else else
return 2; return PlateColor::Yellow;
return 0; return PlateColor::Unknown;
} }
//clearLiuDing //clearLiuDing
@ -162,12 +162,12 @@ int CCharsSegment::charsSegment(Mat input, vector<Mat>& resultVec)
{ return -3; } { return -3; }
//判断车牌颜色以此确认threshold方法 //判断车牌颜色以此确认threshold方法
int plateType = getPlateType(input); PlateColor plateType = getPlateType(input);
cvtColor(input, input, CV_RGB2GRAY); cvtColor(input, input, CV_RGB2GRAY);
//Threshold input image //Threshold input image
Mat img_threshold; Mat img_threshold;
if (1 == plateType) if (PlateColor::Blue == plateType)
threshold(input, img_threshold, 10, 255, CV_THRESH_OTSU+CV_THRESH_BINARY); threshold(input, img_threshold, 10, 255, CV_THRESH_OTSU+CV_THRESH_BINARY);
else else
threshold(input, img_threshold, 10, 255, CV_THRESH_OTSU+CV_THRESH_BINARY_INV); threshold(input, img_threshold, 10, 255, CV_THRESH_OTSU+CV_THRESH_BINARY_INV);

@ -45,9 +45,9 @@ public:
{ {
string color = "未知"; string color = "未知";
int result = m_charsSegment->getPlateType(input); int result = m_charsSegment->getPlateType(input);
if (1 == result) if (PlateColor::Blue == result)
color = "蓝牌"; color = "蓝牌";
if (2 == result) if (PlateColor::Yellow == result)
color = "黄牌"; color = "黄牌";
return color; return color;
} }

@ -19,6 +19,12 @@
*/ */
namespace easypr { namespace easypr {
enum PlateColor {
Blue,
Yellow,
Unknown
};
class CCharsSegment class CCharsSegment
{ {
public: public:
@ -43,7 +49,7 @@ public:
Mat histeq(Mat in); Mat histeq(Mat in);
//! 获得车牌颜色 //! 获得车牌颜色
int getPlateType(Mat input); PlateColor getPlateType(Mat input);
//! 去除影响字符识别的柳钉 //! 去除影响字符识别的柳钉
void clearLiuDing(Mat &img); void clearLiuDing(Mat &img);

Loading…
Cancel
Save