no commit message

devA
yuxue 5 years ago
parent b4050b4451
commit a6acd3a426

@ -1,7 +1,7 @@
package com.yuxue.easypr.core; package com.yuxue.easypr.core;
import static org.bytedeco.javacpp.opencv_core.CV_32FC1; import org.bytedeco.javacpp.opencv_core;
import static org.bytedeco.javacpp.opencv_imgproc.resize; import org.bytedeco.javacpp.opencv_imgproc;
import java.util.Vector; import java.util.Vector;
@ -17,23 +17,27 @@ import org.bytedeco.javacpp.opencv_ml.SVM;
* @date 2020-04-26 15:21 * @date 2020-04-26 15:21
*/ */
public class PlateJudge { public class PlateJudge {
private SVM svm = SVM.create();
/**
* EasyPRgetFeatures, imagesvmfeatures
*/
private SVMCallback features = new Features();
public PlateJudge() { /**
loadModel(); *
} */
private String path = "res/model/svm.xml";
public void loadModel() {
loadModel(path);
}
public void loadModel(String s) { public PlateJudge() {
svm.clear(); svm.clear();
svm=SVM.loadSVM(s, "svm"); svm=SVM.loadSVM(path, "svm");
} }
/** /**
* SVM * SVM
*
* @param inMat * @param inMat
* @return * @return
*/ */
@ -42,7 +46,7 @@ public class PlateJudge {
// 通过直方图均衡化后的彩色图进行预测 // 通过直方图均衡化后的彩色图进行预测
Mat p = features.reshape(1, 1); Mat p = features.reshape(1, 1);
p.convertTo(p, CV_32FC1); p.convertTo(p, opencv_core.CV_32FC1);
float ret = svm.predict(features); float ret = svm.predict(features);
return (int) ret; return (int) ret;
@ -50,7 +54,6 @@ public class PlateJudge {
/** /**
* SVM * SVM
*
* @param inVec * @param inVec
* @param resultVec * @param resultVec
* @return * @return
@ -67,9 +70,8 @@ public class PlateJudge {
int h = inMat.rows(); int h = inMat.rows();
Mat tmpDes = inMat.clone(); Mat tmpDes = inMat.clone();
Mat tmpMat = new Mat(inMat, new Rect((int) (w * 0.05), (int) (h * 0.1), (int) (w * 0.9), Mat tmpMat = new Mat(inMat, new Rect((int) (w * 0.05), (int) (h * 0.1), (int) (w * 0.9), (int) (h * 0.8)));
(int) (h * 0.8))); opencv_imgproc.resize(tmpMat, tmpDes, new Size(inMat.size()));
resize(tmpMat, tmpDes, new Size(inMat.size()));
if (plateJudge(tmpDes) == 1) { if (plateJudge(tmpDes) == 1) {
resultVec.add(inMat); resultVec.add(inMat);
@ -79,6 +81,7 @@ public class PlateJudge {
return 0; return 0;
} }
public void setModelPath(String path) { public void setModelPath(String path) {
this.path = path; this.path = path;
} }
@ -86,17 +89,5 @@ public class PlateJudge {
public final String getModelPath() { public final String getModelPath() {
return path; return path;
} }
private SVM svm = SVM.create();
/**
* EasyPRgetFeatures, imagesvmfeatures
*/
private SVMCallback features = new Features();
/**
*
*/
private String path = "res/model/svm.xml";
} }

Loading…
Cancel
Save