MCPcopy Create free account
hub / github.com/OpenShot/libopenshot / trackClip

Method trackClip

src/CVTracker.cpp:70–124  ·  view source on GitHub ↗

Track object in the whole clip or in a given interval

Source from the content-addressed store, hash-verified

68
69// Track object in the whole clip or in a given interval
70void CVTracker::trackClip(openshot::Clip& video,
71 size_t _start,
72 size_t _end,
73 bool process_interval)
74{
75 video.Open();
76 if (!json_interval) {
77 start = _start; end = _end;
78 if (!process_interval || end <= 1 || end - start == 0) {
79 start = int(video.Start() * video.Reader()->info.fps.ToFloat()) + 1;
80 end = int(video.End() * video.Reader()->info.fps.ToFloat()) + 1;
81 }
82 } else {
83 start = int(start + video.Start() * video.Reader()->info.fps.ToFloat()) + 1;
84 end = int(video.End() * video.Reader()->info.fps.ToFloat()) + 1;
85 }
86 if (error) return;
87 processingController->SetError(false, "");
88
89 bool trackerInit = false;
90 lostCount = 0; // reset lost counter once at the start
91
92 for (size_t frame = start; frame <= end; ++frame) {
93 if (processingController->ShouldStop()) return;
94
95 auto f = video.GetFrame(frame);
96 cv::Mat img = f->GetImageCV();
97
98 if (frame == start) {
99 bbox = cv::Rect2d(
100 int(bbox.x * img.cols),
101 int(bbox.y * img.rows),
102 int(bbox.width * img.cols),
103 int(bbox.height * img.rows)
104 );
105 }
106
107 if (!trackerInit) {
108 initTracker(img, frame);
109 trackerInit = true;
110 lostCount = 0;
111 }
112 else {
113 // trackFrame now manages lostCount and will re-init internally
114 trackFrame(img, frame);
115
116 // record whatever bbox we have now
117 FrameData fd = GetTrackedData(frame);
118 }
119
120 processingController->SetProgress(
121 uint(100 * (frame - start) / (end - start))
122 );
123 }
124}
125
126// Initialize the tracker
127bool CVTracker::initTracker(cv::Mat &frame, size_t frameId)

Callers 2

CVTracker.cppFile · 0.45
mainFunction · 0.45

Calls 10

ToFloatMethod · 0.80
SetErrorMethod · 0.80
ShouldStopMethod · 0.80
GetImageCVMethod · 0.80
SetProgressMethod · 0.80
OpenMethod · 0.45
StartMethod · 0.45
ReaderMethod · 0.45
EndMethod · 0.45
GetFrameMethod · 0.45

Tested by

no test coverage detected