修改分水岭切图

pull/30/head
thenk008 5 years ago
parent f389cffe26
commit 9aed49c620

@ -72,13 +72,13 @@ public class Operation {//进行计算
if (templeConfig.isShowLog()) {
System.out.println(feature);
}
System.out.println("=====================================");
//System.out.println("=====================================");
int classifier = templeConfig.getClassifier();
switch (classifier) {
case Classifier.DNN:
Map<Integer, Double> map = new HashMap<>();
map.put(tag, 1.0);
if (templeConfig.getSensoryNerves().size() == templeConfig.getFeatureNub()) {
if (templeConfig.getSensoryNerves().size() == templeConfig.getFeatureNub() * 3) {
intoDnnNetwork(1, feature, templeConfig.getSensoryNerves(), true, map, null);
} else {
throw new Exception("nerves number is not equal featureNub");
@ -142,7 +142,7 @@ public class Operation {//进行计算
id = getIdByLVQ(myMatrix);
break;
case Classifier.DNN:
if (templeConfig.getSensoryNerves().size() == templeConfig.getFeatureNub()) {
if (templeConfig.getSensoryNerves().size() == templeConfig.getFeatureNub() * 3) {
intoDnnNetwork(IdCreator.get().nextId(), feature, templeConfig.getSensoryNerves(), false, null, maxPoint);
id = maxPoint.getId();
} else {

@ -45,7 +45,7 @@ public class TempleConfig {
private double th = -1;//标准阈值
private boolean boxReady = false;//边框已经学习完毕
private double iouTh = 0.5;//IOU阈值
private int lvqNub = 100;//lvq循环次数默认30
private int lvqNub = 200;//lvq循环次数默认30
private VectorK vectorK;//特征向量均值类
private boolean isThreeChannel = false;//是否启用三通道
private int classifier = Classifier.VAvg;//默认分类类别使用的是向量均值分类
@ -65,7 +65,7 @@ public class TempleConfig {
private double maxRain = 340;//不降雨RGB阈值
private int featureNub = 4;//聚类特征数量
private Knn knn;//KNN分类器
private int knnNub = 5;//KNN投票人数
private int knnNub = 3;//KNN投票人数
public Knn getKnn() {
return knn;

@ -87,35 +87,16 @@ public class LVQ {
long type = matrixBody.getId();//类别
double distEnd = 0;
int id = 0;
double dis0 = 0;
double dis1 = 0;
double dis2 = 0;
double dis3 = 0;
for (int i = 0; i < typeNub; i++) {
MatrixBody modelBody = model[i];
Matrix modelMatrix = modelBody.getMatrix();
//修正矩阵与原矩阵的范数差
double dist = vectorEqual(modelMatrix, matrix);
switch (i) {
case 0:
dis0 = dist;
break;
case 1:
dis1 = dist;
break;
case 2:
dis2 = dist;
break;
case 3:
dis3 = dist;
break;
}
if (distEnd == 0 || dist < distEnd) {
id = modelBody.getId();
distEnd = dist;
}
}
System.out.println("type==" + type + ",dist0==" + dis0 + ",dist1==" + dis1 + ",dist2==" + dis2 + ",dist3==" + dis3);
MatrixBody modelBody = model[id];
Matrix modelMatrix = modelBody.getMatrix();
boolean isRight = id == type;
@ -156,7 +137,7 @@ public class LVQ {
}
//初始化完成
for (int i = 0; i < lvqNub; i++) {
System.out.println("================================");
//System.out.println("================================");
study();
}
isReady = true;

@ -30,38 +30,28 @@ public class FoodTest {
specifications.setHeight(400);
specificationsList.add(specifications);
Operation operation = new Operation(templeConfig);
for (int i = 1; i <= 10; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\pic/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\pic/c" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\pic/d" + i + ".jpg");
RegionBody regionBody1 = operation.colorLook(threeChannelMatrix1, specificationsList).get(0);
RegionBody regionBody2 = operation.colorLook(threeChannelMatrix2, specificationsList).get(0);
RegionBody regionBody3 = operation.colorLook(threeChannelMatrix3, specificationsList).get(0);
RegionBody regionBody4 = operation.colorLook(threeChannelMatrix4, specificationsList).get(0);
System.out.println("type1==" + regionBody1.getType());
System.out.println("type2==" + regionBody2.getType());
System.out.println("type3==" + regionBody3.getType());
System.out.println("type4==" + regionBody4.getType());
System.out.println("==========================================" + i);
for (int i = 6; i <= 7; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic\\f/f" + i + ".jpg");
List<RegionBody> regionBody = operation.colorLook(threeChannelMatrix1, specificationsList);
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 {
TempleConfig templeConfig = new TempleConfig();
Picture picture = new Picture();
templeConfig.setStudyPoint(0.01);
templeConfig.isShowLog(true);
templeConfig.setMaxRain(320);
templeConfig.setSensoryNerveNub(3);
templeConfig.setSoftMax(true);
templeConfig.setFeatureNub(3);
templeConfig.sethTh(0.88);
templeConfig.setPoolSize(2);
templeConfig.setRzType(RZ.L1);
templeConfig.setlParam(0.015);
templeConfig.setSensoryNerveNub(3);
templeConfig.setStudyPoint(0.01);
templeConfig.setClassifier(Classifier.VAvg);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 4);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
Operation operation = new Operation(templeConfig);
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
@ -73,16 +63,14 @@ public class FoodTest {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\pic/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("D:\\pic/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("D:\\pic/c" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("D:\\pic/d" + i + ".jpg");
operation.colorStudy(threeChannelMatrix1, 1, specificationsList);
operation.colorStudy(threeChannelMatrix2, 2, specificationsList);
operation.colorStudy(threeChannelMatrix3, 3, specificationsList);
operation.colorStudy(threeChannelMatrix4, 4, specificationsList);
System.out.println("=======================================" + i);
}
}
//templeConfig.finishStudy();
//test2(templeConfig);
templeConfig.finishStudy();
test2(templeConfig);
}
public static void study() throws Exception {
@ -100,7 +88,7 @@ public class FoodTest {
Picture picture = new Picture();
Convolution convolution = new Convolution();
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("");
// List<Double> feature = convolution.getCenterColor(threeChannelMatrix, 2, 4);
// List<Double> feature = convolution.getCenterColor(threeChannelMatrix, 2, 4);
}
public static void food() throws Exception {

Loading…
Cancel
Save