增加最大边框限制参数

pull/32/head
thenk008 5 years ago
parent 7b83664028
commit 35ab9c027c

@ -165,6 +165,22 @@ public class Operation {//进行计算
return regionList;
}
private int getIdByCos(Matrix myVector) throws Exception {//VAG获取分类
Map<Integer, Matrix> matrixK = templeConfig.getVectorK().getMatrixK();
double maxCos = 0;
int id = 0;
for (Map.Entry<Integer, Matrix> entry : matrixK.entrySet()) {
Matrix matrix = entry.getValue();
double cos = MatrixOperation.getNormCos(matrix, myVector);
//System.out.println("距离===" + dist + ",类别==" + entry.getKey()+",核心:"+matrix.getString());
if (cos > maxCos) {
maxCos = cos;
id = entry.getKey();
}
}
return id;
}
private int getIdByVag(Matrix myVector) throws Exception {//VAG获取分类
Map<Integer, Matrix> matrixK = templeConfig.getVectorK().getMatrixK();
double minDist = 0;

@ -1,22 +1,40 @@
package org.wlld.imageRecognition.segmentation;
public class Specifications {
private double width;
private double height;
private double minWidth;
private double minHeight;
private double maxWidth;
private double maxHeight;
public double getWidth() {
return width;
public double getMinWidth() {
return minWidth;
}
public void setWidth(double width) {
this.width = width;
public void setMinWidth(double minWidth) {
this.minWidth = minWidth;
}
public double getHeight() {
return height;
public double getMinHeight() {
return minHeight;
}
public void setHeight(double height) {
this.height = height;
public void setMinHeight(double minHeight) {
this.minHeight = minHeight;
}
public double getMaxWidth() {
return maxWidth;
}
public void setMaxWidth(double maxWidth) {
this.maxWidth = maxWidth;
}
public double getMaxHeight() {
return maxHeight;
}
public void setMaxHeight(double maxHeight) {
this.maxHeight = maxHeight;
}
}

@ -210,7 +210,8 @@ public class Watershed {
for (Specifications specification : specifications) {
int width = maxY - minY;
int height = maxX - minX;
if (width >= specification.getWidth() && height >= specification.getHeight()) {
if (width >= specification.getMinWidth() && height >= specification.getMinHeight()
&& width <= specification.getMaxWidth() && height <= specification.getMaxHeight()) {
isRight = true;
break;
}

@ -18,48 +18,59 @@ public class FoodTest {
public static void main(String[] args) throws Exception {
//test2();
test();
test2();
}
public static void test2(TempleConfig templeConfig) throws Exception {
public static void test2() throws Exception {
//test();
TempleConfig templeConfig = getTemple();
Picture picture = new Picture();
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
specifications.setWidth(400);
specifications.setHeight(400);
specifications.setMinWidth(300);
specifications.setMinHeight(300);
specifications.setMaxWidth(700);
specifications.setMaxHeight(700);
specificationsList.add(specifications);
Operation operation = new Operation(templeConfig);
for (int i = 6; i <= 7; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic\\f/f" + i + ".jpg");
for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai\\g/g" + i + ".jpg");
List<RegionBody> regionBody = operation.colorLook(threeChannelMatrix1, specificationsList);
for (int j = 0; j < regionBody.size(); j++) {
System.out.println(regionBody.get(j).getType());
}
// for (int j = 0; j < regionBody.size(); j++) {
// System.out.println(regionBody.get(j).getType());
// }
System.out.println("=============================" + i);
}
}
public static void test() throws Exception {
public static TempleConfig getTemple() throws Exception {
TempleConfig templeConfig = new TempleConfig();
Picture picture = new Picture();
templeConfig.isShowLog(true);//是否打印日志
templeConfig.setMaxRain(320);//切割阈值
templeConfig.setMaxRain(340);//切割阈值
templeConfig.setFeatureNub(3);
templeConfig.sethTh(0.88);
templeConfig.setPoolSize(2);
//templeConfig.setRegionNub(100);
templeConfig.setRegionNub(200);
templeConfig.setClassifier(Classifier.VAvg);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
return templeConfig;
}
public static void test() throws Exception {
Picture picture = new Picture();
TempleConfig templeConfig = getTemple();
Operation operation = new Operation(templeConfig);
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
specifications.setWidth(400);
specifications.setHeight(400);
specifications.setMinWidth(300);
specifications.setMinHeight(300);
specifications.setMaxWidth(700);
specifications.setMaxHeight(700);
specificationsList.add(specifications);
for (int j = 0; j < 1; j++) {
for (int i = 1; i <= 10; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("E:\\food\\train/a.jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\pic/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\pic/c" + i + ".jpg");
operation.colorStudy(threeChannelMatrix1, 1, specificationsList);
@ -69,7 +80,7 @@ public class FoodTest {
}
}
templeConfig.finishStudy();
test2(templeConfig);
test2();
}
public static void study() throws Exception {

Loading…
Cancel
Save