@@ -43,6 +43,15 @@ Robot::Robot(Eigen::Matrix4d transformation_matrix) {
4343 * @param frame : Current Camera frame
4444 * @return Mat : processed camera frame, ready for detection
4545 */
46+ Net Robot::loadNetwork (string model_config, string model_weights) {
47+ // Load the network
48+ Net net = cv::dnn::readNetFromDarknet (model_config,
49+ model_weights);
50+ // Define use of specific computation backend
51+ net.setPreferableBackend (cv::dnn::DNN_TARGET_CPU );
52+ return net;
53+ }
54+
4655Mat Robot::prepFrame (Mat frame) {
4756 Mat blob_frame;
4857 blob_frame = cv::dnn::blobFromImage (frame, 1 /255.0 ,
@@ -88,36 +97,15 @@ vector<double> Robot::transformToRobotFrame(vector<Rect> bbox_coords) {
8897/* *
8998 * @brief detectHumans : Main method for human detection
9099 */
91- int Robot::detectHumans () {
100+ int Robot::detectHumans (Mat frame, Net net ) {
92101 HumanDetector hooman;
93- // Load the network
94- Net net = cv::dnn::readNetFromDarknet (path_to_model_congfiguration,
95- path_to_model_weights);
96- // Define use of specific computation backend
97- net.setPreferableBackend (cv::dnn::DNN_TARGET_CPU );
98- // Start video capture by activating camera
99- cv::VideoCapture cap (0 );
100- // Test if camera is actually active or not
101- if (cap.isOpened () == false ) {
102- std::cout << " Cannot open the video camera" << std::endl;
103- // Wait for any key press
104- std::cin.get ();
105- return -1 ;
106- }
107- // Create name for window frame
108- static const string window_name = " Human Object Detector & Tracker" ;
109- cv::namedWindow (window_name, cv::WINDOW_NORMAL );
110- // Initialize the frame that will be analysed
111- Mat frame, blob;
112- // Initialize variable that stores data recieved from detection model
113- vector<Mat> outs;
114102 vector<Rect> bbox;
115- // Create a loop for capturing frames in real time
116- while ( true ) {
117- // Take one frame from live feed for processing
118- cap >> frame ;
119- // Create a pre-processed frame for detection
120- blob = prepFrame (frame);
103+ vector<Mat> outs;
104+ vector<Rect> human_locations;
105+ bbox. clear ();
106+ outs. clear () ;
107+ human_locations. clear ();
108+ Mat blob = prepFrame (frame);
121109 // Run the detection model and get the data for detected humans
122110 outs = hooman.detection (net, blob);
123111 // Apply confidence and NMS thresholding
@@ -126,15 +114,6 @@ int Robot::detectHumans() {
126114 // Testing out transformation matrix
127115 vector<Rect> dummy = {Rect (10 , 20 , 30 , 1 )};
128116 transformToRobotFrame (dummy);
129- // Show the frame captured on screen
130- cv::imshow (window_name, frame);
131- // To get continuous live video until ctrl+C is pressed
132- if (cv::waitKey (1 ) == 27 ) {
133- break ;
134- }
135- }
136- // Deactivate camera and close window
137- cap.release ();
138- cv::destroyAllWindows ();
117+
139118 return 0 ;
140- }
119+ }
0 commit comments