From 32119aa497cb2c0677a16878437d8dd674e46091 Mon Sep 17 00:00:00 2001 From: thenk008 <794757862@qq.com> Date: Fri, 5 Jun 2020 09:29:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=87=E5=89=B2=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=BC=82=E5=B8=B8=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/wlld/imageRecognition/Operation.java | 84 ++++++++++--------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index a1b5b8e..fc87c5d 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -61,47 +61,51 @@ public class Operation {//进行计算 public void colorStudy(ThreeChannelMatrix threeChannelMatrix, int tag, List specificationsList) throws Exception { Watershed watershed = new Watershed(threeChannelMatrix.getMatrixRGB(), specificationsList, templeConfig); List regionBodies = watershed.rainfall(); - RegionBody regionBody = regionBodies.get(0); - int minX = regionBody.getMinX() + dif; - int minY = regionBody.getMinY() + dif; - int maxX = regionBody.getMaxX() - dif; - int maxY = regionBody.getMaxY() - dif; - int xSize = maxX - minX; - int ySize = maxY - minY; - ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); - //convolution.filtering(threeChannelMatrix1);//光照过滤 - int times = templeConfig.getFood().getTimes(); - for (int i = 0; i < times; i++) { - List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(), - templeConfig.getFeatureNub()); - if (templeConfig.isShowLog()) { - System.out.println(tag + ":" + feature); - } - //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() * 3) { - intoDnnNetwork(1, feature, templeConfig.getSensoryNerves(), true, map, null); - } else { - throw new Exception("nerves number is not equal featureNub"); - } - break; - case Classifier.LVQ: - Matrix vector = MatrixOperation.listToRowVector(feature); - lvqStudy(tag, vector); - break; - case Classifier.VAvg: - Matrix vec = MatrixOperation.listToRowVector(feature); - avgStudy(tag, vec); - break; - case Classifier.KNN: - Matrix veck = MatrixOperation.listToRowVector(feature); - knnStudy(tag, veck); - break; + if (regionBodies.size() == 1) { + RegionBody regionBody = regionBodies.get(0); + int minX = regionBody.getMinX() + dif; + int minY = regionBody.getMinY() + dif; + int maxX = regionBody.getMaxX() - dif; + int maxY = regionBody.getMaxY() - dif; + int xSize = maxX - minX; + int ySize = maxY - minY; + ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); + //convolution.filtering(threeChannelMatrix1);//光照过滤 + int times = templeConfig.getFood().getTimes(); + for (int i = 0; i < times; i++) { + List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(), + templeConfig.getFeatureNub()); + if (templeConfig.isShowLog()) { + System.out.println(tag + ":" + feature); + } + //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() * 3) { + intoDnnNetwork(1, feature, templeConfig.getSensoryNerves(), true, map, null); + } else { + throw new Exception("nerves number is not equal featureNub"); + } + break; + case Classifier.LVQ: + Matrix vector = MatrixOperation.listToRowVector(feature); + lvqStudy(tag, vector); + break; + case Classifier.VAvg: + Matrix vec = MatrixOperation.listToRowVector(feature); + avgStudy(tag, vec); + break; + case Classifier.KNN: + Matrix veck = MatrixOperation.listToRowVector(feature); + knnStudy(tag, veck); + break; + } } + } else { + throw new Exception("Parameter exception"); } }