From c10adfa88512e2bb3f373a91abadf0352a0fa587 Mon Sep 17 00:00:00 2001 From: lidapeng <794757862@qq.com> Date: Tue, 21 Jul 2020 10:11:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=87=E5=89=B2=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E8=BE=B9=E7=BC=98=E5=87=8F=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wlld/imageRecognition/TempleConfig.java | 9 +++++++++ .../segmentation/Watershed.java | 20 +++++++++++++------ src/test/java/coverTest/FoodTest.java | 16 +++------------ src/test/java/org/wlld/LangTest.java | 17 ++++++++-------- 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/wlld/imageRecognition/TempleConfig.java b/src/main/java/org/wlld/imageRecognition/TempleConfig.java index 87a033f..03b355e 100644 --- a/src/main/java/org/wlld/imageRecognition/TempleConfig.java +++ b/src/main/java/org/wlld/imageRecognition/TempleConfig.java @@ -70,6 +70,15 @@ public class TempleConfig { private ThreeChannelMatrix backGround;//背景面板 private double backGroundError;//背景误差偏移量,0-255 private Cutting cutting = new Cutting(); + private double edge = 0;//边缘剪掉多少份 + + public double getEdge() { + return edge; + } + + public void setEdge(double edge) { + this.edge = edge; + } public Cutting getCutting() { return cutting; diff --git a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java index 4dbabdc..a90cc10 100644 --- a/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java +++ b/src/main/java/org/wlld/imageRecognition/segmentation/Watershed.java @@ -18,8 +18,8 @@ public class Watershed { private Matrix regionMap;//分区图 private int xSize;//单元高度 private int ySize;//单元宽度 - private double th = Kernel.th;//灰度阈值 - private int regionNub = Kernel.Region_Nub;//一张图分多少份 + private double th;//灰度阈值 + private int regionNub;//一张图分多少份 private Map regionBodyMap = new HashMap<>(); private double rainTh = 0; private int xMax; @@ -27,6 +27,7 @@ public class Watershed { private double maxRain; private double width; private double height; + private double edgeSize = 0;//边缘提取多少份 private List specifications; public Watershed(Matrix matrix, List specifications, TempleConfig templeConfig) throws Exception { @@ -37,6 +38,9 @@ public class Watershed { maxRain = cutting.getMaxRain(); this.matrix = matrix; this.specifications = specifications; + if (templeConfig.getEdge() > 0) { + edgeSize = templeConfig.getEdge(); + } width = matrix.getY(); height = matrix.getX(); xSize = matrix.getX() / regionNub; @@ -216,11 +220,15 @@ public class Watershed { for (Specifications specification : specifications) { int width = maxY - minY; int height = maxX - minX; -// double h = this.height / 8; -// double w = this.width / 8; - // boolean isCenter = minX > h && minY > w && minX < (h * 4.5) && minY < (w * 4.5); + boolean isCenter = true; + if (edgeSize > 0) { + double h = this.height / edgeSize; + double w = this.width / edgeSize; + isCenter = maxX > h && maxY > w && maxX < (h * (edgeSize - 1)) && maxY < (w * (edgeSize - 1)); + } if (width >= specification.getMinWidth() && height >= specification.getMinHeight() - && width <= specification.getMaxWidth() && height <= specification.getMaxHeight()) { + && width <= specification.getMaxWidth() && height <= specification.getMaxHeight() + && isCenter) { isRight = true; break; } diff --git a/src/test/java/coverTest/FoodTest.java b/src/test/java/coverTest/FoodTest.java index 7d8fdab..0c633e0 100644 --- a/src/test/java/coverTest/FoodTest.java +++ b/src/test/java/coverTest/FoodTest.java @@ -112,22 +112,12 @@ public class FoodTest { for (int i = 1; i <= 1; i++) { ThreeChannelMatrix threeChannelMatrix1 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/a" + i + ".jpg"); ThreeChannelMatrix threeChannelMatrix2 = picture.getThreeMatrix("/Users/lidapeng/Documents/paramterTest/b" + i + ".jpg"); - operation.colorStudy(threeChannelMatrix1, 83, specificationsList); + operation.colorStudy(threeChannelMatrix1, 1, specificationsList); System.out.println("======================================="); - operation.colorStudy(threeChannelMatrix2, 86, specificationsList); + operation.colorStudy(threeChannelMatrix2, 2, specificationsList); System.out.println("=======================================" + i); } - ModelParameter modelParameter = templeConfig.getModel(); - if (modelParameter.getKnnVector() != null) { - System.out.println("not null 1"); - } - String tr = JSON.toJSONString(modelParameter); - System.out.println(tr); - ModelParameter modelParameter1 = JSON.parseObject(tr, ModelParameter.class); - if (modelParameter1.getKnnVector() != null) { - System.out.println("not null 2"); - } - //test2(templeConfig); + test2(templeConfig); } public static void study() throws Exception { diff --git a/src/test/java/org/wlld/LangTest.java b/src/test/java/org/wlld/LangTest.java index 1df3657..6d64d67 100644 --- a/src/test/java/org/wlld/LangTest.java +++ b/src/test/java/org/wlld/LangTest.java @@ -71,19 +71,20 @@ public class LangTest { //创建模板读取累 TemplateReader templateReader = new TemplateReader(); WordTemple wordTemple = new WordTemple();//初始化语言模版 - wordTemple.setTreeNub(9); - // wordTemple.setSplitWord(true); + //wordTemple.setTreeNub(9); + //wordTemple.setTrustPunishment(0.5); + wordTemple.setSplitWord(true); //读取语言模版,第一个参数是模版地址,第二个参数是编码方式 (教程里的第三个参数已经省略) //同时也是学习过程 templateReader.read("/Users/lidapeng/Desktop/myDocument/model.txt", "UTF-8", wordTemple); Talk talk = new Talk(wordTemple); //输入语句进行识别,若有标点符号会形成LIST中的每个元素 //返回的集合中每个值代表了输入语句,每个标点符号前语句的分类 -// List> lists = talk.getSplitWord("空调坏了,帮我修一修"); -// for (List list : lists) { -// System.out.println(list); -// } - List list = talk.talk("空调坏了,帮我修一修"); - System.out.println(list); + List> lists = talk.getSplitWord("空调坏了,帮我修一修"); + for (List list : lists) { + System.out.println(list); + } +// List list = talk.talk("空调坏了,帮我修一修"); +// System.out.println(list); } }