增加回归特征

pull/50/head
lidapeng 5 years ago
parent e1de269883
commit 0a84ad77f5

@ -7,6 +7,7 @@ import org.wlld.imageRecognition.border.Border;
import org.wlld.imageRecognition.border.Frame;
import org.wlld.imageRecognition.border.FrameBody;
import org.wlld.imageRecognition.modelEntity.RegressionBody;
import org.wlld.imageRecognition.segmentation.RgbRegression;
import org.wlld.tools.ArithUtil;
import org.wlld.tools.Frequency;
@ -186,7 +187,9 @@ public class Convolution extends Frequency {
Collections.sort(rgbNorms, rgbSort);
List<Double> features = new ArrayList<>();
for (int i = 0; i < sqNub; i++) {
double[] rgb = rgbNorms.get(i).getRgb();
//double[] rgb = rgbNorms.get(i).getRgb();
RgbRegression rgbRegression = rgbNorms.get(i).getRgbRegression();
double[] rgb = new double[]{rgbRegression.getWr(), rgbRegression.getWg(), rgbRegression.getB()};
for (int j = 0; j < 3; j++) {
features.add(rgb[j]);
}

@ -1,5 +1,7 @@
package org.wlld.imageRecognition;
import org.wlld.imageRecognition.segmentation.RgbRegression;
import java.util.*;
//K均值聚类
@ -8,6 +10,7 @@ public class MeanClustering {
private int length;//向量长度(模型需要返回)
private int speciesQuantity;//种类数量(模型需要返回)
private List<RGBNorm> matrices = new ArrayList<>();//均值K模型(模型需要返回)
private int size = 10000;
public List<RGBNorm> getMatrices() {
return matrices;
@ -69,6 +72,23 @@ public class MeanClustering {
}
}
private void startRegression() throws Exception {//开始聚类回归
Random random = new Random();
for (RGBNorm rgbNorm : matrices) {
RgbRegression rgbRegression = new RgbRegression(size);
List<double[]> list = rgbNorm.getRgbs();
for (int i = 0; i < size; i++) {
double[] rgb = list.get(random.nextInt(list.size()));
rgb[0] = rgb[0] / 255;
rgb[1] = rgb[1] / 255;
rgb[2] = rgb[2] / 255;
rgbRegression.insertRGB(rgb);
}
rgbRegression.regression();
rgbNorm.setRgbRegression(rgbRegression);
}
}
public void start() throws Exception {//开始聚类
if (matrixList.size() > 1) {
Random random = new Random();
@ -81,16 +101,16 @@ public class MeanClustering {
}
//进行两者的比较
boolean isNext;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 30; i++) {
averageMatrix();
isNext = isNext();
if (isNext) {
if (isNext && i < 29) {
clear();
} else {
break;
}
}
startRegression();//开始进行回归
} else {
throw new Exception("matrixList number less than 2");
}

@ -73,12 +73,12 @@ public class Operation {//进行计算
for (int i = 0; i < size; i++) {
int xr = random.nextInt(x);
int yr = random.nextInt(y);
double[] rgb = new double[]{matrixR.getNumber(xr, yr), matrixG.getNumber(xr, yr),
matrixB.getNumber(xr, yr)};
double[] rgb = new double[]{matrixR.getNumber(xr, yr) / 255, matrixG.getNumber(xr, yr) / 255,
matrixB.getNumber(xr, yr) / 255};
rgbRegression.insertRGB(rgb);
}
rgbRegression.regression();
// double[] rgb = new double[]{164, 189, 193};
// double[] rgb = new double[]{164 / 255, 189 / 255, 193 / 255};
// double dis = rgbRegression.getDisError(rgb);
// System.out.println("dis==" + dis);
templeConfig.getFood().getTrayBody().add(rgbRegression);

@ -1,13 +1,27 @@
package org.wlld.imageRecognition;
import org.wlld.imageRecognition.segmentation.RgbRegression;
import org.wlld.tools.ArithUtil;
import java.util.ArrayList;
import java.util.List;
public class RGBNorm {
private double[] rgbAll = new double[3];
private double norm;
private int nub;
private double[] rgb = new double[3];
private double[] rgbUp;
private List<double[]> rgbs = new ArrayList<>();
private RgbRegression rgbRegression;
public RgbRegression getRgbRegression() {
return rgbRegression;
}
public void setRgbRegression(RgbRegression rgbRegression) {
this.rgbRegression = rgbRegression;
}
RGBNorm(double[] rgb) {
this.rgbUp = rgb;
@ -17,12 +31,17 @@ public class RGBNorm {
rgbUp = rgb;
}
public List<double[]> getRgbs() {
return rgbs;
}
public void clear() {
rgbAll = new double[3];
nub = 0;
for (int i = 0; i < rgb.length; i++) {
rgbUp[i] = rgb[i];
}
rgbs.clear();
//System.out.println("clear==" + Arrays.toString(rgbUp));
}
@ -57,6 +76,7 @@ public class RGBNorm {
for (int i = 0; i < rgb.length; i++) {
rgbAll[i] = rgbAll[i] + rgb[i];
}
rgbs.add(rgb);
nub++;
}

@ -54,7 +54,7 @@ public class RgbRegression {
wg = ws.getNumber(1, 0);
b = ws.getNumber(2, 0);
isRegression = true;
System.out.println("wr==" + wr + ",wg==" + wg + ",b==" + b);
// System.out.println("wr==" + wr + ",wg==" + wg + ",b==" + b);
} else {
throw new Exception("regression matrix size is zero");
}

@ -73,11 +73,11 @@ public class Watershed {
private boolean isTray(int x, int y) throws Exception {
boolean isTray = false;
double[] rgb = new double[]{matrixR.getNumber(x, y), matrixG.getNumber(x, y),
matrixB.getNumber(x, y)};
double[] rgb = new double[]{matrixR.getNumber(x, y) / 255, matrixG.getNumber(x, y) / 255,
matrixB.getNumber(x, y) / 255};
for (RgbRegression rgbRegression : trayBody) {
double dist = rgbRegression.getDisError(rgb);
if (dist < 10) {
if (dist < 0) {
isTray = true;
break;
}

@ -17,7 +17,7 @@ public class Food {
private double rowMark = 0.12;//行痕迹过滤
private double columnMark = 0.25;//列痕迹过滤
private List<RgbRegression> trayBody = new ArrayList<>();//托盘实体参数
private int regressionNub = 70;//回归数据量
private int regressionNub = 10000;//回归次数
public int getRegressionNub() {
return regressionNub;

@ -53,14 +53,14 @@ public class FoodTest {
Picture picture = new Picture();
List<Specifications> specificationsList = new ArrayList<>();
Specifications specifications = new Specifications();
specifications.setMinWidth(400);
specifications.setMinHeight(400);
specifications.setMinWidth(300);
specifications.setMinHeight(300);
specifications.setMaxWidth(950);
specifications.setMaxHeight(950);
specificationsList.add(specifications);
Operation operation = new Operation(templeConfig);
for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/c" + i + ".jpg");
for (int i = 1; i <= 28; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Desktop/foodModel/test1/g" + i + ".jpg");
List<RegionBody> regionBody = operation.colorLook(threeChannelMatrix1, specificationsList);
for (int j = 0; j < regionBody.size(); j++) {
RegionBody regionBody1 = regionBody.get(j);
@ -89,7 +89,7 @@ public class FoodTest {
//聚类
templeConfig.setFeatureNub(3);//聚类特征数量
//菜品识别实体类
food.setShrink(5);//缩紧像素
food.setShrink(20);//缩紧像素
food.setTimes(2);//聚类数据增强
food.setRowMark(0.1);//0.12
food.setColumnMark(0.1);//0.25
@ -114,14 +114,24 @@ public class FoodTest {
specificationsList.add(specifications);
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/d.jpg");
operation.setTray(threeChannelMatrix);
for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Desktop/test/e1.jpg");
for (int i = 1; i <= 10; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Desktop/foodModel/a/a" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("/Users/lidapeng/Desktop/foodModel/b/b" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix3 = picture.getThreeMatrix("/Users/lidapeng/Desktop/foodModel/c/c" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix4 = picture.getThreeMatrix("/Users/lidapeng/Desktop/foodModel/d/d" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix5 = picture.getThreeMatrix("/Users/lidapeng/Desktop/foodModel/e/e" + i + ".jpg");
ThreeChannelMatrix threeChannelMatrix6 = picture.getThreeMatrix("/Users/lidapeng/Desktop/foodModel/f/f" + i + ".jpg");
operation.colorStudy(threeChannelMatrix1, 1, specificationsList);
System.out.println("=======================================");
operation.colorStudy(threeChannelMatrix2, 2, specificationsList);
operation.colorStudy(threeChannelMatrix3, 3, specificationsList);
operation.colorStudy(threeChannelMatrix4, 4, specificationsList);
operation.colorStudy(threeChannelMatrix5, 5, specificationsList);
operation.colorStudy(threeChannelMatrix6, 6, specificationsList);
System.out.println("=======================================" + i);
}
// minX==301,minY==430,maxX==854,maxY==920
// minX==497,minY==1090,maxX==994,maxY==1520
//test2(templeConfig);
test2(templeConfig);
}
public static void study() throws Exception {

Loading…
Cancel
Save