* @brief This class runs trought a clip to detect objects and returns the bounding boxes and its properties. * * Object detection is performed using YoloV3 model with OpenCV DNN module */
| 62 | * Object detection is performed using YoloV3 model with OpenCV DNN module |
| 63 | */ |
| 64 | class CVObjectDetection{ |
| 65 | |
| 66 | private: |
| 67 | |
| 68 | cv::dnn::Net net; |
| 69 | std::vector<std::string> classNames; |
| 70 | float confThreshold, nmsThreshold; |
| 71 | |
| 72 | std::string classesFile; |
| 73 | std::string modelConfiguration; |
| 74 | std::string modelWeights; |
| 75 | std::string processingDevice; |
| 76 | std::string protobuf_data_path; |
| 77 | |
| 78 | SortTracker sort; |
| 79 | |
| 80 | uint progress; |
| 81 | |
| 82 | size_t start; |
| 83 | size_t end; |
| 84 | |
| 85 | bool error = false; |
| 86 | |
| 87 | /// Will handle a Thread safely comutication between ClipProcessingJobs and the processing effect classes |
| 88 | ProcessingController *processingController; |
| 89 | |
| 90 | void setProcessingDevice(); |
| 91 | |
| 92 | // Detect onbects on a single frame |
| 93 | void DetectObjects(const cv::Mat &frame, size_t frame_number); |
| 94 | |
| 95 | bool iou(cv::Rect pred_box, cv::Rect sort_box); |
| 96 | |
| 97 | // Remove the bounding boxes with low confidence using non-maxima suppression |
| 98 | void postprocess(const cv::Size &frameDims, const std::vector<cv::Mat>& out, size_t frame_number); |
| 99 | |
| 100 | // Get the names of the output layers |
| 101 | std::vector<cv::String> getOutputsNames(const cv::dnn::Net& net); |
| 102 | |
| 103 | public: |
| 104 | |
| 105 | std::map<size_t, CVDetectionData> detectionsData; |
| 106 | |
| 107 | CVObjectDetection(std::string processInfoJson, ProcessingController &processingController); |
| 108 | |
| 109 | // Iterate over a clip object and run inference for each video frame |
| 110 | void detectObjectsClip(openshot::Clip &video, size_t start=0, size_t end=0, bool process_interval=false); |
| 111 | |
| 112 | CVDetectionData GetDetectionData(size_t frameId); |
| 113 | |
| 114 | /// Protobuf Save and Load methods |
| 115 | // Save protobuf file |
| 116 | bool SaveObjDetectedData(); |
| 117 | // Add frame object detection data into protobuf message. |
| 118 | void AddFrameDataToProto(pb_objdetect::Frame* pbFrameData, CVDetectionData& dData); |
| 119 | |
| 120 | // Get and Set JSON methods |
| 121 | void SetJson(const std::string value); ///< Load JSON string into this object |
nothing calls this directly
no outgoing calls
no test coverage detected