Skip to content

Commit

Permalink
the first demo can pass the simple test.
Browse files Browse the repository at this point in the history
  • Loading branch information
1002 authored and 1002 committed May 31, 2015
1 parent ce58f00 commit 0abd21b
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 313 deletions.
1 change: 1 addition & 0 deletions src/org/easypr/core/CharsIdentify.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public final String getModelPath() {
"zh_min" /* 闽 */, "zh_ning" /* 宁 */, "zh_qing" /* 青 */, "zh_qiong" /* 琼 */, "zh_shan" /* 陕 */,
"zh_su" /* 苏 */, "zh_sx" /* 晋 */, "zh_wan" /* 皖 */, "zh_xiang" /* 湘 */, "zh_xin" /* 新 */, "zh_yu" /* 豫 */,
"zh_yu1" /* 渝 */, "zh_yue" /* 粤 */, "zh_yun" /* 云 */, "zh_zang" /* 藏 */, "zh_zhe" /* 浙 */};
@SuppressWarnings("unused")
private final static int numChinese = 31;

private final static int numAll = 65; /* 34+31=65 */
Expand Down
10 changes: 6 additions & 4 deletions src/org/easypr/core/CoreFunc.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ public static float[] projectedHistogram(final Mat img, Direction direction) {
}

/**
* Asign values to feature
* Assign values to feature
* <p>
* ANN的样本特征为水平、垂直直方图和低分辨率图像所组成的矢量
* 样本特征为水平、垂直直方图和低分辨率图像所组成的矢量
*
* @param in
* @param sizeData
* 低分辨率图像size = sizeData*sizeData
* 低分辨率图像size = sizeData*sizeData, 可以为0
* @return
*/
public static Mat features(final Mat in, final int sizeData) {
Expand All @@ -252,7 +252,9 @@ public static Mat features(final Mat in, final int sizeData) {
float[] hhist = projectedHistogram(in, Direction.HORIZONTAL);

Mat lowData = new Mat();
resize(in, lowData, new Size(sizeData, sizeData));
if (sizeData > 0) {
resize(in, lowData, new Size(sizeData, sizeData));
}

int numCols = vhist.length + hhist.length + lowData.cols() * lowData.rows();
Mat out = Mat.zeros(1, numCols, CV_32F).asMat();
Expand Down
157 changes: 64 additions & 93 deletions src/org/easypr/core/Features.java
Original file line number Diff line number Diff line change
@@ -1,121 +1,92 @@
package org.easypr.core;

import org.easypr.util.Convert;

import static org.bytedeco.javacpp.opencv_core.*;
import static org.bytedeco.javacpp.opencv_core.merge;
import static org.bytedeco.javacpp.opencv_core.split;
import static org.bytedeco.javacpp.opencv_imgproc.*;
import static org.easypr.core.CoreFunc.features;

/*
* Created by fanwenjie
* @version 1.1
*/


public class Features implements SVMCallback{

public Mat histeq(Mat in) {
Mat out = new Mat(in.size(), in.type());
if (in.channels() == 3) {
Mat hsv = new Mat();
MatVector hsvSplit = new MatVector();
cvtColor(in, hsv, CV_BGR2HSV);
split(hsv, hsvSplit);
equalizeHist(hsvSplit.get(2), hsvSplit.get(2));
merge(hsvSplit, hsv);
cvtColor(hsv, out, CV_HSV2BGR);
hsv = null;
hsvSplit = null;
System.gc();
} else if (in.channels() == 1) {
equalizeHist(in, out);
}
return out;
}

// !获取垂直和水平方向直方图
public float[][] ProjectedHistogram(Mat img) {

float []nonZeroHor = new float[img.rows()];
float []nonZeroVer = new float[img.cols()];
for(int i=0;i<img.rows();++i)
for(int j=0;j<img.cols();++j)
if(0!=img.ptr(i,j).get()){
++nonZeroHor[i];
++nonZeroVer[j];
}
float [][]out = new float[][]{nonZeroVer,nonZeroHor};
for(int i=0;i<2;++i){
float max = 0;
for(int j=0;j<out[i].length;++j)
if(max<out[i][j])
max = out[i][j];
if(max>0)
for(int j=0;j<out[i].length;++j)
out[i][j]/=max;
}
return out;
}


//! 获得车牌的特征数
public Mat getTheFeatures(Mat in) {

//Histogram features
float [][]hist = ProjectedHistogram(in);
float[] vhist = hist[0];
float[] hhist = hist[1];
import org.bytedeco.javacpp.opencv_core.Mat;
import org.bytedeco.javacpp.opencv_core.MatVector;

//Last 10 is the number of moments components
int numCols = vhist.length + hhist.length;

Mat out = Mat.zeros(1, numCols, CV_32FC1).asMat();

//Asign values to feature,样本特征为水平、垂直直方图
int j = 0;
for (int i = 0; i < vhist.length; i++, ++j) {
out.ptr(j).put(Convert.getBytes(vhist[i]));
}
for (int i = 0; i < hhist.length; i++, ++j) {
out.ptr(j).put(Convert.getBytes(hhist[i]));
}
return out;
}

// ! EasyPR的getFeatures回调函数
// !本函数是生成直方图均衡特征的回调函数
/**
*
* @author Created by fanwenjie
* @author lin.yao
*
*/
public class Features implements SVMCallback {

/*
* (non-Javadoc)
*
* @see org.easypr.core.SVMCallback#getHisteqFeatures(org.bytedeco.javacpp.
* opencv_core.Mat)
*/
@Override
public Mat getHisteqFeatures(final Mat image) {
return histeq(image);
}

// ! EasyPR的getFeatures回调函数
// !本函数是获取垂直和水平的直方图图值
/*
* (non-Javadoc)
*
* @see
* org.easypr.core.SVMCallback#getHistogramFeatures(org.bytedeco.javacpp
* .opencv_core.Mat)
*/
@Override
public Mat getHistogramFeatures(Mat image) {
Mat grayImage = new Mat();
cvtColor(image, grayImage, CV_RGB2GRAY);
//grayImage = histeq(grayImage);

Mat img_threshold = new Mat();
threshold(grayImage, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
return getTheFeatures(img_threshold);
}

return features(img_threshold, 0);
}

// ! EasyPR的getFeatures回调函数
// !本函数是获取SITF特征子
// !
/*
* (non-Javadoc)
*
* @see
* org.easypr.core.SVMCallback#getSIFTFeatures(org.bytedeco.javacpp.opencv_core
* .Mat)
*/
@Override
public Mat getSIFTFeatures(final Mat image) {
//TODO: 待完善
// TODO: 待完善
return null;
}


// ! EasyPR的getFeatures回调函数
// !本函数是获取HOG特征子
/*
* (non-Javadoc)
*
* @see
* org.easypr.core.SVMCallback#getHOGFeatures(org.bytedeco.javacpp.opencv_core
* .Mat)
*/
@Override
public Mat getHOGFeatures(final Mat image) {
//TODO: 待完善
// TODO: 待完善
return null;
}

private Mat histeq(Mat in) {
Mat out = new Mat(in.size(), in.type());
if (in.channels() == 3) {
Mat hsv = new Mat();
MatVector hsvSplit = new MatVector();
cvtColor(in, hsv, CV_BGR2HSV);
split(hsv, hsvSplit);
equalizeHist(hsvSplit.get(2), hsvSplit.get(2));
merge(hsvSplit, hsv);
cvtColor(hsv, out, CV_HSV2BGR);
hsv = null;
hsvSplit = null;
System.gc();
} else if (in.channels() == 1) {
equalizeHist(in, out);
}
return out;
}
}
41 changes: 27 additions & 14 deletions src/org/easypr/core/PlateDetect.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,43 @@
import org.bytedeco.javacpp.opencv_core.Mat;

/**
* @author Created by fanwenjie
* @author lin.yao
*
*/
public class PlateDetect {

/**
* 可能是车牌的图块集合
*
* @param src
* @param resultVec
* @return
* 可能是车牌的图块集合
* @return the error number
* <ul>
* <li>0: plate detected successfully;
* <li>-1: source Mat is empty;
* <li>-2: plate not detected.
* </ul>
*/
public int plateDetect(final Mat src, Vector<Mat> resultVec) {
Vector<Mat> matVec = plateLocate.plateLocate(src);
if (0 == matVec.size())

if (0 == matVec.size()) {
return -1;
int resultJu = plateJudge.plateJudge(matVec, resultVec);
}

if (0 != plateJudge.plateJudge(matVec, resultVec)) {
return -2;
}

if (getPDDebug()) {
int size = (int) resultVec.size();
for (int i = 0; i < size; i++) {
Mat img = resultVec.get(i);
String str = "image/tmp/plate_judge_result_"
+ Integer.valueOf(i).toString() + ".jpg";
String str = "tmp/plate_judge_result_" + Integer.valueOf(i).toString() + ".jpg";
imwrite(str, img);
}
}
if (0 != resultJu)
return -2;

return 0;
}

Expand All @@ -48,17 +56,24 @@ public void setPDLifemode(boolean pdLifemode) {
plateLocate.setLifemode(pdLifemode);
}

// ! 是否开启调试模式
/**
* 是否开启调试模式
*
* @param pdDebug
*/
public void setPDDebug(boolean pdDebug) {
plateLocate.setDebug(pdDebug);
}

// ! 获取调试模式状态
/**
* 获取调试模式状态
*
* @return
*/
public boolean getPDDebug() {
return plateLocate.getDebug();
}

// ! 设置与读取变量
public void setGaussianBlurSize(int gaussianBlurSize) {
plateLocate.setGaussianBlurSize(gaussianBlurSize);
}
Expand Down Expand Up @@ -111,10 +126,8 @@ public void setJudgeAngle(int judgeAngle) {
plateLocate.setJudgeAngle(judgeAngle);
}

// !车牌定位
private PlateLocate plateLocate = new PlateLocate();

// ! 车牌判断
private PlateJudge plateJudge = new PlateJudge();

}
Loading

0 comments on commit 0abd21b

Please sign in to comment.