添加多种类干食切图

pull/59/head
lidapeng 4 years ago
parent 48f7934573
commit 7e1a01e650

@ -136,7 +136,9 @@ public class Convolution extends Frequency {
if (isFood) {//干食学习 if (isFood) {//干食学习
food.setFoodType(insertFoodTypes(food.getFoodType(), tag)); food.setFoodType(insertFoodTypes(food.getFoodType(), tag));
meanMap = food.getFoodMeanMap(); meanMap = food.getFoodMeanMap();
foods.put(tag, xn * yn * food.getFoodFilterTh()); double size = xn * yn * food.getFoodFilterTh();
meanClustering.setRegionSize(size);
foods.put(tag, size);
} else {//非干食学习 } else {//非干食学习
meanMap = food.getNotFoodMeanMap(); meanMap = food.getNotFoodMeanMap();
} }

@ -18,16 +18,13 @@ import java.util.Map;
*/ */
public class CutFood { public class CutFood {
private TempleConfig templeConfig; private TempleConfig templeConfig;
private Map<Integer, GMClustering> meanMap = new HashMap<>();//干食混高模型 private Map<Integer, GMClustering> meanMap;//干食混高模型
private Matrix regionMap; private Matrix regionMap;
private double foodFilterTh; private double foodFilterTh;
public CutFood(TempleConfig templeConfig) { public CutFood(TempleConfig templeConfig, Map<Integer, GMClustering> meanMap) {
this.templeConfig = templeConfig; this.templeConfig = templeConfig;
foodFilterTh = templeConfig.getFood().getFoodFilterTh(); foodFilterTh = templeConfig.getFood().getFoodFilterTh();
}
public void setMeanMap(Map<Integer, GMClustering> meanMap) {
this.meanMap = meanMap; this.meanMap = meanMap;
} }

@ -167,7 +167,7 @@ public class Operation {//进行计算
} }
} }
} }
CutFood cutFood = food.getCutFood(); CutFood cutFood = new CutFood(templeConfig, food.getFoodMeanMap());
if (isFood) {//一次判定就属于干食,则无需进行二次判定 if (isFood) {//一次判定就属于干食,则无需进行二次判定
regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, null)); regionBody.setTypeNub(cutFood.getTypeNub(threeChannelMatrix1, null));
} else {//一次判定属于非干食,则进行二次判定 } else {//一次判定属于非干食,则进行二次判定

@ -1,20 +1,16 @@
package org.wlld.imageRecognition; package org.wlld.imageRecognition;
import com.sun.tools.javac.comp.Enter;
import org.wlld.MatrixTools.Matrix; import org.wlld.MatrixTools.Matrix;
import org.wlld.MatrixTools.MatrixOperation; import org.wlld.MatrixTools.MatrixOperation;
import org.wlld.config.Classifier; import org.wlld.config.Classifier;
import org.wlld.config.Kernel;
import org.wlld.config.RZ; import org.wlld.config.RZ;
import org.wlld.config.StudyPattern; import org.wlld.config.StudyPattern;
import org.wlld.function.ReLu; import org.wlld.function.ReLu;
import org.wlld.function.Sigmod;
import org.wlld.function.Tanh; import org.wlld.function.Tanh;
import org.wlld.i.ActiveFunction; import org.wlld.i.ActiveFunction;
import org.wlld.imageRecognition.border.*; import org.wlld.imageRecognition.border.*;
import org.wlld.imageRecognition.modelEntity.*; import org.wlld.imageRecognition.modelEntity.*;
import org.wlld.imageRecognition.segmentation.DimensionMappingStudy; import org.wlld.imageRecognition.segmentation.DimensionMappingStudy;
import org.wlld.imageRecognition.segmentation.RgbRegression;
import org.wlld.nerveCenter.NerveManager; import org.wlld.nerveCenter.NerveManager;
import org.wlld.nerveCenter.Normalization; import org.wlld.nerveCenter.Normalization;
import org.wlld.nerveEntity.BodyList; import org.wlld.nerveEntity.BodyList;
@ -705,6 +701,7 @@ public class TempleConfig {
GMClustering gmClustering = new GMClustering(featureNub); GMClustering gmClustering = new GMClustering(featureNub);
gmClustering.insertParameter(matrix); gmClustering.insertParameter(matrix);
if (set.contains(key)) {//干食 if (set.contains(key)) {//干食
gmClustering.setRegionSize(foods.get(key));
food.getFoodMeanMap().put(key, gmClustering); food.getFoodMeanMap().put(key, gmClustering);
} else { } else {
food.getNotFoodMeanMap().put(key, gmClustering); food.getNotFoodMeanMap().put(key, gmClustering);
@ -714,9 +711,6 @@ public class TempleConfig {
DimensionMappingStudy dimensionAll = new DimensionMappingStudy(this); DimensionMappingStudy dimensionAll = new DimensionMappingStudy(this);
dimensionAll.start();//生成映射层并将已经保存的knn特征进行映射 dimensionAll.start();//生成映射层并将已经保存的knn特征进行映射
food.setDimensionMappingStudy(dimensionAll); food.setDimensionMappingStudy(dimensionAll);
CutFood cutFood = new CutFood(this);
cutFood.setMeanMap(food.getFoodMeanMap());
food.setCutFood(cutFood);
} }
break; break;
} }

@ -29,15 +29,6 @@ public class Food {
private Map<Integer, GMClustering> foodMeanMap = new HashMap<>();//干食类别混高模型 需激活注入 private Map<Integer, GMClustering> foodMeanMap = new HashMap<>();//干食类别混高模型 需激活注入
private Map<Integer, GMClustering> notFoodMeanMap = new HashMap<>();//干食类别混高模型 需激活注入 private Map<Integer, GMClustering> notFoodMeanMap = new HashMap<>();//干食类别混高模型 需激活注入
private DimensionMappingStudy dimensionMappingStudy;//需激活注入 private DimensionMappingStudy dimensionMappingStudy;//需激活注入
private CutFood cutFood;//需激活时注入
public CutFood getCutFood() {
return cutFood;
}
public void setCutFood(CutFood cutFood) {
this.cutFood = cutFood;
}
public DimensionMappingStudy getDimensionMappingStudy() { public DimensionMappingStudy getDimensionMappingStudy() {
return dimensionMappingStudy; return dimensionMappingStudy;

@ -59,35 +59,6 @@ public class FoodTest {
operation.setTray(threeChannelMatrix); 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<Specifications> 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 { public static void test() throws Exception {
Picture picture = new Picture(); Picture picture = new Picture();
@ -100,41 +71,16 @@ public class FoodTest {
specifications.setMaxHeight(600); specifications.setMaxHeight(600);
specificationsList.add(specifications); specificationsList.add(specifications);
TempleConfig templeConfig = operation.getTempleConfig(); 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 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); operation.setTray(threeChannelMatrixB);
//学习背景 String a = "/Users/lidapeng/Desktop/myDocument/man.jpeg";
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";
//训练馒头
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(a); ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix(a);
//训练鸡蛋 Watershed watershed = new Watershed(threeChannelMatrix1, specificationsList, templeConfig);
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix(c); List<RegionBody> regionList = watershed.rainfall();
study(threeChannelMatrix1, templeConfig, specificationsList, cutFood, 2); System.out.println("==");
study(threeChannelMatrix2, templeConfig, specificationsList, cutFood, 3);
//
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix(g);
look(threeChannelMatrix3, templeConfig, specificationsList, cutFood);
} }
private static void look(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, List<Specifications> specifications, private static void look(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, List<Specifications> specifications,
@ -155,34 +101,6 @@ public class FoodTest {
} }
} }
private static void study(ThreeChannelMatrix threeChannelMatrix, TempleConfig templeConfig, List<Specifications> specifications,
CutFood cutFood, int type) throws Exception {
Convolution convolution = new Convolution();
Watershed watershed = new Watershed(threeChannelMatrix, specifications, templeConfig);
List<RegionBody> 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 { public static void study() throws Exception {
TempleConfig templeConfig = new TempleConfig(); TempleConfig templeConfig = new TempleConfig();

@ -83,7 +83,6 @@ public class ForestTest {
//聚类 //聚类
templeConfig.setFeatureNub(3);//聚类特征数量 templeConfig.setFeatureNub(3);//聚类特征数量
//菜品识别实体类 //菜品识别实体类
food.setShrink(5);//缩紧像素
food.setRowMark(0.15);//0.12 food.setRowMark(0.15);//0.12
food.setColumnMark(0.15);//0.25 food.setColumnMark(0.15);//0.25
food.setRegressionNub(20000); food.setRegressionNub(20000);

Loading…
Cancel
Save