diff --git a/.classpath b/.classpath
index 136685672d01d4c8354c99513a8711750df586e3..da1d34b65a034d5627357a4acde1243064b77764 100644
--- a/.classpath
+++ b/.classpath
@@ -16,5 +16,6 @@
+
diff --git a/pom.xml b/pom.xml
index ee04f5ebadc16d2746742e8c3d163be4368ee0c6..40d8ad91a7262c304de521778d5848ce9e620896 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,6 +13,7 @@
3.8.0
11
+ UTF-8
@@ -38,5 +39,11 @@
poi-ooxml
4.1.2
+
+
+ net.sourceforge.tess4j
+ tess4j
+ 4.5.3
+
\ No newline at end of file
diff --git a/src/main/java/com/hy/java/uct/umlrecog/ClassDiagramRecognizer.java b/src/main/java/com/hy/java/uct/umlrecog/ClassDiagramRecognizer.java
index 82042dd04d05f639b158f6db389560b1ba773dbc..a58e47bfadad82734ad08e7eb71d2310a3acf7ae 100644
--- a/src/main/java/com/hy/java/uct/umlrecog/ClassDiagramRecognizer.java
+++ b/src/main/java/com/hy/java/uct/umlrecog/ClassDiagramRecognizer.java
@@ -1,5 +1,58 @@
package com.hy.java.uct.umlrecog;
+import java.util.List;
+
+import org.opencv.core.Core;
+import org.opencv.core.Mat;
+
+import com.hy.java.uct.umlrecog.cddetector.ClassDetector;
+import com.hy.java.uct.umlrecog.cddetector.ClassRelationDetector;
+import com.hy.java.uct.umlrecog.util.UMLClass;
+import com.hy.java.utility.common.Pair;
+import com.hy.java.utility.common.Traverser;
+import com.hy.java.utility.common.Traverser.FileNode;
+
public class ClassDiagramRecognizer {
+ public static void recog(String cd_dir, String repo_name) {
+ // 遍历cd_dir下的文件,寻找repo_name对应的图片,存在repo_cd_path中
+ String repo_cd_path = findCD(cd_dir, repo_name);
+ if (repo_cd_path != null) {
+ // 导入OpenCV库,开始识别
+ System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
+ // 识别类图中的类
+ ClassDetector cls_detector = new ClassDetector(repo_cd_path);
+ cls_detector.recog();
+ Pair> classes = cls_detector.getResult();
+ // 识别类图中的关系
+ ClassRelationDetector cls_relation_detector = new ClassRelationDetector(repo_cd_path, classes);
+ cls_relation_detector.recog();
+ // 整合文件吧,哈哈
+ cls_relation_detector.getResult();
+ } else {
+ System.err.println("不存在" + repo_name + "的类图");
+ }
+ }
+
+ private static String findCD(String cd_dir, String repo_name) {
+ String result = null;
+ // 用repo_name去查找图片时所使用的字符串
+ String search_string = cd_dir + "cd-" + repo_name.replaceAll("/", "_");
+ // 遍历cd_dir下的文件
+ List cd_dir_files = Traverser.traverseDir(cd_dir).children;
+ for (FileNode cd_dir_file : cd_dir_files) {
+ // 过滤掉result.txt文件,只找图片
+ if (cd_dir_file.path.equals(cd_dir + "result.txt")) {
+ continue;
+ }
+ // 针对图片名,去掉后缀后,与search_string做匹配
+ if (search_string.equals(cd_dir_file.path.substring(0, cd_dir_file.path.lastIndexOf(".")))) {
+ // 如果匹配成功,则保存图片路径
+ result = cd_dir_file.path;
+ // 找到指定图片后就可以结束查找了
+ break;
+ }
+ }
+ return result;
+ }
}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/SequenceDiagramRecognizer.java b/src/main/java/com/hy/java/uct/umlrecog/SequenceDiagramRecognizer.java
index d4056028a190ae9c0e43cec2dbce3658faaeeefc..2e719942e32c9f90c0d629289b3363eec74957f0 100644
--- a/src/main/java/com/hy/java/uct/umlrecog/SequenceDiagramRecognizer.java
+++ b/src/main/java/com/hy/java/uct/umlrecog/SequenceDiagramRecognizer.java
@@ -2,4 +2,8 @@ package com.hy.java.uct.umlrecog;
public class SequenceDiagramRecognizer {
+ public static void recog(String string, String string2) {
+ // TODO Auto-generated method stub
+
+ }
}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/UMLDiagramRecognizer.java b/src/main/java/com/hy/java/uct/umlrecog/UMLDiagramRecognizer.java
index 93c8420bff18b89a5cec79fa1d0b6e9e687dd1eb..48d9e14862710bc9c5a568823d7dcce8cda2deea 100644
--- a/src/main/java/com/hy/java/uct/umlrecog/UMLDiagramRecognizer.java
+++ b/src/main/java/com/hy/java/uct/umlrecog/UMLDiagramRecognizer.java
@@ -1,10 +1,39 @@
package com.hy.java.uct.umlrecog;
public class UMLDiagramRecognizer {
+ /**
+ * 将要识别的类图放在cd_dir目录下
+ */
+ private static final String cd_dir = System.getProperty("user.dir") + "\\src\\main\\resources\\cd\\";
- public static void main(String[] args) {
- // TODO Auto-generated method stub
+ /**
+ * 将要识别的顺序图放在sd_dir目录下
+ */
+ private static final String sd_dir = System.getProperty("user.dir") + "\\src\\main\\resources\\sd\\";
+ /**
+ * 将识别文字要用的tessdata放在tessdata下
+ */
+ public static final String tessdata_path = "D:\\eclipse-committers\\tessdata";
+
+ /**
+ * 识别目录下指定的类图并将结果存为文件
+ */
+ public static void recogCD(String cd_dir, String repo_name) {
+ ClassDiagramRecognizer.recog(cd_dir, repo_name);
+ }
+ /**
+ * 识别目录下指定的顺序图并将结果存为文件
+ */
+ public static void recogSD(String sd_dir, String repo_name) {
+ SequenceDiagramRecognizer.recog(sd_dir, repo_name);
}
+ /*
+ * 测试一下识别特定的类图和顺序图
+ */
+ public static void main(String[] args) {
+ UMLDiagramRecognizer.recogCD(cd_dir, "Team-MWSU/GroupProject");
+ UMLDiagramRecognizer.recogSD(sd_dir, "albanoj2/grp");
+ }
}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassDetector.java b/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassDetector.java
index 2e9bd0ccfd508da6aa8d9821cc2e5c1638827046..e5e2f8e4feb4626fafd6ed01d3169b5b58f2d253 100644
--- a/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassDetector.java
+++ b/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassDetector.java
@@ -1,5 +1,222 @@
package com.hy.java.uct.umlrecog.cddetector;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+
+import org.opencv.core.Mat;
+import org.opencv.core.MatOfPoint;
+import org.opencv.core.MatOfPoint2f;
+import org.opencv.core.Scalar;
+import org.opencv.imgcodecs.Imgcodecs;
+import org.opencv.imgproc.Imgproc;
+
+import com.hy.java.uct.umlrecog.UMLDiagramRecognizer;
+import com.hy.java.uct.umlrecog.util.Rectangle;
+import com.hy.java.uct.umlrecog.util.UMLClass;
+import com.hy.java.utility.common.Pair;
+
+import net.sourceforge.tess4j.ITesseract;
+import net.sourceforge.tess4j.Tesseract;
+import net.sourceforge.tess4j.TesseractException;
+
public class ClassDetector {
+ private String cd_path = null;
+ private String temp_res_path = null;
+ private Pair> result = null;
+
+ public ClassDetector(String repo_cd_path) {
+ this.cd_path = repo_cd_path;
+ this.temp_res_path = cd_path.replaceAll(cd_path.substring(cd_path.lastIndexOf("\\") + 1, cd_path.lastIndexOf(".")), "temp result");
+ }
+
+ public void recog() {
+ /*
+ * 预处理
+ */
+ // 读取图片。并灰度处理
+ Mat mat = Imgcodecs.imread(cd_path, Imgcodecs.IMREAD_GRAYSCALE);
+ // 高斯锐化,提升类图图形清晰度
+ // Imgproc.Laplacian(mat, mat, 2);
+ // 二值化,用于后续处理
+ Imgproc.threshold(mat, mat, 160, 255, Imgproc.THRESH_BINARY);
+ /*
+ * 识别类
+ */
+ // 矩形检测。识别所有矩形区域
+ Pair> all_rect_areas_in_cd = detectRectArea(mat, 0.000555);
+ // 对矩形进行整合,形成类区域
+ List classes = mergeIntoClass(all_rect_areas_in_cd);
+ // 对类区域进行文字检测
+ result = Pair.createPair(all_rect_areas_in_cd.getLeft(), detectText(classes));
+ }
+
+ /**
+ * 检测方框
+ *
+ * @param cls_diagram
+ * @param ratio 检测最小矩形占全图面积的比例(0~1之间的一个小数)。如果类图中类的面积很小,则该比例应设的很小。
+ * @return
+ */
+ private Pair> detectRectArea(Mat cls_diagram, double ratio) {
+ System.out.println("开始识别" + cd_path + "中所有矩形");
+ /*
+ * 识别图中所有“轮廓”并存在contours中
+ */
+ List contours = new ArrayList<>();
+ Imgproc.findContours(cls_diagram, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
+ /*
+ * 对每个轮廓contour,检测是否为矩形,并将contour和检测结果存在Pair中。所有轮廓的检测结果最终存在all_rect_areas中
+ */
+ List all_rect_areas = new ArrayList<>();
+ // 这个rect_contours里只存那些检测结果为矩形的contour,用于后面边框涂白,防止矩形干扰关系符号和关系线识别
+ List rect_contours = new ArrayList<>();
+ // 根据图片像素计算轮廓面积阈值。如果轮廓面积太小或太大,则直接忽略
+ int cd_width = cls_diagram.width();
+ int cd_height = cls_diagram.height();
+ long cd_area = cd_width * cd_height;
+ double min_cls_area = cd_area * ratio;
+ double max_cls_area = cd_area * 0.5;
+ for (MatOfPoint contour : contours) {
+ // 如果轮廓面积太小或太大,则直接忽略
+ double contour_area = Imgproc.contourArea(contour);
+ if (contour_area < min_cls_area || contour_area > max_cls_area) {
+ continue;
+ }
+ // 如果轮廓面积合适,则检测是否为矩形。采用多边形逼近法,将轮廓转化为curve向多边形做逼近,并将逼近结果存在approx_curve中
+ MatOfPoint2f curve = new MatOfPoint2f(contour.toArray());
+ MatOfPoint2f approx_curve = new MatOfPoint2f();
+ Imgproc.approxPolyDP(curve, approx_curve, 0.01 * Imgproc.arcLength(curve, true), true);
+ // 针对逼近结果approx_curve,若其共有4个顶点,则可认为是矩形。将检测结果绘制在原图中,便于后续处理
+ if (approx_curve.toArray().length == 4) {
+ // 将矩形存在all_rect_areas中用于类的整合和文字识别。存完后将其从原图中抹掉,防止其干扰关系符号和关系线识别
+ all_rect_areas.add(new Rectangle(cls_diagram.clone(), contour, approx_curve));
+ rect_contours.add(contour);
+ // 存完后将矩形从图中抹掉(涂白)。后面还需对所有边框进行涂白
+ Imgproc.fillConvexPoly(cls_diagram, contour, new Scalar(255, 255, 255));
+ }
+ }
+ // 对所有矩形边框进行涂白,防止其干扰关系符号和关系线识别
+ Imgproc.drawContours(cls_diagram, rect_contours, -1, new Scalar(255, 255, 255), 4);
+ // 此时的cls_diagram中矩形已涂白
+ return Pair.createPair(cls_diagram, all_rect_areas);
+ }
+
+ private List mergeIntoClass(Pair> all_rect_areas_in_cd) {
+ List result = new ArrayList<>();
+ // 获取所有矩形
+ List rect_area_list = all_rect_areas_in_cd.getRight();
+ /*
+ * 拼接思路:
+ *
+ * 首先针对当前矩形,将其赋给一个类。记录该类当前拥有的矩形列表。
+ *
+ * 然后针对该矩形的左上角,看是否与其他矩形的左上角横坐标相差不超过3~5个像素
+ *
+ * 如果是,则再看两个左上角的纵坐标距离是否大致等于“上面矩形”的高度
+ *
+ * 如果是,则纳入同一个类中
+ */
+ for (int all_rect_index = 0; all_rect_index < rect_area_list.size(); all_rect_index++) {
+ Rectangle current_rect = rect_area_list.get(all_rect_index);
+ // 如果当前rect已经属于某个类,则跳过它
+ if (current_rect.within_class) {
+ continue;
+ }
+ // 如果当前rect不属于任何类,则将其赋给一个新的类
+ UMLClass uml_class = new UMLClass();
+ uml_class.list.add(current_rect);
+ current_rect.within_class = true;
+ // 这个temp_rect用于每次拼接之后更新类的总大小。实际每次都是用temp_rect与其他未拼接的类作比较
+ uml_class.temp_rect = current_rect.clone();
+ // 对当前类的temp_rect,与all_rect_areas中其他所有矩形做比较
+ for (int j = all_rect_index + 1; j < rect_area_list.size(); j++) {
+ // 获取all_rect_areas列表中位于current_rect后面的矩形
+ Rectangle other_rect = rect_area_list.get(j);
+ // 针对该矩形的左上角,看是否与其他矩形的左上角横坐标相差不超过3~5个像素
+ if (Math.abs(other_rect.tl().x - uml_class.temp_rect.tl().x) <= 5) {
+ // 如果是,则再看两个左上角的纵坐标距离是否大致等于“上面矩形”的高度
+ // “上面矩形”是temp_rect
+ if (uml_class.temp_rect.tl().y < other_rect.tl().y) {
+ if (other_rect.tl().y - uml_class.temp_rect.tl().y - uml_class.temp_rect.height <= 5) {
+ uml_class.list.add(other_rect);
+ other_rect.within_class = true;
+ // 更新类的temp_rect
+ uml_class.temp_rect.height += other_rect.height;
+ }
+ }
+ // “上面矩形”是other_rect
+ else {
+ if (uml_class.temp_rect.tl().y - other_rect.tl().y - other_rect.height <= 5) {
+ uml_class.list.add(other_rect);
+ other_rect.within_class = true;
+ // 更新类的temp_rect
+ uml_class.temp_rect.x = other_rect.x;
+ uml_class.temp_rect.y = other_rect.y;
+ uml_class.temp_rect.height += other_rect.height;
+ }
+ }
+ }
+ }
+ // 将列表里的矩形按上、中、下排序
+ uml_class.list.sort(new Comparator() {
+ @Override
+ public int compare(Rectangle r1, Rectangle r2) {
+ return Integer.valueOf(r1.y).compareTo(r2.y);
+ }
+ });
+ for (int j = 0; j < uml_class.list.size(); j++) {
+ Rectangle r_in_l = uml_class.list.get(j);
+ if (r_in_l != null) {
+ switch (j) {
+ case 0: {
+ uml_class.top = r_in_l;
+ break;
+ }
+ case 1: {
+ uml_class.mid = r_in_l;
+ break;
+ }
+ case 2: {
+ uml_class.bottom = r_in_l;
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ }
+ // 针对当前矩形,与所有其他矩形对比完毕后,则完成了该类的识别
+ result.add(uml_class);
+ }
+ System.out.println("已将" + cd_path + "中的矩形整合为类,共" + result.size() + "个");
+ return result;
+ }
+
+ private List detectText(List classes) {
+ System.out.println("开始识别" + cd_path + "中每个类的文字");
+ for (UMLClass uc : classes) {
+ ITesseract instance = new Tesseract();
+ instance.setDatapath(UMLDiagramRecognizer.tessdata_path);
+ try {
+ // 将uc中的每个区域写入临时文件,然后识别临时文件中的文字
+ Imgcodecs.imwrite(temp_res_path, uc.top.getMat());
+ uc.setTitle(instance.doOCR(new File(temp_res_path)));
+ Imgcodecs.imwrite(temp_res_path, uc.mid.getMat());
+ uc.setAttrisStr(instance.doOCR(new File(temp_res_path)));
+ Imgcodecs.imwrite(temp_res_path, uc.bottom.getMat());
+ uc.setMethodsStr(instance.doOCR(new File(temp_res_path)));
+ } catch (TesseractException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ System.out.println("完成对" + cd_path + "中每个类的文字识别");
+ return classes;
+ }
+ public Pair> getResult() {
+ return result;
+ }
}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassRelationDetector.java b/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassRelationDetector.java
index 6e30f4d8b39af3b30defa30745faf32a3ed2d6f8..65e3be8aeaf5347f63ae8ee92762580389c16d07 100644
--- a/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassRelationDetector.java
+++ b/src/main/java/com/hy/java/uct/umlrecog/cddetector/ClassRelationDetector.java
@@ -1,5 +1,98 @@
package com.hy.java.uct.umlrecog.cddetector;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.opencv.core.Mat;
+import org.opencv.core.MatOfPoint;
+import org.opencv.core.MatOfPoint2f;
+import org.opencv.core.Point;
+import org.opencv.core.Scalar;
+import org.opencv.imgcodecs.Imgcodecs;
+import org.opencv.imgproc.Imgproc;
+
+import com.hy.java.uct.umlrecog.util.UMLClass;
+import com.hy.java.utility.common.Pair;
+
public class ClassRelationDetector {
+ private String cd_path = null;
+ private String temp_res_path = null;
+ private Pair> classes = null;
+ private Object result = null;
+
+ public ClassRelationDetector(String repo_cd_path, Pair> classes) {
+ this.cd_path = repo_cd_path;
+ this.temp_res_path = cd_path.replaceAll(cd_path.substring(cd_path.lastIndexOf("\\") + 1, cd_path.lastIndexOf(".")), "temp result");
+ this.classes = classes;
+ }
+
+ public void recog() {
+ // 关系类型检测
+ // Mat temp = detectRelationType(classes);
+ // 直线检测
+ // detectLines(temp);
+ }
+
+ /**
+ * 识别关系符号
+ *
+ * @param classes2
+ * @return
+ */
+ private static Mat detectRelationType(Pair> classes) {
+ // TODO Auto-generated method stub
+ System.out.println("识别所有关系符号");
+ List class_rects = new ArrayList<>();
+ // 识别图中所有“轮廓”并保存
+ List contours = new ArrayList<>();
+ Imgproc.findContours(classes.getLeft(), contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
+ // 对每个轮廓,检测是否为“特殊形状”
+ for (MatOfPoint contour : contours) {
+ // 如果轮廓面积太小或太大,则直接忽略。阈值可以根据图片像素动态计算
+ if (Imgproc.contourArea(contour) < 35 || Imgproc.contourArea(contour) > 1000) {
+ continue;
+ }
+ // 如果轮廓面积合适,则检测是否为关系符号形状。采用多边形逼近法
+ MatOfPoint2f curve = new MatOfPoint2f(contour.toArray());
+ MatOfPoint2f approx_curve = new MatOfPoint2f();
+ // 将轮廓向多边形做逼近
+ double epsilon = 0.01 * Imgproc.arcLength(curve, true);
+ Imgproc.approxPolyDP(curve, approx_curve, epsilon, true);
+ System.out.print(approx_curve.dump());
+ // 将每个关系符号存在别处。存完后将其从图中抹掉,防止其干扰直线识别
+ class_rects.add(contour);
+ // 将关系符号从图中抹掉(涂白)。后面还需对所有边框进行涂白
+ Imgproc.fillConvexPoly(classes.getLeft(), contour, new Scalar(15, 225, 25));
+ }
+ // 对所有边框进行涂白
+ Imgproc.drawContours(classes.getLeft(), class_rects, -1, new Scalar(255, 255, 255), 8);
+ // 将图片写入result文件
+ Imgcodecs.imwrite("D:\\eclipse-committers\\uml-code-trace\\src\\test\\resources\\result.png", classes.getLeft());
+ System.out.println("识别关系符号完毕,共" + class_rects.size() + "个");
+ return classes.getLeft();
+ }
+
+ private static void detectLines(Mat src) {
+ // TODO Auto-generated method stub
+ System.out.println("识别关系");
+ // 先检测边缘。然后从边缘集中检测直线
+ Mat canny = new Mat();
+ Imgproc.Canny(src, canny, 50, 150, 3, true);
+ // 从边缘集中检测直线
+ Mat lines = new Mat();
+ Imgproc.HoughLinesP(canny, lines, 1, Math.PI / 4, 12, 17, 20);
+ // 将检测到的直线绘制到图中
+ for (int i = 0; i < lines.rows(); i++) {
+ Point pt1 = new Point(lines.get(i, 0)[0], lines.get(i, 0)[1]);
+ Point pt2 = new Point(lines.get(i, 0)[2], lines.get(i, 0)[3]);
+ Imgproc.line(src, pt1, pt2, new Scalar(187, 255, 255), 2);
+ }
+ // Writing the image
+ Imgcodecs.imwrite("D:\\eclipse-committers\\uml-code-trace\\src\\test\\resources\\result.png", src);
+ System.out.println("识别关系完毕,共" + lines.rows() + "条");
+ }
+ public Object getResult() {
+ return result;
+ }
}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/util/ArrowDetector.java b/src/main/java/com/hy/java/uct/umlrecog/util/ArrowDetector.java
deleted file mode 100644
index 925982acc6587b191ec1038fe13d5cf28243f634..0000000000000000000000000000000000000000
--- a/src/main/java/com/hy/java/uct/umlrecog/util/ArrowDetector.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.hy.java.uct.umlrecog.util;
-
-public class ArrowDetector {
-
-}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/util/LineDetector.java b/src/main/java/com/hy/java/uct/umlrecog/util/LineDetector.java
deleted file mode 100644
index 409a116c4dd3e61fd19d20f10c8dc180962bbe95..0000000000000000000000000000000000000000
--- a/src/main/java/com/hy/java/uct/umlrecog/util/LineDetector.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.hy.java.uct.umlrecog.util;
-
-public class LineDetector {
-
-}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/util/Rectangle.java b/src/main/java/com/hy/java/uct/umlrecog/util/Rectangle.java
new file mode 100644
index 0000000000000000000000000000000000000000..fd5766365736bb27a98fdd1b839530638997436e
--- /dev/null
+++ b/src/main/java/com/hy/java/uct/umlrecog/util/Rectangle.java
@@ -0,0 +1,41 @@
+package com.hy.java.uct.umlrecog.util;
+
+import org.opencv.core.Mat;
+import org.opencv.core.MatOfPoint;
+import org.opencv.core.MatOfPoint2f;
+import org.opencv.core.Point;
+import org.opencv.core.Rect;
+
+public class Rectangle extends Rect {
+ private Mat mat;
+ private MatOfPoint contour;
+ public boolean within_class = false;
+
+ public Rectangle(Mat cls_diagram, MatOfPoint contour, MatOfPoint2f approx_rect) {
+ super(new Point(approx_rect.get(0, 0)[0], approx_rect.get(0, 0)[1]), new Point(approx_rect.get(2, 0)[0], approx_rect.get(2, 0)[1]));
+ this.mat = new Mat(cls_diagram, this);
+ this.contour = contour;
+ }
+
+ private Rectangle(Mat mat, MatOfPoint contour, int x, int y, int width, int height) {
+ super(x, y, width, height);
+ this.mat = mat;
+ this.contour = contour;
+ }
+
+ public Mat getMat() {
+ return mat;
+ }
+
+ public MatOfPoint getContour() {
+ return contour;
+ }
+
+ /**
+ * Creates and returns a copy of this object.
+ */
+ @Override
+ public Rectangle clone() {
+ return new Rectangle(mat, contour, this.x, this.y, this.width, this.height);
+ }
+}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/util/RectangleDetector.java b/src/main/java/com/hy/java/uct/umlrecog/util/RectangleDetector.java
deleted file mode 100644
index a16ad5d5b006159e5c0a55e58c9bcf895a0a4590..0000000000000000000000000000000000000000
--- a/src/main/java/com/hy/java/uct/umlrecog/util/RectangleDetector.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.hy.java.uct.umlrecog.util;
-
-public class RectangleDetector {
-
-}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/util/TextDetector.java b/src/main/java/com/hy/java/uct/umlrecog/util/TextDetector.java
deleted file mode 100644
index a865e1fc0cc7493fa22e1e3fcc3e6167a06d5c0d..0000000000000000000000000000000000000000
--- a/src/main/java/com/hy/java/uct/umlrecog/util/TextDetector.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.hy.java.uct.umlrecog.util;
-
-public class TextDetector {
-
-}
diff --git a/src/main/java/com/hy/java/uct/umlrecog/util/UMLClass.java b/src/main/java/com/hy/java/uct/umlrecog/util/UMLClass.java
new file mode 100644
index 0000000000000000000000000000000000000000..5b2e173a7d7fb83fdd474b0c3cd91954e49bd965
--- /dev/null
+++ b/src/main/java/com/hy/java/uct/umlrecog/util/UMLClass.java
@@ -0,0 +1,39 @@
+package com.hy.java.uct.umlrecog.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class UMLClass {
+ public List list = new ArrayList<>();
+ public Rectangle temp_rect = null;
+ public Rectangle top = null;
+ public Rectangle mid = null;
+ public Rectangle bottom = null;
+ private String title;
+ private String attris_str;
+ private String methods_str;
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getAttrisStr() {
+ return attris_str;
+ }
+
+ public void setAttrisStr(String attris_str) {
+ this.attris_str = attris_str;
+ }
+
+ public String getMethodsStr() {
+ return methods_str;
+ }
+
+ public void setMethodsStr(String methods_str) {
+ this.methods_str = methods_str;
+ }
+}
diff --git a/src/main/resources/cd/cd-BackupTheBerlios_jpwgen-svn.png b/src/main/resources/cd/cd-BackupTheBerlios_jpwgen-svn.png
new file mode 100644
index 0000000000000000000000000000000000000000..ff7c6247a13ee5c44d9a60ac545559ff43fe4217
Binary files /dev/null and b/src/main/resources/cd/cd-BackupTheBerlios_jpwgen-svn.png differ
diff --git a/src/main/resources/cd/cd-C204-242-DJSMT_Assignment-1.jpg b/src/main/resources/cd/cd-C204-242-DJSMT_Assignment-1.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..4b900513ed368d28229a724ecc79923493df335c
Binary files /dev/null and b/src/main/resources/cd/cd-C204-242-DJSMT_Assignment-1.jpg differ
diff --git a/src/main/resources/cd/cd-FantomKnight_AndEngine.png b/src/main/resources/cd/cd-FantomKnight_AndEngine.png
new file mode 100644
index 0000000000000000000000000000000000000000..7c9690ad35c0f2d1c87188d3fa8519c718fa53eb
Binary files /dev/null and b/src/main/resources/cd/cd-FantomKnight_AndEngine.png differ
diff --git a/src/main/resources/cd/cd-Istarnion_Team12.png b/src/main/resources/cd/cd-Istarnion_Team12.png
new file mode 100644
index 0000000000000000000000000000000000000000..91f0809d7159e7e7424151b2f942fdeb979bd457
Binary files /dev/null and b/src/main/resources/cd/cd-Istarnion_Team12.png differ
diff --git a/src/main/resources/cd/cd-MichelSc_touse.moplaf.jpg b/src/main/resources/cd/cd-MichelSc_touse.moplaf.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..754efe7716ee53137da48bca6cfc7ffa611c6056
Binary files /dev/null and b/src/main/resources/cd/cd-MichelSc_touse.moplaf.jpg differ
diff --git a/src/main/resources/cd/cd-OBHITA_Consent2Share.png b/src/main/resources/cd/cd-OBHITA_Consent2Share.png
new file mode 100644
index 0000000000000000000000000000000000000000..32b3294e2068ea81e421652dc9fc4b20fffb652c
Binary files /dev/null and b/src/main/resources/cd/cd-OBHITA_Consent2Share.png differ
diff --git a/src/main/resources/cd/cd-PillowSoPaw_SPSWENG-astroNATS.jpg b/src/main/resources/cd/cd-PillowSoPaw_SPSWENG-astroNATS.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..f37c2b16ceefca04e44b47f8e82e3b24da606bf1
Binary files /dev/null and b/src/main/resources/cd/cd-PillowSoPaw_SPSWENG-astroNATS.jpg differ
diff --git a/src/main/resources/cd/cd-Salaboy_smart-tasks.png b/src/main/resources/cd/cd-Salaboy_smart-tasks.png
new file mode 100644
index 0000000000000000000000000000000000000000..bfcb8e15253ff80d0341c99b8656505921507e13
Binary files /dev/null and b/src/main/resources/cd/cd-Salaboy_smart-tasks.png differ
diff --git a/src/main/resources/cd/cd-Sanchez82_Crawler.png b/src/main/resources/cd/cd-Sanchez82_Crawler.png
new file mode 100644
index 0000000000000000000000000000000000000000..2159c0f88476fe6104e42a79d3de807bb52e849b
Binary files /dev/null and b/src/main/resources/cd/cd-Sanchez82_Crawler.png differ
diff --git a/src/main/resources/cd/cd-Team-MWSU_GroupProject.png b/src/main/resources/cd/cd-Team-MWSU_GroupProject.png
new file mode 100644
index 0000000000000000000000000000000000000000..59f509a8dc4d3f3f72b612499efbb3edc11f358d
Binary files /dev/null and b/src/main/resources/cd/cd-Team-MWSU_GroupProject.png differ
diff --git a/src/main/resources/cd/cd-WiReSEP_Rollercoaster2011.png b/src/main/resources/cd/cd-WiReSEP_Rollercoaster2011.png
new file mode 100644
index 0000000000000000000000000000000000000000..83ca83cf8595a84b56c4682b89cef04dd09c9f94
Binary files /dev/null and b/src/main/resources/cd/cd-WiReSEP_Rollercoaster2011.png differ
diff --git a/src/main/resources/cd/cd-abrden_StarCraft.png b/src/main/resources/cd/cd-abrden_StarCraft.png
new file mode 100644
index 0000000000000000000000000000000000000000..838e5a36003bc5c7641424d6db863c81b05a65ea
Binary files /dev/null and b/src/main/resources/cd/cd-abrden_StarCraft.png differ
diff --git a/src/main/resources/cd/cd-alexasahis_km2.png b/src/main/resources/cd/cd-alexasahis_km2.png
new file mode 100644
index 0000000000000000000000000000000000000000..055ebb5505e013e6777e4f6a6dafae8ef748c75a
Binary files /dev/null and b/src/main/resources/cd/cd-alexasahis_km2.png differ
diff --git a/src/main/resources/cd/cd-badqiu_rapid-framework.jpg b/src/main/resources/cd/cd-badqiu_rapid-framework.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..39ac27c3f264792b5af09c1b2453e56359c87549
Binary files /dev/null and b/src/main/resources/cd/cd-badqiu_rapid-framework.jpg differ
diff --git a/src/main/resources/cd/cd-bojoer_loadui.png b/src/main/resources/cd/cd-bojoer_loadui.png
new file mode 100644
index 0000000000000000000000000000000000000000..f30a1d4e1ab4c86f7aad2735fc93a3c83af2e5ff
Binary files /dev/null and b/src/main/resources/cd/cd-bojoer_loadui.png differ
diff --git a/src/main/resources/cd/cd-cscfa_bartleby.jpg b/src/main/resources/cd/cd-cscfa_bartleby.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..cb6578208bc56986a8d4e66a23f8a9709c7138a4
Binary files /dev/null and b/src/main/resources/cd/cd-cscfa_bartleby.jpg differ
diff --git a/src/main/resources/cd/cd-dsarlis_SoftEng.png b/src/main/resources/cd/cd-dsarlis_SoftEng.png
new file mode 100644
index 0000000000000000000000000000000000000000..b6450cd570c2163cc939026210669ce996230116
Binary files /dev/null and b/src/main/resources/cd/cd-dsarlis_SoftEng.png differ
diff --git a/src/main/resources/cd/cd-egoless_pqs.png b/src/main/resources/cd/cd-egoless_pqs.png
new file mode 100644
index 0000000000000000000000000000000000000000..c03a01b83263990836df45c5b0ffc304cdd37feb
Binary files /dev/null and b/src/main/resources/cd/cd-egoless_pqs.png differ
diff --git a/src/main/resources/cd/cd-emeric254_Java-STRI-S4.png b/src/main/resources/cd/cd-emeric254_Java-STRI-S4.png
new file mode 100644
index 0000000000000000000000000000000000000000..4729438fdd9fa05647fec24c4e3872175290c9ba
Binary files /dev/null and b/src/main/resources/cd/cd-emeric254_Java-STRI-S4.png differ
diff --git a/src/main/resources/cd/cd-felps_FTFramework.png b/src/main/resources/cd/cd-felps_FTFramework.png
new file mode 100644
index 0000000000000000000000000000000000000000..97c4cf1bb1aa894a9df63eb8205d9cd1c4e97ab2
Binary files /dev/null and b/src/main/resources/cd/cd-felps_FTFramework.png differ
diff --git a/src/main/resources/cd/cd-fltt_jss7.png b/src/main/resources/cd/cd-fltt_jss7.png
new file mode 100644
index 0000000000000000000000000000000000000000..7174fd728f4ed04c48bc517153a99642376bcec2
Binary files /dev/null and b/src/main/resources/cd/cd-fltt_jss7.png differ
diff --git a/src/main/resources/cd/cd-gemxd_gemfirexd-oss.png b/src/main/resources/cd/cd-gemxd_gemfirexd-oss.png
new file mode 100644
index 0000000000000000000000000000000000000000..afbeaa46990dea2d930b81027dfb99cee8cade93
Binary files /dev/null and b/src/main/resources/cd/cd-gemxd_gemfirexd-oss.png differ
diff --git a/src/main/resources/cd/cd-georgejakes_Xug.jpg b/src/main/resources/cd/cd-georgejakes_Xug.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..cb6578208bc56986a8d4e66a23f8a9709c7138a4
Binary files /dev/null and b/src/main/resources/cd/cd-georgejakes_Xug.jpg differ
diff --git a/src/main/resources/cd/cd-ging_isabel.png b/src/main/resources/cd/cd-ging_isabel.png
new file mode 100644
index 0000000000000000000000000000000000000000..a99e362c59b56f674f09995f7d4a68a51ba77ccc
Binary files /dev/null and b/src/main/resources/cd/cd-ging_isabel.png differ
diff --git a/src/main/resources/cd/cd-hangum_TadpoleForDBTools.png b/src/main/resources/cd/cd-hangum_TadpoleForDBTools.png
new file mode 100644
index 0000000000000000000000000000000000000000..072223e90b43a6e2d8aaa35af8a01c792ff9294e
Binary files /dev/null and b/src/main/resources/cd/cd-hangum_TadpoleForDBTools.png differ
diff --git a/src/main/resources/cd/cd-hungnguyen94_BTrouble.jpg b/src/main/resources/cd/cd-hungnguyen94_BTrouble.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..f493959072ad1b60733dad951af0123fc5993f6b
Binary files /dev/null and b/src/main/resources/cd/cd-hungnguyen94_BTrouble.jpg differ
diff --git a/src/main/resources/cd/cd-jaissegrela_steganography.png b/src/main/resources/cd/cd-jaissegrela_steganography.png
new file mode 100644
index 0000000000000000000000000000000000000000..2a7ef47748b20b75c6a7052143760c6c04ed6e19
Binary files /dev/null and b/src/main/resources/cd/cd-jaissegrela_steganography.png differ
diff --git a/src/main/resources/cd/cd-jguze_ACiv.png b/src/main/resources/cd/cd-jguze_ACiv.png
new file mode 100644
index 0000000000000000000000000000000000000000..aa6794e89bb9d4e6d57765950275e4aab20f1780
Binary files /dev/null and b/src/main/resources/cd/cd-jguze_ACiv.png differ
diff --git a/src/main/resources/cd/cd-jorgearj_USDLPricing_API.png b/src/main/resources/cd/cd-jorgearj_USDLPricing_API.png
new file mode 100644
index 0000000000000000000000000000000000000000..66f682f72c40620087b0b85fdc1d9a42cc7a1890
Binary files /dev/null and b/src/main/resources/cd/cd-jorgearj_USDLPricing_API.png differ
diff --git a/src/main/resources/cd/cd-kauffmj_modificare.png b/src/main/resources/cd/cd-kauffmj_modificare.png
new file mode 100644
index 0000000000000000000000000000000000000000..fe9b6786a0e6adc06b35cf37b60678f893840766
Binary files /dev/null and b/src/main/resources/cd/cd-kauffmj_modificare.png differ
diff --git a/src/main/resources/cd/cd-kbarrett_third-year-project.png b/src/main/resources/cd/cd-kbarrett_third-year-project.png
new file mode 100644
index 0000000000000000000000000000000000000000..dff4e14fedae6c6e5fe67f92c0bfa1de74aba502
Binary files /dev/null and b/src/main/resources/cd/cd-kbarrett_third-year-project.png differ
diff --git a/src/main/resources/cd/cd-klemens_openolat.jpg b/src/main/resources/cd/cd-klemens_openolat.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..b52b67baa51ae3e48b915c8e47251515c87da4d1
Binary files /dev/null and b/src/main/resources/cd/cd-klemens_openolat.jpg differ
diff --git a/src/main/resources/cd/cd-kuali_rice.png b/src/main/resources/cd/cd-kuali_rice.png
new file mode 100644
index 0000000000000000000000000000000000000000..9da15fff7cdce9d13fd7a37b07adca7e8ee01a86
Binary files /dev/null and b/src/main/resources/cd/cd-kuali_rice.png differ
diff --git a/src/main/resources/cd/cd-leemdoyun_android-education-project.png b/src/main/resources/cd/cd-leemdoyun_android-education-project.png
new file mode 100644
index 0000000000000000000000000000000000000000..54525f823f2ce1b9e2b765bfffe16d12cdf44b38
Binary files /dev/null and b/src/main/resources/cd/cd-leemdoyun_android-education-project.png differ
diff --git a/src/main/resources/cd/cd-lorneliechty_pleaseholdapplause.jpg b/src/main/resources/cd/cd-lorneliechty_pleaseholdapplause.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..84dcb84dad0b7ee26cd1571ed2f0e82fcaa7db9f
Binary files /dev/null and b/src/main/resources/cd/cd-lorneliechty_pleaseholdapplause.jpg differ
diff --git a/src/main/resources/cd/cd-luis-alberto_magicBinder.png b/src/main/resources/cd/cd-luis-alberto_magicBinder.png
new file mode 100644
index 0000000000000000000000000000000000000000..5bb0bcffb93002d44952be3d1b86f67ad74292cb
Binary files /dev/null and b/src/main/resources/cd/cd-luis-alberto_magicBinder.png differ
diff --git a/src/main/resources/cd/cd-marcellodesales_my-cs-research.png b/src/main/resources/cd/cd-marcellodesales_my-cs-research.png
new file mode 100644
index 0000000000000000000000000000000000000000..0e27c1d20c013779b06db2aedb44913d279e628d
Binary files /dev/null and b/src/main/resources/cd/cd-marcellodesales_my-cs-research.png differ
diff --git a/src/main/resources/cd/cd-neuroph_neuroph.jpg b/src/main/resources/cd/cd-neuroph_neuroph.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..0cd7c707dfbd6bf567bdf16e44aea4fe3b9ae60a
Binary files /dev/null and b/src/main/resources/cd/cd-neuroph_neuroph.jpg differ
diff --git a/src/main/resources/cd/cd-petergodfrey_TradeSimulator.png b/src/main/resources/cd/cd-petergodfrey_TradeSimulator.png
new file mode 100644
index 0000000000000000000000000000000000000000..1107d8c0979cc47f45cb0e3b23702b11af54ac17
Binary files /dev/null and b/src/main/resources/cd/cd-petergodfrey_TradeSimulator.png differ
diff --git a/src/main/resources/cd/cd-portmobile_LAGP-Example-Code.png b/src/main/resources/cd/cd-portmobile_LAGP-Example-Code.png
new file mode 100644
index 0000000000000000000000000000000000000000..03ba6d9792391c67118023196b8b6581888c48a2
Binary files /dev/null and b/src/main/resources/cd/cd-portmobile_LAGP-Example-Code.png differ
diff --git a/src/main/resources/cd/cd-rNdm74_Java.png b/src/main/resources/cd/cd-rNdm74_Java.png
new file mode 100644
index 0000000000000000000000000000000000000000..3576cab6f1a8b486de549a43a6ec624fb2d553d4
Binary files /dev/null and b/src/main/resources/cd/cd-rNdm74_Java.png differ
diff --git a/src/main/resources/cd/cd-retoo_bodesuri.png b/src/main/resources/cd/cd-retoo_bodesuri.png
new file mode 100644
index 0000000000000000000000000000000000000000..39f2942b0361bafbf9bf2196d1625f26da3746eb
Binary files /dev/null and b/src/main/resources/cd/cd-retoo_bodesuri.png differ
diff --git a/src/main/resources/cd/cd-richardimms_PRCSA.png b/src/main/resources/cd/cd-richardimms_PRCSA.png
new file mode 100644
index 0000000000000000000000000000000000000000..653de74af74abc6f9aab77407e77b5d2164e39ea
Binary files /dev/null and b/src/main/resources/cd/cd-richardimms_PRCSA.png differ
diff --git a/src/main/resources/cd/cd-rodrigoazevedomartins_TrabalhoFinalLTPIII.jpeg b/src/main/resources/cd/cd-rodrigoazevedomartins_TrabalhoFinalLTPIII.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..7ef462cc7e89cd4b331f64f3e2677b80b334fa97
Binary files /dev/null and b/src/main/resources/cd/cd-rodrigoazevedomartins_TrabalhoFinalLTPIII.jpeg differ
diff --git a/src/main/resources/cd/cd-snucsne_bio-inspired-leadership.png b/src/main/resources/cd/cd-snucsne_bio-inspired-leadership.png
new file mode 100644
index 0000000000000000000000000000000000000000..e057328c43f1c0f95ec999d52e410d3524634d55
Binary files /dev/null and b/src/main/resources/cd/cd-snucsne_bio-inspired-leadership.png differ
diff --git a/src/main/resources/cd/cd-steyskal_Ren-Fest.png b/src/main/resources/cd/cd-steyskal_Ren-Fest.png
new file mode 100644
index 0000000000000000000000000000000000000000..1075b9c18a97eff6cc9be94b515c4f0a8fa9cfac
Binary files /dev/null and b/src/main/resources/cd/cd-steyskal_Ren-Fest.png differ
diff --git a/src/main/resources/cd/cd-teopalva_travel-dream.png b/src/main/resources/cd/cd-teopalva_travel-dream.png
new file mode 100644
index 0000000000000000000000000000000000000000..993f1a4ac7361ef5a03979c3c1c8bbf6f0f9f87c
Binary files /dev/null and b/src/main/resources/cd/cd-teopalva_travel-dream.png differ
diff --git a/src/main/resources/cd/cd-tiendan3108_CP.jpg b/src/main/resources/cd/cd-tiendan3108_CP.jpg
new file mode 100644
index 0000000000000000000000000000000000000000..a32adf009aab9d2f72897f83a146b61f1181e1b9
Binary files /dev/null and b/src/main/resources/cd/cd-tiendan3108_CP.jpg differ
diff --git a/src/main/resources/cd/cd-ultragdb_org.eclipse.cdt.jpeg b/src/main/resources/cd/cd-ultragdb_org.eclipse.cdt.jpeg
new file mode 100644
index 0000000000000000000000000000000000000000..aabe897c1db72c264c9b2c360238704155208deb
Binary files /dev/null and b/src/main/resources/cd/cd-ultragdb_org.eclipse.cdt.jpeg differ
diff --git a/src/main/resources/cd/cd-valentinamata_flow3in2013.png b/src/main/resources/cd/cd-valentinamata_flow3in2013.png
new file mode 100644
index 0000000000000000000000000000000000000000..81ec88d36a6aeffb6db635e2d01fd84ab30b7a24
Binary files /dev/null and b/src/main/resources/cd/cd-valentinamata_flow3in2013.png differ
diff --git a/src/main/resources/cd/temp result.png b/src/main/resources/cd/temp result.png
new file mode 100644
index 0000000000000000000000000000000000000000..57e4abc065765d1484e301fc4f91be935dfaf34a
Binary files /dev/null and b/src/main/resources/cd/temp result.png differ
diff --git a/src/main/resources/sd/sd-albanoj2_grp.png b/src/main/resources/sd/sd-albanoj2_grp.png
new file mode 100644
index 0000000000000000000000000000000000000000..4ca99cb6e053bcfbc448ad585c0fe9dde43b70d0
Binary files /dev/null and b/src/main/resources/sd/sd-albanoj2_grp.png differ
diff --git a/src/test/java/com/hy/java/uct/umlrecog/OtherTests.java b/src/test/java/com/hy/java/uct/umlrecog/OtherTests.java
new file mode 100644
index 0000000000000000000000000000000000000000..fc7e8db30065dca7ae7ce354857d67fc73338d60
--- /dev/null
+++ b/src/test/java/com/hy/java/uct/umlrecog/OtherTests.java
@@ -0,0 +1,38 @@
+package com.hy.java.uct.umlrecog;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class OtherTests {
+ @Test
+ public void list_remove() {
+ List list = new ArrayList<>();
+ list.add("a");
+ list.add("bb");
+ list.add("ccc");
+ list.add("dddd");
+ list.add("eeeee");
+ list.add("ffffff");
+ String temp = list.get(2);
+ // 用ArrayList的构造法复制list,从而使all_other_es的操作不影响list
+ List result = all_other_es(new ArrayList(list), temp);
+ for (String s : result) {
+ System.out.println(s);
+ }
+ System.out.println("==============================================");
+ for (String s : list) {
+ System.out.println(s);
+ }
+ }
+
+ private List all_other_es(List list, String temp) {
+ List result = new ArrayList<>();
+ list.remove(temp);
+ for (String s : list) {
+ result.add(String.valueOf(s.length()));
+ }
+ return result;
+ }
+}
diff --git a/src/test/resources/result.png b/src/test/resources/result.png
index d49509128935a2a6340c1f393a42c1a3bfdd31a5..00bf372e41d7e248274899d5194cd890247748f3 100644
Binary files a/src/test/resources/result.png and b/src/test/resources/result.png differ