@@ -118,7 +118,7 @@ void CVObjectDetection::DetectObjects(const cv::Mat &frame, size_t frameId){
118118 // Runs the forward pass to get output of the output layers
119119 std::vector<cv::Mat> outs;
120120 net.forward (outs, getOutputsNames (net));
121-
121+
122122 // Remove the bounding boxes with low confidence
123123 postprocess (frame.size (), outs, frameId);
124124
@@ -239,8 +239,8 @@ void CVObjectDetection::postprocess(const cv::Size &frameDims, const std::vector
239239 cv::Rect_<float > normalized_box;
240240 normalized_box.x = (box.x )/(float )frameDims.width ;
241241 normalized_box.y = (box.y )/(float )frameDims.height ;
242- normalized_box.width = (box.x +box. width )/(float )frameDims.width ;
243- normalized_box.height = (box.y +box. height )/(float )frameDims.height ;
242+ normalized_box.width = (box.width )/(float )frameDims.width ;
243+ normalized_box.height = (box.height )/(float )frameDims.height ;
244244 normalized_boxes.push_back (normalized_box);
245245 }
246246
@@ -300,7 +300,7 @@ CVDetectionData CVObjectDetection::GetDetectionData(size_t frameId){
300300 }
301301}
302302
303- bool CVObjectDetection::SaveTrackedData (){
303+ bool CVObjectDetection::SaveObjDetectedData (){
304304 // Create tracker message
305305 libopenshotobjdetect::ObjDetect objMessage;
306306
@@ -346,10 +346,10 @@ void CVObjectDetection::AddFrameDataToProto(libopenshotobjdetect::Frame* pbFrame
346346 libopenshotobjdetect::Frame_Box* box = pbFrameData->add_bounding_box ();
347347
348348 // Save bounding box data
349- box->set_x1 (dData.boxes .at (i).x );
350- box->set_y1 (dData.boxes .at (i).y );
351- box->set_x2 (dData. boxes . at (i). x + dData.boxes .at (i).width );
352- box->set_y2 (dData. boxes . at (i). y + dData.boxes .at (i).height );
349+ box->set_x (dData.boxes .at (i).x );
350+ box->set_y (dData.boxes .at (i).y );
351+ box->set_w ( dData.boxes .at (i).width );
352+ box->set_h ( dData.boxes .at (i).height );
353353 box->set_classid (dData.classIds .at (i));
354354 box->set_confidence (dData.confidences .at (i));
355355
@@ -394,3 +394,77 @@ void CVObjectDetection::SetJsonValue(const Json::Value root) {
394394 classesFile = (root[" classes_file" ].asString ());
395395 }
396396}
397+
398+
399+
400+ /*
401+ ||||||||||||||||||||||||||||||||||||||||||||||||||
402+ ONLY FOR MAKE TEST
403+ ||||||||||||||||||||||||||||||||||||||||||||||||||
404+ */
405+
406+
407+
408+ // Load protobuf data file
409+ bool CVObjectDetection::_LoadObjDetectdData (){
410+ // Create tracker message
411+ libopenshotobjdetect::ObjDetect objMessage;
412+
413+ {
414+ // Read the existing tracker message.
415+ fstream input (protobuf_data_path, ios::in | ios::binary);
416+ if (!objMessage.ParseFromIstream (&input)) {
417+ cerr << " Failed to parse protobuf message." << endl;
418+ return false ;
419+ }
420+ }
421+
422+ // Make sure classNames and detectionsData are empty
423+ classNames.clear (); detectionsData.clear ();
424+
425+ // Get all classes names and assign a color to them
426+ for (int i = 0 ; i < objMessage.classnames_size (); i++){
427+ classNames.push_back (objMessage.classnames (i));
428+ }
429+
430+ // Iterate over all frames of the saved message
431+ for (size_t i = 0 ; i < objMessage.frame_size (); i++) {
432+ // Create protobuf message reader
433+ const libopenshotobjdetect::Frame& pbFrameData = objMessage.frame (i);
434+
435+ // Get frame Id
436+ size_t id = pbFrameData.id ();
437+
438+ // Load bounding box data
439+ const google::protobuf::RepeatedPtrField<libopenshotobjdetect::Frame_Box > &pBox = pbFrameData.bounding_box ();
440+
441+ // Construct data vectors related to detections in the current frame
442+ std::vector<int > classIds; std::vector<float > confidences; std::vector<cv::Rect_<float >> boxes;
443+
444+ for (int i = 0 ; i < pbFrameData.bounding_box_size (); i++){
445+ // Get bounding box coordinates
446+ float x = pBox.Get (i).x (); float y = pBox.Get (i).y ();
447+ float w = pBox.Get (i).w (); float h = pBox.Get (i).h ();
448+ // Create OpenCV rectangle with the bouding box info
449+ cv::Rect_<float > box (x, y, w, h);
450+
451+ // Get class Id (which will be assign to a class name) and prediction confidence
452+ int classId = pBox.Get (i).classid (); float confidence = pBox.Get (i).confidence ();
453+
454+ // Push back data into vectors
455+ boxes.push_back (box); classIds.push_back (classId); confidences.push_back (confidence);
456+ }
457+
458+ // Assign data to object detector map
459+ detectionsData[id] = CVDetectionData (classIds, confidences, boxes, id);
460+ }
461+
462+ // Show the time stamp from the last update in object detector data file
463+ if (objMessage.has_last_updated ())
464+ cout << " Loaded Data. Saved Time Stamp: " << TimeUtil::ToString (objMessage.last_updated ()) << endl;
465+
466+ // Delete all global objects allocated by libprotobuf.
467+ google::protobuf::ShutdownProtobufLibrary ();
468+
469+ return true ;
470+ }
0 commit comments