|
|
|
@ -1,6 +1,18 @@
|
|
|
|
|
package coverTest;
|
|
|
|
|
|
|
|
|
|
import org.wlld.randomForest.Tree;
|
|
|
|
|
import org.wlld.MatrixTools.Matrix;
|
|
|
|
|
import org.wlld.config.Classifier;
|
|
|
|
|
import org.wlld.config.StudyPattern;
|
|
|
|
|
import org.wlld.imageRecognition.Convolution;
|
|
|
|
|
import org.wlld.imageRecognition.Picture;
|
|
|
|
|
import org.wlld.imageRecognition.TempleConfig;
|
|
|
|
|
import org.wlld.imageRecognition.ThreeChannelMatrix;
|
|
|
|
|
import org.wlld.imageRecognition.segmentation.RegionBody;
|
|
|
|
|
import org.wlld.imageRecognition.segmentation.Specifications;
|
|
|
|
|
import org.wlld.imageRecognition.segmentation.Watershed;
|
|
|
|
|
import org.wlld.nerveEntity.ModelParameter;
|
|
|
|
|
import org.wlld.param.Cutting;
|
|
|
|
|
import org.wlld.param.Food;
|
|
|
|
|
import org.wlld.regressionForest.RegressionForest;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
@ -12,6 +24,8 @@ import java.util.*;
|
|
|
|
|
* @Description
|
|
|
|
|
*/
|
|
|
|
|
public class ForestTest {
|
|
|
|
|
private static Convolution convolution = new Convolution();
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
|
test();
|
|
|
|
|
//int a = (int) (Math.log(4) / Math.log(2));//id22是第几层
|
|
|
|
@ -20,6 +34,66 @@ public class ForestTest {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void testPic() throws Exception {
|
|
|
|
|
Picture picture = new Picture();
|
|
|
|
|
TempleConfig templeConfig = getTemple(null);
|
|
|
|
|
List<Specifications> specificationsList = new ArrayList<>();
|
|
|
|
|
Specifications specifications = new Specifications();
|
|
|
|
|
specifications.setMinWidth(100);
|
|
|
|
|
specifications.setMinHeight(100);
|
|
|
|
|
specifications.setMaxWidth(1000);
|
|
|
|
|
specifications.setMaxHeight(1000);
|
|
|
|
|
specificationsList.add(specifications);
|
|
|
|
|
ThreeChannelMatrix threeChannelMatrix = picture.getThreeMatrix("/Users/lidapeng/Desktop/myDocument/d.jpg");
|
|
|
|
|
Watershed watershed = new Watershed(threeChannelMatrix, specificationsList, templeConfig);
|
|
|
|
|
List<RegionBody> regionBodies = watershed.rainfall();
|
|
|
|
|
RegionBody regionBody = regionBodies.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;
|
|
|
|
|
ThreeChannelMatrix threeChannelMatrix1 = convolution.getRegionMatrix(threeChannelMatrix, minX, minY, xSize, ySize);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void picDo(ThreeChannelMatrix threeChannelMatrix) {//进行lbp特征提取
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static TempleConfig getTemple(ModelParameter modelParameter) throws Exception {
|
|
|
|
|
TempleConfig templeConfig = new TempleConfig();
|
|
|
|
|
//templeConfig.isShowLog(true);//是否打印日志
|
|
|
|
|
Cutting cutting = templeConfig.getCutting();
|
|
|
|
|
Food food = templeConfig.getFood();
|
|
|
|
|
//
|
|
|
|
|
cutting.setMaxRain(360);//切割阈值
|
|
|
|
|
cutting.setTh(0.6);
|
|
|
|
|
cutting.setRegionNub(200);
|
|
|
|
|
cutting.setMaxIou(0.5);
|
|
|
|
|
//knn参数
|
|
|
|
|
templeConfig.setKnnNub(1);
|
|
|
|
|
//池化比例
|
|
|
|
|
templeConfig.setPoolSize(2);//缩小比例
|
|
|
|
|
//聚类
|
|
|
|
|
templeConfig.setFeatureNub(3);//聚类特征数量
|
|
|
|
|
//菜品识别实体类
|
|
|
|
|
food.setShrink(10);//缩紧像素
|
|
|
|
|
food.setTimes(2);//聚类数据增强
|
|
|
|
|
food.setRowMark(0.1);//0.12
|
|
|
|
|
food.setColumnMark(0.1);//0.25
|
|
|
|
|
food.setRegressionNub(20000);
|
|
|
|
|
food.setTrayTh(0.08);
|
|
|
|
|
templeConfig.setClassifier(Classifier.KNN);
|
|
|
|
|
templeConfig.init(StudyPattern.Cover_Pattern, true, 400, 400, 3);
|
|
|
|
|
if (modelParameter != null) {
|
|
|
|
|
templeConfig.insertModel(modelParameter);
|
|
|
|
|
}
|
|
|
|
|
return templeConfig;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void test() throws Exception {//对分段回归进行测试
|
|
|
|
|
int size = 2000;
|
|
|
|
|
RegressionForest regressionForest = new RegressionForest(size, 3, 0.01, 200);
|
|
|
|
@ -41,18 +115,22 @@ public class ForestTest {
|
|
|
|
|
double sigma = 0;
|
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
|
|
|
double[] feature = a1.get(i);
|
|
|
|
|
double[] test = new double[]{feature[0], feature[1]};
|
|
|
|
|
Matrix test = new Matrix(1, 3);
|
|
|
|
|
test.setNub(0, 0, feature[0]);
|
|
|
|
|
test.setNub(0, 1, feature[1]);
|
|
|
|
|
test.setNub(0, 2, feature[2]);
|
|
|
|
|
double dist = regressionForest.getDist(test, feature[2]);
|
|
|
|
|
sigma = sigma + dist;
|
|
|
|
|
}
|
|
|
|
|
double avs = sigma / size;
|
|
|
|
|
System.out.println("a误差:" + avs);
|
|
|
|
|
// a误差:0.0017585065712555645
|
|
|
|
|
// b误差:0.00761733737464547
|
|
|
|
|
sigma = 0;
|
|
|
|
|
for (int i = 0; i < 1000; i++) {
|
|
|
|
|
double[] feature = b1.get(i);
|
|
|
|
|
double[] test = new double[]{feature[0], feature[1]};
|
|
|
|
|
Matrix test = new Matrix(1, 3);
|
|
|
|
|
test.setNub(0, 0, feature[0]);
|
|
|
|
|
test.setNub(0, 1, feature[1]);
|
|
|
|
|
test.setNub(0, 2, feature[2]);
|
|
|
|
|
double dist = regressionForest.getDist(test, feature[2]);
|
|
|
|
|
sigma = sigma + dist;
|
|
|
|
|
}
|
|
|
|
|