Skip to content
......@@ -6,11 +6,8 @@ import java.util.*;
public class PointSet {
static final int NUM_REPS = 10;
Set<Point> pset;
Point[] reps;
Point centroid;
String predName;
final int IDX;
......@@ -18,14 +15,13 @@ public class PointSet {
*
* @param pp : the points that this PointSet will contain
*/
public PointSet(int id, Point ...pp){
pset = new HashSet<>();
public PointSet(int id, String predName, Point ...pp){
this.pset = new HashSet<>();
// add every point blankly to pointset
pset.addAll(Arrays.asList(pp));
centroid = new Point(0,0,0);
reps = new Point[NUM_REPS];
IDX = id;
this.pset.addAll(Arrays.asList(pp));
this.IDX = id;
this.predName = predName;
}
public void addPoint(Point p){
......@@ -40,8 +36,8 @@ public class PointSet {
pset.addAll(p);
}
public Point[] getSetReps(){
return this.reps;
public String getPred(){
return this.predName;
}
/*
......@@ -58,24 +54,6 @@ public class PointSet {
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() {
return this.IDX;
}
......
......@@ -36,24 +36,11 @@ public class BackendJava {
private final MongoDBInteraction dbInteraction = new MongoDBInteraction();
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")
public ResponseEntity<String> getObjects() {
public ResponseEntity<String> getObjects(@RequestParam String dataset) throws CsvValidationException, IOException {
System.out.println("==========================");
ObjectDetector.startProcess(dataset);
System.out.println("==========================");
try {
ObjectSet objectSet = dbInteraction.retrieveLatestObjectSet();
if (objectSet != null && objectSet.objects != null && !objectSet.objects.isEmpty()) {
......@@ -61,7 +48,7 @@ public class BackendJava {
for (PointSet ps : objectSet.objects) {
Map<String, Object> objData = new HashMap<>();
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<>();
for (Point p : ps.getPoints()) {
......@@ -87,19 +74,6 @@ public class BackendJava {
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
......@@ -108,29 +82,23 @@ public class BackendJava {
private final MongoDBInteraction dbInteraction = new MongoDBInteraction();
private final Gson gson = new GsonBuilder().create();
@RequestMapping("/hello")
@ResponseBody
public String hello() {
return "Hello There";
}
@RequestMapping("/")
public String index() {
return "html/index";
}
@RequestMapping("/runProcess")
@ResponseBody
public boolean runProcess() throws IOException, CsvValidationException {
System.out.println(" ============> Starting process");
ObjectDetector.startProcess();
return true;
}
// @RequestMapping("/runProcess")
// @ResponseBody
// public boolean runProcess() throws IOException, CsvValidationException {
// System.out.println(" ============> Starting process");
// ObjectDetector.startProcess();
// return true;
// }
@RequestMapping("/getJSON")
@ResponseBody
public ResponseEntity<String> tempJson(@RequestParam String dataset) throws CsvValidationException, IOException {
ObjectDetector.startProcess();
ObjectDetector.startProcess(dataset);
try {
ObjectSet latestObjectSet = dbInteraction.retrieveLatestObjectSet();
......@@ -154,16 +122,6 @@ public class BackendJava {
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")
public String getBuild() {
return "js/buildPC.js";
......
......@@ -28,19 +28,19 @@ public class Vid2Frames {
Java2DFrameConverter converter = new Java2DFrameConverter();
Frame frame;
int frameNumber = 0; // Overall frame number
int savedFrameNumber = 0; // Number of frames actually saved
int frameNumber = 0;
// Frame rate of the video file
double frameRate = frameGrabber.getFrameRate();
// Interval to capture the frame (e.g., every 0.2 seconds for 5 frames per second)
int frameInterval = (int) Math.round(frameRate / 15);
// Interval to capture the frame (every 0.2 seconds for 5 frames per second)
int frameInterval = (int) Math.round(frameRate / 5);
int savedFrameNumber = 0; // Number of frames actually saved
while ((frame = frameGrabber.grabFrame()) != null) {
if (frame.image != null) {
if (frameNumber % frameInterval == 0) {
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));
System.out.println("Saved: " + path);
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