From 9aed49c620fda6913bd2a7fa2703e5be572b2e48 Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Thu, 21 May 2020 11:38:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E6=B0=B4=E5=B2=AD?= =?UTF-8?q?=E5=88=87=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/wlld/imageRecognition/Operation.java | 6 +-- .../wlld/imageRecognition/TempleConfig.java | 4 +- .../org/wlld/imageRecognition/border/LVQ.java | 21 +--------- src/test/java/coverTest/FoodTest.java | 38 +++++++------------ 4 files changed, 19 insertions(+), 50 deletions(-) diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 643d58e..37e22ca 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -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 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 { diff --git a/src/main/java/org/wlld/imageRecognition/TempleConfig.java b/src/main/java/org/wlld/imageRecognition/TempleConfig.java index 5f43461..217bdfc 100644 --- a/src/main/java/org/wlld/imageRecognition/TempleConfig.java +++ b/src/main/java/org/wlld/imageRecognition/TempleConfig.java @@ -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; diff --git a/src/main/java/org/wlld/imageRecognition/border/LVQ.java b/src/main/java/org/wlld/imageRecognition/border/LVQ.java index 5bf6106..ded7311 100644 --- a/src/main/java/org/wlld/imageRecognition/border/LVQ.java +++ b/src/main/java/org/wlld/imageRecognition/border/LVQ.java @@ -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; diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index abe74d3..03cdc98 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -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 = 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 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 feature = convolution.getCenterColor(threeChannelMatrix, 2, 4); + // List feature = convolution.getCenterColor(threeChannelMatrix, 2, 4); } public static void food() throws Exception {