From f1620ba4f1f936c545f6b2c0738b1e90da2dd029 Mon Sep 17 00:00:00 2001 From: lidapeng <794757862@qq.com> Date: Wed, 17 Jun 2020 10:27:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A6=86=E7=9B=96=E6=A8=A1=E5=BC=8F=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8rgb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wlld/imageRecognition/Convolution.java | 27 ++++++------------- .../org/wlld/imageRecognition/Operation.java | 24 ++++++++--------- src/test/java/coverTest/CoverTest.java | 6 ++--- 3 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/wlld/imageRecognition/Convolution.java b/src/main/java/org/wlld/imageRecognition/Convolution.java index 87efbfe..210f42f 100644 --- a/src/main/java/org/wlld/imageRecognition/Convolution.java +++ b/src/main/java/org/wlld/imageRecognition/Convolution.java @@ -62,26 +62,17 @@ public class Convolution extends Frequency { return threeChannelMatrixList; } - public List> kAvg(ThreeChannelMatrix threeMatrix, int poolSize, int sqNub + public List> kAvg(ThreeChannelMatrix threeMatrix, int sqNub , int regionSize) throws Exception { RGBSort rgbSort = new RGBSort(); List> features = new ArrayList<>(); - Matrix matrixR = threeMatrix.getMatrixR(); - Matrix matrixG = threeMatrix.getMatrixG(); - Matrix matrixB = threeMatrix.getMatrixB(); - matrixR = late(matrixR, poolSize); - matrixG = late(matrixG, poolSize); - matrixB = late(matrixB, poolSize); - threeMatrix.setMatrixR(matrixR); - threeMatrix.setMatrixG(matrixG); - threeMatrix.setMatrixB(matrixB); List threeChannelMatrixList = regionThreeChannelMatrix(threeMatrix, regionSize); for (ThreeChannelMatrix threeChannelMatrix : threeChannelMatrixList) { List feature = new ArrayList<>(); MeanClustering meanClustering = new MeanClustering(sqNub); - matrixR = threeChannelMatrix.getMatrixR(); - matrixG = threeChannelMatrix.getMatrixG(); - matrixB = threeChannelMatrix.getMatrixB(); + Matrix matrixR = threeChannelMatrix.getMatrixR(); + Matrix matrixG = threeChannelMatrix.getMatrixG(); + Matrix matrixB = threeChannelMatrix.getMatrixB(); int x = matrixR.getX(); int y = matrixR.getY(); for (int i = 0; i < x; i++) { @@ -93,14 +84,12 @@ public class Convolution extends Frequency { meanClustering.start(); List rgbNorms = meanClustering.getMatrices(); Collections.sort(rgbNorms, rgbSort); - double[] dm = new double[sqNub]; for (RGBNorm rgbNorm : rgbNorms) { - feature.add(rgbNorm.getNorm()); - } - for (int t = 0; t < dm.length; t++) { - dm[t] = rgbNorms.get(t).getNorm(); + double[] rgb = rgbNorm.getRgb(); + for (int i = 0; i < rgb.length; i++) { + feature.add(rgb[i]); + } } - //System.out.println(Arrays.toString(dm)); features.add(feature); } return features; diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 13c9495..570b89e 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -226,8 +226,7 @@ public class Operation {//进行计算 return id; } - public void coverStudy(Map matrixMap, int poolSize, int sqNub, int regionSize, - int times) throws Exception { + public void coverStudy(Map matrixMap, int sqNub, int regionSize) throws Exception { if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) { int size = 0; List coverBodies = new ArrayList<>(); @@ -235,32 +234,31 @@ public class Operation {//进行计算 CoverBody coverBody = new CoverBody(); Map tag = new HashMap<>(); tag.put(entry.getKey(), 1.0); - List> lists = convolution.kAvg(entry.getValue(), poolSize, sqNub, regionSize); + List> lists = convolution.kAvg(entry.getValue(), sqNub, regionSize); size = lists.size(); coverBody.setFeature(lists); coverBody.setTag(tag); coverBodies.add(coverBody); } //特征塞入容器完毕 - for (int j = 0; j < times; j++) { - for (int i = 0; i < size; i++) { - for (CoverBody coverBody : coverBodies) { - List list = coverBody.getFeature().get(i); - if (templeConfig.isShowLog()) { - System.out.println("feature:" + list); - } - intoDnnNetwork(1, list, templeConfig.getSensoryNerves(), true, coverBody.getTag(), null); + for (int i = 0; i < size; i++) { + for (CoverBody coverBody : coverBodies) { + List list = coverBody.getFeature().get(i); + if (templeConfig.isShowLog()) { + System.out.println("feature:" + list); } + intoDnnNetwork(1, list, templeConfig.getSensoryNerves(), true, coverBody.getTag(), null); } } + } } - public Map coverPoint(ThreeChannelMatrix matrix, int poolSize, int sqNub, int regionSize) throws Exception { + public Map coverPoint(ThreeChannelMatrix matrix, int sqNub, int regionSize) throws Exception { if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) { Map coverMap = new HashMap<>(); Map typeNub = new HashMap<>(); - List> lists = convolution.kAvg(matrix, poolSize, sqNub, regionSize); + List> lists = convolution.kAvg(matrix, sqNub, regionSize); //特征塞入容器完毕 int size = lists.size(); int all = 0; diff --git a/src/test/java/coverTest/CoverTest.java b/src/test/java/coverTest/CoverTest.java index 15ecdab..46ec8b2 100644 --- a/src/test/java/coverTest/CoverTest.java +++ b/src/test/java/coverTest/CoverTest.java @@ -24,7 +24,7 @@ import java.util.Map; public class CoverTest { public static void main(String[] args) throws Exception { - //cover(); + cover(); } public static void insertModel(String model) throws Exception {//注入模型 @@ -63,7 +63,7 @@ public class CoverTest { String na = "D:\\share\\cai/" + name + i + ".jpg"; //System.out.println("name======================" + na); ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix(na); - Map map1 = operation.coverPoint(threeChannelMatrix, poolSize, sqlNub, regionSize); + Map map1 = operation.coverPoint(threeChannelMatrix, sqlNub, regionSize); int id = 0; double point = 0; for (Map.Entry entry : map1.entrySet()) { @@ -117,7 +117,7 @@ public class CoverTest { matrixMap.put(2, threeChannelMatrix2);//土地 matrixMap.put(3, threeChannelMatrix3);//桔梗覆盖 matrixMap.put(4, threeChannelMatrix4);//土地 - operation.coverStudy(matrixMap, 2, 3, 18, 2); + operation.coverStudy(matrixMap, 2, 18); } ModelParameter modelParameter = templeConfig.getModel(); String model = JSON.toJSONString(modelParameter);