Skip to content
...@@ -6,11 +6,8 @@ import java.util.*; ...@@ -6,11 +6,8 @@ import java.util.*;
public class PointSet { public class PointSet {
static final int NUM_REPS = 10;
Set<Point> pset; Set<Point> pset;
Point[] reps; String predName;
Point centroid;
final int IDX; final int IDX;
...@@ -18,14 +15,13 @@ public class PointSet { ...@@ -18,14 +15,13 @@ public class PointSet {
* *
* @param pp : the points that this PointSet will contain * @param pp : the points that this PointSet will contain
*/ */
public PointSet(int id, Point ...pp){ public PointSet(int id, String predName, Point ...pp){
pset = new HashSet<>(); this.pset = new HashSet<>();
// add every point blankly to pointset // add every point blankly to pointset
pset.addAll(Arrays.asList(pp)); this.pset.addAll(Arrays.asList(pp));
centroid = new Point(0,0,0); this.IDX = id;
reps = new Point[NUM_REPS]; this.predName = predName;
IDX = id;
} }
public void addPoint(Point p){ public void addPoint(Point p){
...@@ -40,8 +36,8 @@ public class PointSet { ...@@ -40,8 +36,8 @@ public class PointSet {
pset.addAll(p); pset.addAll(p);
} }
public Point[] getSetReps(){ public String getPred(){
return this.reps; return this.predName;
} }
/* /*
...@@ -58,24 +54,6 @@ public class PointSet { ...@@ -58,24 +54,6 @@ public class PointSet {
return res; return res;
} }
/**
* This method is called on a specific Point, and updates the Point via
* some disjoint sets' method.
*/
public void updateReps(){
// get first NUM_REPS from pset for now, will make more efficient later
Iterator<Point> iter = this.pset.iterator();
for(int i = 0; i < NUM_REPS; i++){
// early exit if we have less than NUM_REPS points in the current object
if(i == this.pset.size()) {
return;
}
reps[i] = iter.next();
}
}
public int getIDX() { public int getIDX() {
return this.IDX; return this.IDX;
} }
......
...@@ -36,24 +36,11 @@ public class BackendJava { ...@@ -36,24 +36,11 @@ public class BackendJava {
private final MongoDBInteraction dbInteraction = new MongoDBInteraction(); private final MongoDBInteraction dbInteraction = new MongoDBInteraction();
private final Gson gson = new GsonBuilder().create(); private final Gson gson = new GsonBuilder().create();
@GetMapping("/{index}")
public ResponseEntity<String> getObjectSet(@PathVariable int index) {
try {
ObjectSet objectSet = dbInteraction.retrieveLatestObjectSet();
if (objectSet != null) {
return ResponseEntity.ok(gson.toJson(objectSet));
} else {
return ResponseEntity.notFound().build();
}
} catch (NumberFormatException e) {
return ResponseEntity.badRequest().body("{\"error\":\"Invalid index format\"}");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("{\"error\":\"Internal Server Error: " + e.getMessage() + "\"}");
}
}
@GetMapping("/getObjects") @GetMapping("/getObjects")
public ResponseEntity<String> getObjects() { public ResponseEntity<String> getObjects(@RequestParam String dataset) throws CsvValidationException, IOException {
System.out.println("==========================");
ObjectDetector.startProcess(dataset);
System.out.println("==========================");
try { try {
ObjectSet objectSet = dbInteraction.retrieveLatestObjectSet(); ObjectSet objectSet = dbInteraction.retrieveLatestObjectSet();
if (objectSet != null && objectSet.objects != null && !objectSet.objects.isEmpty()) { if (objectSet != null && objectSet.objects != null && !objectSet.objects.isEmpty()) {
...@@ -61,7 +48,7 @@ public class BackendJava { ...@@ -61,7 +48,7 @@ public class BackendJava {
for (PointSet ps : objectSet.objects) { for (PointSet ps : objectSet.objects) {
Map<String, Object> objData = new HashMap<>(); Map<String, Object> objData = new HashMap<>();
objData.put("id", ps.getIDX()); objData.put("id", ps.getIDX());
objData.put("predName", "Some Pred Name"); // Placeholder, adjust based on your application's data objData.put("predName", ps.getPred()); // Placeholder, adjust based on your application's data
List<Map<String, Object>> pointsList = new ArrayList<>(); List<Map<String, Object>> pointsList = new ArrayList<>();
for (Point p : ps.getPoints()) { for (Point p : ps.getPoints()) {
...@@ -87,19 +74,6 @@ public class BackendJava { ...@@ -87,19 +74,6 @@ public class BackendJava {
return ResponseEntity.internalServerError().body("{\"error\":\"Failed to retrieve all objects: " + e.getMessage() + "\"}"); return ResponseEntity.internalServerError().body("{\"error\":\"Failed to retrieve all objects: " + e.getMessage() + "\"}");
} }
} }
@GetMapping("/getPointCloud")
public ResponseEntity<String> getPoints() {
try {
Map<String, List<String>> result = new HashMap<>();
result.put("yes", Collections.singletonList("true"));
return ResponseEntity.ok(gson.toJson(result));
} catch (Exception e){
return ResponseEntity.internalServerError().body("{\"error\":\"Failed to retrieve all objects: " + e.getMessage() + "\"}");
}
}
} }
@Controller @Controller
...@@ -108,29 +82,23 @@ public class BackendJava { ...@@ -108,29 +82,23 @@ public class BackendJava {
private final MongoDBInteraction dbInteraction = new MongoDBInteraction(); private final MongoDBInteraction dbInteraction = new MongoDBInteraction();
private final Gson gson = new GsonBuilder().create(); private final Gson gson = new GsonBuilder().create();
@RequestMapping("/hello")
@ResponseBody
public String hello() {
return "Hello There";
}
@RequestMapping("/") @RequestMapping("/")
public String index() { public String index() {
return "html/index"; return "html/index";
} }
@RequestMapping("/runProcess") // @RequestMapping("/runProcess")
@ResponseBody // @ResponseBody
public boolean runProcess() throws IOException, CsvValidationException { // public boolean runProcess() throws IOException, CsvValidationException {
System.out.println(" ============> Starting process"); // System.out.println(" ============> Starting process");
ObjectDetector.startProcess(); // ObjectDetector.startProcess();
return true; // return true;
} // }
@RequestMapping("/getJSON") @RequestMapping("/getJSON")
@ResponseBody @ResponseBody
public ResponseEntity<String> tempJson(@RequestParam String dataset) throws CsvValidationException, IOException { public ResponseEntity<String> tempJson(@RequestParam String dataset) throws CsvValidationException, IOException {
ObjectDetector.startProcess(); ObjectDetector.startProcess(dataset);
try { try {
ObjectSet latestObjectSet = dbInteraction.retrieveLatestObjectSet(); ObjectSet latestObjectSet = dbInteraction.retrieveLatestObjectSet();
...@@ -154,16 +122,6 @@ public class BackendJava { ...@@ -154,16 +122,6 @@ public class BackendJava {
return "style/main.css"; 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";
}
@RequestMapping("/js/buildPC.js") @RequestMapping("/js/buildPC.js")
public String getBuild() { public String getBuild() {
return "js/buildPC.js"; return "js/buildPC.js";
......
...@@ -28,19 +28,19 @@ public class Vid2Frames { ...@@ -28,19 +28,19 @@ public class Vid2Frames {
Java2DFrameConverter converter = new Java2DFrameConverter(); Java2DFrameConverter converter = new Java2DFrameConverter();
Frame frame; Frame frame;
int frameNumber = 0; // Overall frame number int frameNumber = 0;
int savedFrameNumber = 0; // Number of frames actually saved
// Frame rate of the video file // Frame rate of the video file
double frameRate = frameGrabber.getFrameRate(); double frameRate = frameGrabber.getFrameRate();
// Interval to capture the frame (e.g., every 0.2 seconds for 5 frames per second) // Interval to capture the frame (every 0.2 seconds for 5 frames per second)
int frameInterval = (int) Math.round(frameRate / 15); int frameInterval = (int) Math.round(frameRate / 5);
int savedFrameNumber = 0; // Number of frames actually saved
while ((frame = frameGrabber.grabFrame()) != null) { while ((frame = frameGrabber.grabFrame()) != null) {
if (frame.image != null) { if (frame.image != null) {
if (frameNumber % frameInterval == 0) { if (frameNumber % frameInterval == 0) {
BufferedImage bi = converter.convert(frame); BufferedImage bi = converter.convert(frame);
String path = String.format("%s/frame_%d.png", outputDirPath, savedFrameNumber); String path = String.format("%s/frame_%d.png", outputDirPath, frameNumber);
ImageIO.write(bi, "png", new File(path)); ImageIO.write(bi, "png", new File(path));
System.out.println("Saved: " + path); System.out.println("Saved: " + path);
savedFrameNumber++; savedFrameNumber++;
......
## Notes
Notes from Rohan:
- could use MATLAB coder to move MATLAB code to C/C++ code
- not sure if this is possible for Java code as well
- Prof. mentioned wanting Java code s.t. other students can read and critique codebase
- use MATLAB functions, create new MATLAB objects for data structures / database system
- dataset used by MATLAB example: https://cvg.cit.tum.de/data/datasets/rgbd-dataset
#### Performing VSLAM using online dataset
- Open up MATLAB console
- Install necessary Mathworks Library: Vision, Visual SLAM (users will be queried to download necessary packages)
- In MATLAB console, set imagesPath to 'rgbd_dataset_freiburg3_long_office_household/rgb'
- Run the vslam_implementation.m script with the imagesPath as input
- Use output of worldPointSet for figuring out which key features belong to which objects