diff --git a/src/main/java/org/wlld/imageRecognition/Convolution.java b/src/main/java/org/wlld/imageRecognition/Convolution.java index ddced80..d336f8a 100644 --- a/src/main/java/org/wlld/imageRecognition/Convolution.java +++ b/src/main/java/org/wlld/imageRecognition/Convolution.java @@ -136,7 +136,9 @@ public class Convolution extends Frequency { if (isFood) {//干食学习 food.setFoodType(insertFoodTypes(food.getFoodType(), tag)); meanMap = food.getFoodMeanMap(); - foods.put(tag, xn * yn * food.getFoodFilterTh()); + double size = xn * yn * food.getFoodFilterTh(); + meanClustering.setRegionSize(size); + foods.put(tag, size); } else {//非干食学习 meanMap = food.getNotFoodMeanMap(); } diff --git a/src/main/java/org/wlld/imageRecognition/CutFood.java b/src/main/java/org/wlld/imageRecognition/CutFood.java index 3145d2c..5b1e2b5 100644 --- a/src/main/java/org/wlld/imageRecognition/CutFood.java +++ b/src/main/java/org/wlld/imageRecognition/CutFood.java @@ -18,16 +18,13 @@ import java.util.Map; */ public class CutFood { private TempleConfig templeConfig; - private Map meanMap = new HashMap<>();//干食混高模型 + private Map meanMap;//干食混高模型 private Matrix regionMap; private double foodFilterTh; - public CutFood(TempleConfig templeConfig) { + public CutFood(TempleConfig templeConfig, Map meanMap) { this.templeConfig = templeConfig; foodFilterTh = templeConfig.getFood().getFoodFilterTh(); - } - - public void setMeanMap(Map meanMap) { this.meanMap = meanMap; } diff --git a/src/main/java/org/wlld/imageRecognition/Operation.java b/src/main/java/org/wlld/imageRecognition/Operation.java index 8e56247..0d437cf 100644 --- a/src/main/java/org/wlld/imageRecognition/Operation.java +++ b/src/main/java/org/wlld/imageRecognition/Operation.java @@ -167,7 +167,7 @@ public class Operation {//进行计算 } } } - CutFood cutFood = food.getCutFood(); + CutFood cutFood = new CutFood(templeConfig, food.getFoodMeanMap()); if (isFood) {//一次判定就属于干食,则无需进行二次判定 regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, null)); } else {//一次判定属于非干食,则进行二次判定 diff --git a/src/main/java/org/wlld/imageRecognition/TempleConfig.java b/src/main/java/org/wlld/imageRecognition/TempleConfig.java index 9aac6d4..e03e1d3 100644 --- a/src/main/java/org/wlld/imageRecognition/TempleConfig.java +++ b/src/main/java/org/wlld/imageRecognition/TempleConfig.java @@ -1,20 +1,16 @@ package org.wlld.imageRecognition; -import com.sun.tools.javac.comp.Enter; import org.wlld.MatrixTools.Matrix; import org.wlld.MatrixTools.MatrixOperation; import org.wlld.config.Classifier; -import org.wlld.config.Kernel; import org.wlld.config.RZ; import org.wlld.config.StudyPattern; import org.wlld.function.ReLu; -import org.wlld.function.Sigmod; import org.wlld.function.Tanh; import org.wlld.i.ActiveFunction; import org.wlld.imageRecognition.border.*; import org.wlld.imageRecognition.modelEntity.*; import org.wlld.imageRecognition.segmentation.DimensionMappingStudy; -import org.wlld.imageRecognition.segmentation.RgbRegression; import org.wlld.nerveCenter.NerveManager; import org.wlld.nerveCenter.Normalization; import org.wlld.nerveEntity.BodyList; @@ -705,6 +701,7 @@ public class TempleConfig { GMClustering gmClustering = new GMClustering(featureNub); gmClustering.insertParameter(matrix); if (set.contains(key)) {//干食 + gmClustering.setRegionSize(foods.get(key)); food.getFoodMeanMap().put(key, gmClustering); } else { food.getNotFoodMeanMap().put(key, gmClustering); @@ -714,9 +711,6 @@ public class TempleConfig { DimensionMappingStudy dimensionAll = new DimensionMappingStudy(this); dimensionAll.start();//生成映射层,并将已经保存的knn特征进行映射 food.setDimensionMappingStudy(dimensionAll); - CutFood cutFood = new CutFood(this); - cutFood.setMeanMap(food.getFoodMeanMap()); - food.setCutFood(cutFood); } break; } diff --git a/src/main/java/org/wlld/param/Food.java b/src/main/java/org/wlld/param/Food.java index 25a9e4d..d4b31f6 100644 --- a/src/main/java/org/wlld/param/Food.java +++ b/src/main/java/org/wlld/param/Food.java @@ -29,15 +29,6 @@ public class Food { private Map foodMeanMap = new HashMap<>();//干食类别混高模型 需激活注入 private Map notFoodMeanMap = new HashMap<>();//干食类别混高模型 需激活注入 private DimensionMappingStudy dimensionMappingStudy;//需激活注入 - private CutFood cutFood;//需激活时注入 - - public CutFood getCutFood() { - return cutFood; - } - - public void setCutFood(CutFood cutFood) { - this.cutFood = cutFood; - } public DimensionMappingStudy getDimensionMappingStudy() { return dimensionMappingStudy; diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index f75606c..36292cb 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -59,35 +59,6 @@ public class FoodTest { operation.setTray(threeChannelMatrix); } - public static void setting2() throws Exception {//前置设定第二步,设定餐盘 - Picture picture = new Picture(); - Operation operation = getTemple(); - CutFood cutFood = new CutFood(operation.getTempleConfig()); - ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/pan1.jpg"); - cutFood.study(1, threeChannelMatrix); - } - - public static void study1() throws Exception {//进行学习 - List specificationsList = new ArrayList<>(); - Specifications specifications = new Specifications(); - specifications.setMinWidth(60);//150 - specifications.setMinHeight(60);//150 - specifications.setMaxWidth(600); - specifications.setMaxHeight(600); - specificationsList.add(specifications); - Picture picture = new Picture(); - String a = "/Users/lidapeng/Desktop/test/testOne/a.jpg"; - Operation operation = getTemple(); - ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(a); - //进行第一步学习目的是将特征生成混高模型 - operation.colorStudy(threeChannelMatrix1, 2, specificationsList, "url", true); - - - CutFood cutFood = new CutFood(operation.getTempleConfig()); - TempleConfig templeConfig = operation.getTempleConfig(); - study(threeChannelMatrix1, templeConfig, specificationsList, cutFood, 2); - - } public static void test() throws Exception { Picture picture = new Picture(); @@ -100,41 +71,16 @@ public class FoodTest { specifications.setMaxHeight(600); specificationsList.add(specifications); TempleConfig templeConfig = operation.getTempleConfig(); - CutFood cutFood = new CutFood(templeConfig); - //KNerveManger kNerveManger = templeConfig.getFood().getkNerveManger(); ThreeChannelMatrix threeChannelMatrixB = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/d.jpg"); //背景也是盘子 - ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/pan1.jpg"); + ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/pan.jpeg"); //设定背景回归 operation.setTray(threeChannelMatrixB); - //学习背景 - cutFood.study(1, threeChannelMatrix); - //训练数据,单张馒头 - String a = "/Users/lidapeng/Desktop/test/testOne/a.jpg"; - //训练数据,一个鸡蛋 - String c = "/Users/lidapeng/Desktop/test/testOne/c.jpg"; - //测试数据,两个鸡蛋 - String d = "/Users/lidapeng/Desktop/test/testOne/d.jpg"; - //测试数据,两个馒头 - String b = "/Users/lidapeng/Desktop/test/testOne/b.jpg"; - String f = "/Users/lidapeng/Desktop/test/testOne/f.jpeg"; - - //测试数据,一个鸡蛋和一个馒头 - String e = "/Users/lidapeng/Desktop/test/testOne/e.jpg"; - //测试数据,两个鸡蛋 一个馒头 - String g = "/Users/lidapeng/Desktop/test/testOne/f.jpg"; - //测试数据,两个鸡蛋两个馒头 - String h = "/Users/lidapeng/Desktop/test/testOne/g.jpg"; - - //训练馒头 + String a = "/Users/lidapeng/Desktop/myDocument/man.jpeg"; ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(a); - //训练鸡蛋 - ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix(c); - study(threeChannelMatrix1, templeConfig, specificationsList, cutFood, 2); - study(threeChannelMatrix2, templeConfig, specificationsList, cutFood, 3); - // - ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix(g); - look(threeChannelMatrix3, templeConfig, specificationsList, cutFood); + Watershed watershed = new Watershed(threeChannelMatrix1, specificationsList, templeConfig); + List regionList = watershed.rainfall(); + System.out.println("=="); } private static void look(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, List specifications, @@ -155,34 +101,6 @@ public class FoodTest { } } - private static void study(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, List specifications, - CutFood cutFood, int type) throws Exception { - Convolution convolution = new Convolution(); - Watershed watershed = new Watershed(threeChannelMatrix, specifications, templeConfig); - List regionList = watershed.rainfall(); - if (regionList.size() == 1) { - RegionBody regionBody = regionList.get(0); - int minX = regionBody.getMinX(); - int minY = regionBody.getMinY(); - int maxX = regionBody.getMaxX(); - int maxY = regionBody.getMaxY(); - int xSize = maxX - minX; - int ySize = maxY - minY; - System.out.println("正常:minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY); - ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize); - cutFood.study(type, threeChannelMatrix1); - } else { - for (RegionBody regionBody : regionList) { - int minX = regionBody.getMinX(); - int minY = regionBody.getMinY(); - int maxX = regionBody.getMaxX(); - int maxY = regionBody.getMaxY(); - System.out.println("异常:minX==" + minX + ",minY==" + minY + ",maxX==" + maxX + ",maxY==" + maxY); - } - throw new Exception("Parameter exception region size:" + regionList.size()); - } - - } public static void study() throws Exception { TempleConfig templeConfig = new TempleConfig(); diff --git a/src/test/java/coverTest/ForestTest.java b/src/test/java/coverTest/ForestTest.java index 98f63db..1fb3924 100644 --- a/src/test/java/coverTest/ForestTest.java +++ b/src/test/java/coverTest/ForestTest.java @@ -83,7 +83,6 @@ public class ForestTest { //聚类 templeConfig.setFeatureNub(3);//聚类特征数量 //菜品识别实体类 - food.setShrink(5);//缩紧像素 food.setRowMark(0.15);//0.12 food.setColumnMark(0.15);//0.25 food.setRegressionNub(20000);