|
|
@ -4,56 +4,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "../include/prep.h"
|
|
|
|
#include "../include/prep.h"
|
|
|
|
#include "../include/features.h"
|
|
|
|
#include "../include/features.h"
|
|
|
|
|
|
|
|
#include "../include/core_func.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*! \namespace easypr
|
|
|
|
/*! \namespace easypr
|
|
|
|
Namespace where all the C++ EasyPR functionality resides
|
|
|
|
Namespace where all the C++ EasyPR functionality resides
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
namespace easypr {
|
|
|
|
namespace easypr {
|
|
|
|
|
|
|
|
|
|
|
|
//! 直方图均衡
|
|
|
|
//! 获取垂直和水平的直方图图值
|
|
|
|
Mat histeq(Mat in)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Mat out(in.size(), in.type());
|
|
|
|
|
|
|
|
if(in.channels()==3)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Mat hsv;
|
|
|
|
|
|
|
|
vector<Mat> hsvSplit;
|
|
|
|
|
|
|
|
cvtColor(in, hsv, CV_BGR2HSV);
|
|
|
|
|
|
|
|
split(hsv, hsvSplit);
|
|
|
|
|
|
|
|
equalizeHist(hsvSplit[2], hsvSplit[2]);
|
|
|
|
|
|
|
|
merge(hsvSplit, hsv);
|
|
|
|
|
|
|
|
cvtColor(hsv, out, CV_HSV2BGR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(in.channels()==1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
equalizeHist(in, out);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// !获取垂直和水平方向直方图
|
|
|
|
|
|
|
|
Mat ProjectedHistogram(Mat img, int t)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int sz=(t)?img.rows:img.cols;
|
|
|
|
|
|
|
|
Mat mhist=Mat::zeros(1,sz,CV_32F);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int j=0; j<sz; j++){
|
|
|
|
|
|
|
|
Mat data=(t)?img.row(j):img.col(j);
|
|
|
|
|
|
|
|
mhist.at<float>(j)=countNonZero(data); //统计这一行或一列中,非零元素的个数,并保存到mhist中
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Normalize histogram
|
|
|
|
|
|
|
|
double min, max;
|
|
|
|
|
|
|
|
minMaxLoc(mhist, &min, &max);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(max>0)
|
|
|
|
|
|
|
|
mhist.convertTo(mhist,-1 , 1.0f/max, 0);//用mhist直方图中的最大值,归一化直方图
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return mhist;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! 获得车牌的特征数
|
|
|
|
|
|
|
|
Mat getTheFeatures(Mat in)
|
|
|
|
Mat getTheFeatures(Mat in)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const int VERTICAL = 0;
|
|
|
|
const int VERTICAL = 0;
|
|
|
@ -84,20 +42,23 @@ Mat getTheFeatures(Mat in)
|
|
|
|
return out;
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
// !本函数是生成直方图均衡特征的回调函数
|
|
|
|
//! 本函数是生成直方图均衡特征的回调函数
|
|
|
|
void getHisteqFeatures(const Mat& image, Mat& features)
|
|
|
|
void getHisteqFeatures(const Mat& image, Mat& features)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
features = histeq(image);
|
|
|
|
features = histeq(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
// !本函数是获取垂直和水平的直方图图值
|
|
|
|
//! 本函数是获取垂直和水平的直方图图值
|
|
|
|
void getHistogramFeatures(const Mat& image, Mat& features)
|
|
|
|
void getHistogramFeatures(const Mat& image, Mat& features)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Mat grayImage;
|
|
|
|
Mat grayImage;
|
|
|
|
cvtColor(image, grayImage, CV_RGB2GRAY);
|
|
|
|
cvtColor(image, grayImage, CV_RGB2GRAY);
|
|
|
|
|
|
|
|
|
|
|
|
//grayImage = histeq(grayImage);
|
|
|
|
//grayImage = histeq(grayImage);
|
|
|
|
|
|
|
|
|
|
|
|
Mat img_threshold;
|
|
|
|
Mat img_threshold;
|
|
|
|
threshold(grayImage, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
|
|
|
|
threshold(grayImage, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
|
|
|
|
features = getTheFeatures(img_threshold);
|
|
|
|
features = getTheFeatures(img_threshold);
|
|
|
@ -105,8 +66,7 @@ void getHistogramFeatures(const Mat& image, Mat& features)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
// !本函数是获取SITF特征子
|
|
|
|
//! 本函数是获取SITF特征子
|
|
|
|
// !
|
|
|
|
|
|
|
|
void getSIFTFeatures(const Mat& image, Mat& features)
|
|
|
|
void getSIFTFeatures(const Mat& image, Mat& features)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//待完善
|
|
|
|
//待完善
|
|
|
@ -114,10 +74,17 @@ void getSIFTFeatures(const Mat& image, Mat& features)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
// !本函数是获取HOG特征子
|
|
|
|
//! 本函数是获取HOG特征子
|
|
|
|
void getHOGFeatures(const Mat& image, Mat& features)
|
|
|
|
void getHOGFeatures(const Mat& image, Mat& features)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//待完善
|
|
|
|
//待完善
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//! EasyPR的getFeatures回调函数
|
|
|
|
|
|
|
|
//! 本函数是获取HSV空间量化的直方图特征子
|
|
|
|
|
|
|
|
void getHSVHistFeatures(const Mat& image, Mat& features)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} /* \namespace easypr */
|
|
|
|
} /* \namespace easypr */
|