Commit e09ba49e authored by Rohan  Kumar's avatar Rohan Kumar
Browse files

"adding entry into system"

parent 8470f668
Loading
Loading
Loading
Loading
+75 −0
Original line number Diff line number Diff line
import database.DatabaseUpdater;
import object_detection.ObjectDetector;
import object_detection.types.ObjectSet;

public class EntryPoint {

    public static void main(String args[]){
        /*
            - start GUI server
            - get keyframes and featurepoints
            - get objects from keyframes
            - start object detection
            - finish object detection and update database
            - ping GUI server
            - GUI server pulls information and displays point cloud to user
         */

        // #################################################
        // 1) Starting the GUI Server

        // nothing yet
        int port = 9999;

        System.out.println("1) GUI Server has been started on https://localhost:"+ port + ".");

        // #################################################
        // 2) Getting keyframes and feature points

        // for now, we can just set paths to the directories that hold keyframes and featurepoint CSVs
        String feature_csv_path = "/src/main/java/vslam/KeyFramePoints/";
        String keyframe_png_path = "/src/main/java/vslam/KeyFrames/";

        System.out.println("2) Keyframe and Features have been collected.");

        // #################################################
        // 3) Get objects from keyframes

        // for now, we can just set paths to the directories holding bounded box information
        String bounding_info_path = "/src/main/java/vslam/BoundedInfo/";

        System.out.println("3) Objects have been detected via YOLOv4.");

        // #################################################
        // 4) Get objects from keyframes

        // start the object detection module, output will be the objects pushed to the cloud, return the completed object set
        ObjectSet os = ObjectDetector.process(bounding_info_path, feature_csv_path);

        System.out.println("4) ObjectSet has been constructed.");


        // #################################################
        // 5) Update database with objectset

        // perform the update of the database using the video elements
        boolean updateRes = DatabaseUpdater.updateDB(os);
        if(!updateRes){
            System.err.println("ERROR: database update failed");
        }

        System.out.println("5) Database has been constructed.");

        // #################################################
        // 6) Ping GUI server with completion status, so server can start displaying ObjectSet

        // nothing yet

        System.out.println("5) GUI will start reflecting object tracking.");


        /*
        At this point, everything is done, but there should be the option to rerun this system with another video possibly?
         */
    }
}
+15 −0
Original line number Diff line number Diff line

# Entry into System

Things that are true:
1. A student should be able to build the system, then press run, then open a localhost and see the video and the point cloud of each object
2. A student should also be able to choose between different object and get information (need interactive display)
3. The entry needs to do the entire workflow
    - get keyframes and featurepoints
    - get objects from keyframes
    - start object detection
    - finish object detection and update database
    - ping GUI server
    - GUI server pulls information and displays point cloud to user

TODO: function to process each frame within the ObjectSet
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
package database;

import object_detection.types.ObjectSet;

public class DatabaseUpdater {

    public static boolean updateDB(ObjectSet objSet){
        return true;
    }
}
+0 −47
Original line number Diff line number Diff line
package object_detection;

import java.net.ServerSocket;
import java.net.Socket;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.FileWriter; // file writing support
import java.nio.charset.StandardCharsets;

public class ObjectDetectionServer {

    public static void main(String[] args) throws Exception {
        final ServerSocket server = new ServerSocket(80); // port 80
        System.out.println("Listening for connection on port 80...");
        while (true) {
            try (Socket clientSocket = server.accept();
                 FileWriter fw = new FileWriter("blank.txt", true); // open file in append mode
            ) {
                InputStreamReader isr = new InputStreamReader(clientSocket.getInputStream());
                BufferedReader reader = new BufferedReader(isr);
                String line = reader.readLine();
                while (!line.isEmpty()) {
                    System.out.println(line);
                    fw.write(line + "\n"); // write line to file
                    line = reader.readLine();
                }
                fw.flush(); // ensure all data is written to file

                // at this point, run ObjectDetector
                // ObjectDetector.run(fw.toString());

                // HTTP response
                String httpResponse = "HTTP/1.1 200 OK\r\n\r\n" + "<html><body><h1>Hello, World!</h1></body></html>";

                // dispatching HTTP response to the client
                OutputStream outputStream = clientSocket.getOutputStream();
                outputStream.write(httpResponse.getBytes(StandardCharsets.UTF_8));
                outputStream.flush();
            } catch (IOException e) {
                e.printStackTrace(); // handle exceptions appropriately
            }
        }
    }
}
+31 −47
Original line number Diff line number Diff line
@@ -6,67 +6,51 @@ import object_detection.types.Point;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.Scanner;

public class ObjectDetector {

    static ObjectSet os;

    public static void run() throws IOException {
        System.out.println("Running object detection:");
        ObjectDetector.main(null);
    }

    public static void processFrame(String framename) throws FileNotFoundException {
        // 1) we get the feature points, store as an
        Scanner sc = new Scanner(new File(framename));
        sc.useDelimiter("\n");

        // 2) we map each point to an object using the bounding boxes
        double[][] box1 = {{1, 2}, {3, 4}};
        System.out.println(Arrays.deepToString(box1));

        // 3)
    public static ObjectSet process(String bbox_dir_pth, String feat_dir_pth){

        File[] feat_CSVs = getDirFiles(feat_dir_pth);
        File[] bbox_CSVs = getDirFiles(bbox_dir_pth);

        // 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");
        }

    public static void main(String[] args) throws IOException {

        /* infinite loop of running system:
        1) Get new info from system
        2) Update UnionFind
        3) Push new update to database if necessary
         */
        // initialize ObjectSet
        ObjectSet objSet = new ObjectSet();

        // create objectset
        os = new ObjectSet();
        // for each keyframe, process bounding box csv and feature csv
        int NUMKF = feat_CSVs.length;

        processFrame("src/main/java/vslam/KeyFramePoints/KeyFramePoints_0003.csv");
        for(int i = 0; i < NUMKF; i++){
            objSet.processFrame(feat_CSVs[i], bbox_CSVs[i]);
        }

        // Add two test sets
        int o1 = os.makeObject(
            new Point(0,10,0),
            new Point(0,0,0),
            new Point(10, 0, 0),
            new Point(10, 10, 0)
        );
        // return the completely built object set
        return objSet;
    }

        int o2 = os.makeObject(
            new Point(5,5,0),
            new Point(5,15,0),
            new Point(15, 5, 0),
            new Point(15, 15, 0)
        );
    public static File[] getDirFiles(String dir_pth){
        File[] f_arr;
        // get the csv files of each frame
        try {
            f_arr = new File(dir_pth).listFiles();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        System.out.println("Added two objects of 4 points to ObjectSet");
        System.out.println("Indices: " + o1 + ", " + o2);
        // test out compare
        boolean same = ObjectSet.compareObjects(o1, o2);
        if(same){
            os.combineObjects(o1, o2);
            System.out.println("Combining object 1 and 2");
        // some error checking
        if(f_arr == null || f_arr.length == 0){
            System.err.println("ERROR: no feature csvs found at given path");
        }

        return f_arr;
    }

}
Loading