From 134db4b9cf75b7779b73421a09cdac289e4c2cac Mon Sep 17 00:00:00 2001 From: lidapeng <794757862@qq.com> Date: Mon, 3 Aug 2020 21:47:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=BF=E6=80=A7=E5=9B=9E?= =?UTF-8?q?=E5=BD=92=E5=8F=AF=E8=B0=83=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wlld/imageRecognition/Convolution.java | 8 +++---- .../wlld/imageRecognition/MeanClustering.java | 3 ++- .../org/wlld/imageRecognition/Operation.java | 8 +++---- .../segmentation/Watershed.java | 22 ++++++++++--------- src/main/java/org/wlld/param/Food.java | 9 ++++++++ 5 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/main/java/org/wlld/imageRecognition/Convolution.java b/src/main/java/org/wlld/imageRecognition/Convolution.java index b6c6eda..3a9ed5c 100644 --- a/src/main/java/org/wlld/imageRecognition/Convolution.java +++ b/src/main/java/org/wlld/imageRecognition/Convolution.java @@ -64,13 +64,13 @@ public class Convolution extends Frequency { } public List> kAvg(ThreeChannelMatrix threeMatrix, int sqNub - , int regionSize) throws Exception { + , int regionSize, TempleConfig templeConfig) throws Exception { RGBSort rgbSort = new RGBSort(); List> features = new ArrayList<>(); List threeChannelMatrixList = regionThreeChannelMatrix(threeMatrix, regionSize); for (ThreeChannelMatrix threeChannelMatrix : threeChannelMatrixList) { List feature = new ArrayList<>(); - MeanClustering meanClustering = new MeanClustering(sqNub); + MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig); Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixG = threeChannelMatrix.getMatrixG(); Matrix matrixB = threeChannelMatrix.getMatrixB(); @@ -165,7 +165,7 @@ public class Convolution extends Frequency { //System.out.println(matrixBD.getString()); } - public List getCenterColor(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub) throws Exception { + public List getCenterColor(ThreeChannelMatrix threeChannelMatrix, int poolSize, int sqNub, TempleConfig templeConfig) throws Exception { Matrix matrixR = threeChannelMatrix.getMatrixR(); Matrix matrixG = threeChannelMatrix.getMatrixG(); Matrix matrixB = threeChannelMatrix.getMatrixB(); @@ -175,7 +175,7 @@ public class Convolution extends Frequency { RGBSort rgbSort = new RGBSort(); int x = matrixR.getX(); int y = matrixR.getY(); - MeanClustering meanClustering = new MeanClustering(sqNub); + MeanClustering meanClustering = new MeanClustering(sqNub, templeConfig); for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { double[] color = new double[]{matrixR.getNumber(i, j), matrixG.getNumber(i, j), matrixB.getNumber(i, j)}; diff --git a/src/main/java/org/wlld/imageRecognition/MeanClustering.java b/src/main/java/org/wlld/imageRecognition/MeanClustering.java index 9984d83..321a346 100644 --- a/src/main/java/org/wlld/imageRecognition/MeanClustering.java +++ b/src/main/java/org/wlld/imageRecognition/MeanClustering.java @@ -16,8 +16,9 @@ public class MeanClustering { return matrices; } - public MeanClustering(int speciesQuantity) { + public MeanClustering(int speciesQuantity, TempleConfig templeConfig) { this.speciesQuantity = speciesQuantity;//聚类的数量 + size = templeConfig.getFood().getRegressionNub(); } public void setColor(double[] color) throws Exception { diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 233e6c6..98d7210 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -111,7 +111,7 @@ public class Operation {//进行计算 int times = templeConfig.getFood().getTimes(); for (int i = 0; i < times; i++) { List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(), - templeConfig.getFeatureNub()); + templeConfig.getFeatureNub(), templeConfig); if (templeConfig.isShowLog()) { System.out.println(tag + ":" + feature); } @@ -178,7 +178,7 @@ public class Operation {//进行计算 ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); //convolution.filtering(threeChannelMatrix1);//光照过滤 List feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(), - templeConfig.getFeatureNub()); + templeConfig.getFeatureNub(), templeConfig); if (templeConfig.isShowLog()) { System.out.println(feature); } @@ -272,7 +272,7 @@ public class Operation {//进行计算 CoverBody coverBody = new CoverBody(); Map tag = new HashMap<>(); tag.put(entry.getKey(), 1.0); - List> lists = convolution.kAvg(entry.getValue(), sqNub, regionSize); + List> lists = convolution.kAvg(entry.getValue(), sqNub, regionSize, templeConfig); size = lists.size(); coverBody.setFeature(lists); coverBody.setTag(tag); @@ -296,7 +296,7 @@ public class Operation {//进行计算 if (templeConfig.getStudyPattern() == StudyPattern.Cover_Pattern) { Map coverMap = new HashMap<>(); Map typeNub = new HashMap<>(); - List> lists = convolution.kAvg(matrix, sqNub, regionSize); + List> lists = convolution.kAvg(matrix, sqNub, regionSize, templeConfig); //特征塞入容器完毕 int size = lists.size(); int all = 0; diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java index bc0b0fc..32a3fb5 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -38,6 +38,7 @@ public class Watershed { private double columnMark;//列过滤 private List specifications;//过滤候选区参数 private List trayBody;//托盘参数 + private double trayTh; public Watershed(ThreeChannelMatrix matrix, List specifications, TempleConfig templeConfig) throws Exception { if (matrix != null && specifications != null && specifications.size() > 0) { @@ -61,6 +62,7 @@ public class Watershed { xSize = this.matrix.getX() / regionNub; ySize = this.matrix.getY() / regionNub; maxIou = templeConfig.getCutting().getMaxIou(); + trayTh = templeConfig.getFood().getTrayTh(); // System.out.println("xSize===" + xSize + ",ysize===" + ySize); rainfallMap = new Matrix(this.matrix.getX(), this.matrix.getY()); regionMap = new Matrix(regionNub, regionNub); @@ -77,7 +79,7 @@ public class Watershed { matrixB.getNumber(x, y) / 255}; for (RgbRegression rgbRegression : trayBody) { double dist = rgbRegression.getDisError(rgb); - if (dist < 0) { + if (dist < trayTh) { isTray = true; break; } @@ -274,15 +276,15 @@ public class Watershed { regionBodies.add(regionBody); } } - for (RegionBody regionBody : regionBodies) { - int minX = regionBody.getMinX(); - int maxX = regionBody.getMaxX(); - int minY = regionBody.getMinY(); - int maxY = regionBody.getMaxY(); - System.out.println("minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY); - } - //return iou(regionBodies); - return regionBodies; +// for (RegionBody regionBody : regionBodies) { +// int minX = regionBody.getMinX(); +// int maxX = regionBody.getMaxX(); +// int minY = regionBody.getMinY(); +// int maxY = regionBody.getMaxY(); +// System.out.println("minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY); +// } + return iou(regionBodies); + //return regionBodies; } private List iou(List regionBodies) { diff --git a/src/main/java/org/wlld/param/Food.java b/src/main/java/org/wlld/param/Food.java index 1f11a27..d2a4869 100644 --- a/src/main/java/org/wlld/param/Food.java +++ b/src/main/java/org/wlld/param/Food.java @@ -18,6 +18,15 @@ public class Food { private double columnMark = 0.25;//列痕迹过滤 private List trayBody = new ArrayList<>();//托盘实体参数 private int regressionNub = 10000;//回归次数 + private double trayTh = 0.1;//托盘回归阈值 + + public double getTrayTh() { + return trayTh; + } + + public void setTrayTh(double trayTh) { + this.trayTh = trayTh; + } public int getRegressionNub() { return regressionNub;