pull/43/head
thenk008 5 years ago
parent a3a09678ac
commit 50da4ed045

@ -16,7 +16,6 @@ import org.wlld.nerveEntity.SensoryNerve;
import org.wlld.tools.ArithUtil;
import org.wlld.tools.IdCreator;
import javax.swing.text.html.parser.Entity;
import java.util.*;
public class Operation {//进行计算
@ -25,7 +24,7 @@ public class Operation {//进行计算
private MatrixBack matrixBack = new MatrixBack();
private ImageBack imageBack = new ImageBack();
private OutBack outBack;
private double dif;
private int dif;
public Operation(TempleConfig templeConfig) {
this.templeConfig = templeConfig;
@ -64,22 +63,13 @@ public class Operation {//进行计算
List<RegionBody> regionBodies = watershed.rainfall();
if (regionBodies.size() == 1) {
RegionBody regionBody = regionBodies.get(0);
int integrate = templeConfig.getFood().getIntegrate();
int minX = regionBody.getMinX();
int minY = regionBody.getMinY();
int maxX = regionBody.getMaxX();
int maxY = regionBody.getMaxY();
int minX = regionBody.getMinX() + dif;
int minY = regionBody.getMinY() + dif;
int maxX = regionBody.getMaxX() - dif;
int maxY = regionBody.getMaxY() - dif;
int xSize = maxX - minX;
int ySize = maxY - minY;
for (int j = 1; j <= integrate; j++) {
double move = dif * j;
int moveX = (int) (xSize * move);
int moveY = (int) (ySize * move);
int x = minX + moveX;
int y = minY + moveY;
int xLength = xSize - moveX * 2;
int yLength = ySize - moveY * 2;
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, x, y, xLength, yLength);
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
//convolution.filtering(threeChannelMatrix1);//光照过滤
int times = templeConfig.getFood().getTimes();
for (int i = 0; i < times; i++) {
@ -110,17 +100,17 @@ public class Operation {//进行计算
break;
case Classifier.KNN:
Matrix veck = MatrixOperation.listToRowVector(feature);
knnStudy(tag, veck, templeConfig.getKnns()[j]);
knnStudy(tag, veck);
break;
}
}
}
} else {
throw new Exception("Parameter exception region size==" + regionBodies.size());
}
}
private void knnStudy(int tagging, Matrix vector, Knn knn) throws Exception {
private void knnStudy(int tagging, Matrix vector) throws Exception {
Knn knn = templeConfig.getKnn();
knn.insertMatrix(vector, tagging);
}
@ -142,23 +132,13 @@ public class Operation {//进行计算
List<RegionBody> regionList = watershed.rainfall();
for (RegionBody regionBody : regionList) {
MaxPoint maxPoint = new MaxPoint();
int integrate = templeConfig.getFood().getIntegrate();
int minX = regionBody.getMinX();
int minY = regionBody.getMinY();
int maxX = regionBody.getMaxX();
int maxY = regionBody.getMaxY();
int minX = regionBody.getMinX() + dif;
int minY = regionBody.getMinY() + dif;
int maxX = regionBody.getMaxX() - dif;
int maxY = regionBody.getMaxY() - dif;
int xSize = maxX - minX;
int ySize = maxY - minY;
Map<Integer, Integer> map = new HashMap<>();
for (int j = 1; j <= integrate; j++) {
double move = dif * j;
int moveX = (int) (xSize * move);
int moveY = (int) (ySize * move);
int x = minX + moveX;
int y = minY + moveY;
int xLength = xSize - moveX * 2;
int yLength = ySize - moveY * 2;
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, x, y, xLength, yLength);
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
//convolution.filtering(threeChannelMatrix1);//光照过滤
List<Double> feature = convolution.getCenterColor(threeChannelMatrix1, templeConfig.getPoolSize(),
templeConfig.getFeatureNub());
@ -186,26 +166,11 @@ public class Operation {//进行计算
break;
case Classifier.KNN:
Matrix myMatrix2 = MatrixOperation.listToRowVector(feature);
Knn knn = templeConfig.getKnns()[j];
Knn knn = templeConfig.getKnn();
id = knn.getType(myMatrix2);
break;
}
//完成一个结果,统计所有结果
if (map.containsKey(id)) {
map.put(id, map.get(id) + 1);
} else {
map.put(id, 1);
}
}
int key = 0;
int max = 0;
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
int nub = entry.getValue();
if (nub > max) {
key = entry.getKey();
}
}
regionBody.setType(key);
regionBody.setType(id);
//System.out.println("类别" + id);
}
return regionList;

@ -66,16 +66,11 @@ public class TempleConfig {
private int featureNub = 4;//聚类特征数量
private Food food = new Food();
private Knn knn;//KNN分类器
private Knn[] knns;//集成knn分类
private int knnNub = 7;//KNN投票人数
private ThreeChannelMatrix backGround;//背景面板
private double backGroundError;//背景误差偏移量0-255
private Cutting cutting = new Cutting();
public Knn[] getKnns() {
return knns;
}
public Cutting getCutting() {
return cutting;
}
@ -330,12 +325,7 @@ public class TempleConfig {
vectorK = new VectorK(featureNub * 3);
break;
case Classifier.KNN:
int integrate = food.getIntegrate();//集成分类次数
knns = new Knn[integrate];
for (int i = 0; i < integrate; i++) {
knns[i] = new Knn(knnNub);
}
//knn = new Knn(knnNub);
knn = new Knn(knnNub);
break;
}
break;

@ -7,26 +7,17 @@ package org.wlld.param;
* @Description
*/
public class Food {
private double shrink = 0.03;//收缩参数
private int shrink = 60;//收缩参数
private int times = 10;//聚类增强次数
private int integrate = 5;//聚类集成次数
public double getShrink() {
public int getShrink() {
return shrink;
}
public void setShrink(double shrink) {
public void setShrink(int shrink) {
this.shrink = shrink;
}
public int getIntegrate() {
return integrate;
}
public void setIntegrate(int integrate) {
this.integrate = integrate;
}
public int getTimes() {
return times;
}

@ -51,8 +51,8 @@ public class FoodTest {
specifications.setMaxHeight(750);
specificationsList.add(specifications);
Operation operation = new Operation(templeConfig);
for (int i = 1; i <= 1; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai\\g/g2.jpg");
for (int i = 1; i <= 28; i++) {
ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("D:\\share\\cai\\g/g" + i + ".jpg");
List<RegionBody> regionBody = operation.colorLook(threeChannelMatrix1, specificationsList);
for (int j = 0; j < regionBody.size(); j++) {
RegionBody regionBody1 = regionBody.get(j);
@ -80,7 +80,7 @@ public class FoodTest {
//聚类
templeConfig.setFeatureNub(3);//聚类特征数量
//菜品识别实体类
//food.setShrink(50);//缩紧像素
food.setShrink(60);//缩紧像素
food.setTimes(2);//聚类数据增强
templeConfig.setClassifier(Classifier.KNN);
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);

Loading…
Cancel
Save