OpenShot Library | libopenshot 0.3.3
Loading...
Searching...
No Matches
CVObjectDetection.h
Go to the documentation of this file.
1
10// Copyright (c) 2008-2019 OpenShot Studios, LLC
11//
12// SPDX-License-Identifier: LGPL-3.0-or-later
13
14#pragma once
15
16#define int64 opencv_broken_int
17#define uint64 opencv_broken_uint
18#include <opencv2/dnn.hpp>
19#include <opencv2/opencv.hpp>
20#include <opencv2/core.hpp>
21#undef uint64
22#undef int64
23#include "Json.h"
25#include "Clip.h"
26
27#include "sort_filter/sort.hpp"
28
29// Forward decl
30namespace pb_objdetect {
31 class Frame;
32}
33
34namespace openshot
35{
36 // Stores the detected object bounding boxes and its properties.
40 std::vector<int> _classIds,
41 std::vector<float> _confidences,
42 std::vector<cv::Rect_<float>> _boxes,
43 size_t _frameId,
44 std::vector<int> _objectIds)
45 {
46 classIds = _classIds;
47 confidences = _confidences;
48 boxes = _boxes;
49 frameId = _frameId;
50 objectIds = _objectIds;
51 }
52 size_t frameId;
53 std::vector<int> classIds;
54 std::vector<float> confidences;
55 std::vector<cv::Rect_<float>> boxes;
56 std::vector<int> objectIds;
57 };
58
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
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
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);
122 void SetJsonValue(const Json::Value root);
123
124 // Load protobuf file (ONLY FOR MAKE TEST)
125 bool _LoadObjDetectdData();
126 };
127
128}
Header file for Clip class.
Header file for JSON class.
This is a message class for thread safe comunication between ClipProcessingJobs and OpenCV classes.
This class runs trought a clip to detect objects and returns the bounding boxes and its properties.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
void detectObjectsClip(openshot::Clip &video, size_t start=0, size_t end=0, bool process_interval=false)
void AddFrameDataToProto(pb_objdetect::Frame *pbFrameData, CVDetectionData &dData)
CVDetectionData GetDetectionData(size_t frameId)
std::map< size_t, CVDetectionData > detectionsData
void SetJson(const std::string value)
Load JSON string into this object.
bool SaveObjDetectedData()
Protobuf Save and Load methods.
This class represents a clip (used to arrange readers on the timeline)
Definition Clip.h:89
This namespace is the default namespace for all code in the openshot library.
Definition Compressor.h:29
std::vector< int > objectIds
std::vector< cv::Rect_< float > > boxes
std::vector< int > classIds
CVDetectionData(std::vector< int > _classIds, std::vector< float > _confidences, std::vector< cv::Rect_< float > > _boxes, size_t _frameId, std::vector< int > _objectIds)
std::vector< float > confidences