Loading pom.xml +7 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <exec.mainClass>top.BackendJava</exec.mainClass> <exec.mainClass>object_detection.ObjectDetector</exec.mainClass> </properties> <!-- FOR THE YOLO USAGE: Loading Loading @@ -80,6 +80,12 @@ <artifactId>spring-boot-devtools</artifactId> <version>3.2.4</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>6.1.4</version> </dependency> </dependencies> Loading src/main/java/object_detection/ObjectDetector.java +11 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import object_detection.types.Point; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ObjectDetector { Loading @@ -22,6 +23,10 @@ public class ObjectDetector { File[] feat_CSVs = getDirFiles(feat_dir_pth); File[] bbox_CSVs = getDirFiles(bbox_dir_pth); // sort to guarantee correct order for keyframes Arrays.sort(feat_CSVs); Arrays.sort(bbox_CSVs); // check to make sure both file arrays have same number of keyframes (for consistency) if(feat_CSVs.length != bbox_CSVs.length){ System.err.println("ERROR: features and bounding box directories have differing number of Keyframes"); Loading @@ -38,6 +43,8 @@ public class ObjectDetector { List<ArrayList<Point>> currFramePoints = objSet.processFrame(feat_CSVs[i], bbox_CSVs[i]); objSet.updateObjectSet(currFramePoints); } System.out.println(objSet); } public static File[] getDirFiles(String dir_pth){ Loading @@ -57,4 +64,8 @@ public class ObjectDetector { return f_arr; } public static void main(String[] args) throws FileNotFoundException { startProcess(); } } src/main/java/object_detection/types/BoundingBox.java +3 −1 Original line number Diff line number Diff line Loading @@ -2,12 +2,13 @@ package object_detection.types; public class BoundingBox { public BoundingBox(Point2D tr, Point2D tl, Point2D br, Point2D bl, int idx){ public BoundingBox(Point2D tr, Point2D tl, Point2D br, Point2D bl, int idx, String predClass){ this.topRight = tr; this.topLeft = tl; this.botRight = br; this.botLeft = bl; this.idx = idx; this.predClass = predClass; } public boolean within(Point2D p){ Loading @@ -24,4 +25,5 @@ public class BoundingBox { Point2D botRight; Point2D botLeft; int idx; String predClass; } src/main/java/object_detection/types/ObjectSet.java +26 −14 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ import java.util.*; public class ObjectSet { public static List<PointSet> objects; static int count = 0; public List<PointSet> objects; int count = 0; public ObjectSet(){ objects = new ArrayList<>(); } Loading @@ -20,7 +20,7 @@ public class ObjectSet { public int makeObject(Point...pp){ PointSet ps = new PointSet(); ps.addAll(pp); count++; this.count++; ps.updateReps(); // add pointset to object list Loading @@ -36,9 +36,9 @@ public class ObjectSet { * @param j : the new candidate object * @return true if objects are the same */ public static boolean compareObjects(int i, int j){ Point[] r1 = objects.get(i).getPoints(); Point[] r2 = objects.get(j).getPoints(); public boolean compareObjects(int i, int j){ Point[] r1 = this.objects.get(i).getPoints(); Point[] r2 = this.objects.get(j).getPoints(); // compare r1 and r2 Set<Point> s = new HashSet<>(); Loading Loading @@ -67,16 +67,16 @@ public class ObjectSet { public void combineObjects(int i, int j){ // add all points of j to i objects.get(i).addAll(objects.get(j).getPoints()); this.objects.get(i).addAll(this.objects.get(j).getPoints()); // redo reps of the object with new points objects.get(i).updateReps(); this.objects.get(i).updateReps(); // remove j objects.remove(j); this.objects.remove(j); // lower the count count--; this.count--; // eventually, push i to database } Loading Loading @@ -108,7 +108,7 @@ public class ObjectSet { while (scanner.hasNextLine()) { // Print the line of the file being processed System.out.println("Processing line " + lineNum++); //System.out.println("Processing line " + lineNum++); String[] line = scanner.nextLine().split(","); Point2D point2D = new Point2D(Float.parseFloat(line[0]), Float.parseFloat(line[1]), Integer.parseInt(line[2])); Loading @@ -135,8 +135,8 @@ public class ObjectSet { * */ public void updateObjectSet(List<ArrayList<Point>> points) { for (int i = 0; i < points.size(); i++) { Point[] pointArray = points.get(i).toArray(new Point[0]); for(ArrayList<Point> point : points) { Point[] pointArray = point.toArray(new Point[0]); int objIdx = makeObject(pointArray); // Compare the new object with all existing objects Loading @@ -153,15 +153,27 @@ public class ObjectSet { List<BoundingBox> boxes = new ArrayList<>(); Scanner scanner = new Scanner(bboxCsv); scanner.nextLine(); // Skip header int i = 0; while (scanner.hasNextLine()) { String[] line = scanner.nextLine().split(","); Point2D tr = new Point2D(Float.parseFloat(line[2]) + Float.parseFloat(line[4]), Float.parseFloat(line[3]), 0); Point2D tl = new Point2D(Float.parseFloat(line[2]), Float.parseFloat(line[3]), 0); Point2D br = new Point2D(Float.parseFloat(line[2]) + Float.parseFloat(line[4]), Float.parseFloat(line[3]) + Float.parseFloat(line[5]), 0); Point2D bl = new Point2D(Float.parseFloat(line[2]), Float.parseFloat(line[3]) + Float.parseFloat(line[5]), 0); boxes.add(new BoundingBox(tr, tl, br, bl, Integer.parseInt(line[0]))); boxes.add(new BoundingBox(tr, tl, br, bl, i, line[0])); i++; } scanner.close(); return boxes; } @Override public String toString(){ StringBuilder res = new StringBuilder("ObjectSet:"); for(PointSet p : this.objects){ res.append("\n\t - Object with ").append(p.pset.size()).append(" points"); } return res.toString(); } } No newline at end of file src/main/java/top/BackendJava.java +60 −2 Original line number Diff line number Diff line Loading @@ -3,10 +3,19 @@ package top; import object_detection.ObjectDetector; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @SpringBootApplication public class BackendJava { Loading @@ -14,18 +23,67 @@ public class BackendJava { @Controller public static class BackendService { @RequestMapping("/hello") @ResponseBody public String hello(){ return "Hello There"; } @RequestMapping("/") public String index(){ return "html/index"; } @RequestMapping("/runProcess") @ResponseBody public boolean runProcess() throws FileNotFoundException { System.out.println(" ============> Starting process"); ObjectDetector.startProcess(); return true; } @RequestMapping("/getJSON") @ResponseBody public Map<String, ArrayList<ArrayList<Float>>> tempJson(){ Map<String, ArrayList<ArrayList<Float>>> temp = new HashMap<>(); ArrayList<Float> pp = new ArrayList<>(); pp.add(0.0f); pp.add(0.0f); pp.add(0.0f); ArrayList<ArrayList<Float>> obj = new ArrayList<>(); obj.add(pp); temp.put("obj1", obj); return temp; } @RequestMapping("/style/main.css") public String getStyle(){ return "style/main.css"; } @RequestMapping("/js/app.js") public String getApp(){ return "js/app.js"; } @RequestMapping("/js/pointCloud.js") public String getPC(){ return "js/pointCloud.js"; } } @Configuration @EnableWebMvc public class WebMvcConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedOrigins("http://localhost:5555"); } } public static void main(String[] args) { Loading Loading
pom.xml +7 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ <maven.compiler.source>17</maven.compiler.source> <maven.compiler.target>17</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <exec.mainClass>top.BackendJava</exec.mainClass> <exec.mainClass>object_detection.ObjectDetector</exec.mainClass> </properties> <!-- FOR THE YOLO USAGE: Loading Loading @@ -80,6 +80,12 @@ <artifactId>spring-boot-devtools</artifactId> <version>3.2.4</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>6.1.4</version> </dependency> </dependencies> Loading
src/main/java/object_detection/ObjectDetector.java +11 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import object_detection.types.Point; import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ObjectDetector { Loading @@ -22,6 +23,10 @@ public class ObjectDetector { File[] feat_CSVs = getDirFiles(feat_dir_pth); File[] bbox_CSVs = getDirFiles(bbox_dir_pth); // sort to guarantee correct order for keyframes Arrays.sort(feat_CSVs); Arrays.sort(bbox_CSVs); // check to make sure both file arrays have same number of keyframes (for consistency) if(feat_CSVs.length != bbox_CSVs.length){ System.err.println("ERROR: features and bounding box directories have differing number of Keyframes"); Loading @@ -38,6 +43,8 @@ public class ObjectDetector { List<ArrayList<Point>> currFramePoints = objSet.processFrame(feat_CSVs[i], bbox_CSVs[i]); objSet.updateObjectSet(currFramePoints); } System.out.println(objSet); } public static File[] getDirFiles(String dir_pth){ Loading @@ -57,4 +64,8 @@ public class ObjectDetector { return f_arr; } public static void main(String[] args) throws FileNotFoundException { startProcess(); } }
src/main/java/object_detection/types/BoundingBox.java +3 −1 Original line number Diff line number Diff line Loading @@ -2,12 +2,13 @@ package object_detection.types; public class BoundingBox { public BoundingBox(Point2D tr, Point2D tl, Point2D br, Point2D bl, int idx){ public BoundingBox(Point2D tr, Point2D tl, Point2D br, Point2D bl, int idx, String predClass){ this.topRight = tr; this.topLeft = tl; this.botRight = br; this.botLeft = bl; this.idx = idx; this.predClass = predClass; } public boolean within(Point2D p){ Loading @@ -24,4 +25,5 @@ public class BoundingBox { Point2D botRight; Point2D botLeft; int idx; String predClass; }
src/main/java/object_detection/types/ObjectSet.java +26 −14 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ import java.util.*; public class ObjectSet { public static List<PointSet> objects; static int count = 0; public List<PointSet> objects; int count = 0; public ObjectSet(){ objects = new ArrayList<>(); } Loading @@ -20,7 +20,7 @@ public class ObjectSet { public int makeObject(Point...pp){ PointSet ps = new PointSet(); ps.addAll(pp); count++; this.count++; ps.updateReps(); // add pointset to object list Loading @@ -36,9 +36,9 @@ public class ObjectSet { * @param j : the new candidate object * @return true if objects are the same */ public static boolean compareObjects(int i, int j){ Point[] r1 = objects.get(i).getPoints(); Point[] r2 = objects.get(j).getPoints(); public boolean compareObjects(int i, int j){ Point[] r1 = this.objects.get(i).getPoints(); Point[] r2 = this.objects.get(j).getPoints(); // compare r1 and r2 Set<Point> s = new HashSet<>(); Loading Loading @@ -67,16 +67,16 @@ public class ObjectSet { public void combineObjects(int i, int j){ // add all points of j to i objects.get(i).addAll(objects.get(j).getPoints()); this.objects.get(i).addAll(this.objects.get(j).getPoints()); // redo reps of the object with new points objects.get(i).updateReps(); this.objects.get(i).updateReps(); // remove j objects.remove(j); this.objects.remove(j); // lower the count count--; this.count--; // eventually, push i to database } Loading Loading @@ -108,7 +108,7 @@ public class ObjectSet { while (scanner.hasNextLine()) { // Print the line of the file being processed System.out.println("Processing line " + lineNum++); //System.out.println("Processing line " + lineNum++); String[] line = scanner.nextLine().split(","); Point2D point2D = new Point2D(Float.parseFloat(line[0]), Float.parseFloat(line[1]), Integer.parseInt(line[2])); Loading @@ -135,8 +135,8 @@ public class ObjectSet { * */ public void updateObjectSet(List<ArrayList<Point>> points) { for (int i = 0; i < points.size(); i++) { Point[] pointArray = points.get(i).toArray(new Point[0]); for(ArrayList<Point> point : points) { Point[] pointArray = point.toArray(new Point[0]); int objIdx = makeObject(pointArray); // Compare the new object with all existing objects Loading @@ -153,15 +153,27 @@ public class ObjectSet { List<BoundingBox> boxes = new ArrayList<>(); Scanner scanner = new Scanner(bboxCsv); scanner.nextLine(); // Skip header int i = 0; while (scanner.hasNextLine()) { String[] line = scanner.nextLine().split(","); Point2D tr = new Point2D(Float.parseFloat(line[2]) + Float.parseFloat(line[4]), Float.parseFloat(line[3]), 0); Point2D tl = new Point2D(Float.parseFloat(line[2]), Float.parseFloat(line[3]), 0); Point2D br = new Point2D(Float.parseFloat(line[2]) + Float.parseFloat(line[4]), Float.parseFloat(line[3]) + Float.parseFloat(line[5]), 0); Point2D bl = new Point2D(Float.parseFloat(line[2]), Float.parseFloat(line[3]) + Float.parseFloat(line[5]), 0); boxes.add(new BoundingBox(tr, tl, br, bl, Integer.parseInt(line[0]))); boxes.add(new BoundingBox(tr, tl, br, bl, i, line[0])); i++; } scanner.close(); return boxes; } @Override public String toString(){ StringBuilder res = new StringBuilder("ObjectSet:"); for(PointSet p : this.objects){ res.append("\n\t - Object with ").append(p.pset.size()).append(" points"); } return res.toString(); } } No newline at end of file
src/main/java/top/BackendJava.java +60 −2 Original line number Diff line number Diff line Loading @@ -3,10 +3,19 @@ package top; import object_detection.ObjectDetector; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.config.annotation.CorsRegistry; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @SpringBootApplication public class BackendJava { Loading @@ -14,18 +23,67 @@ public class BackendJava { @Controller public static class BackendService { @RequestMapping("/hello") @ResponseBody public String hello(){ return "Hello There"; } @RequestMapping("/") public String index(){ return "html/index"; } @RequestMapping("/runProcess") @ResponseBody public boolean runProcess() throws FileNotFoundException { System.out.println(" ============> Starting process"); ObjectDetector.startProcess(); return true; } @RequestMapping("/getJSON") @ResponseBody public Map<String, ArrayList<ArrayList<Float>>> tempJson(){ Map<String, ArrayList<ArrayList<Float>>> temp = new HashMap<>(); ArrayList<Float> pp = new ArrayList<>(); pp.add(0.0f); pp.add(0.0f); pp.add(0.0f); ArrayList<ArrayList<Float>> obj = new ArrayList<>(); obj.add(pp); temp.put("obj1", obj); return temp; } @RequestMapping("/style/main.css") public String getStyle(){ return "style/main.css"; } @RequestMapping("/js/app.js") public String getApp(){ return "js/app.js"; } @RequestMapping("/js/pointCloud.js") public String getPC(){ return "js/pointCloud.js"; } } @Configuration @EnableWebMvc public class WebMvcConfig implements WebMvcConfigurer { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**").allowedOrigins("http://localhost:5555"); } } public static void main(String[] args) { Loading