OpenCV Tracker Element for Object Tracking (rebase)
NOTE: THIS IS A FOLLOW-UP of the work done by @123vivekr in the Google Summer of Code 2020.
What am I fixing/adding?
- Rebase against origin/master (use G_DEFINE_TYPE_WITH_CODE, GST_ELEMENT_REGISTER_DECLARE, GST_ELEMENT_REGISTER_DEFINE, GST_ELEMENT_REGISTER)
- Make it compatible with OpenCV 4.5.0 and >= 4.5.1 (Since OpenCV 4.5.1 the tracking API changed leaving place for a "legacy" API)
- Change the structure posted to the bus, to hold only UINT for x,y,width,height (in OpenCV legacy, it used double but now int, so keep a consistent API for the plugin whatever the OpenCV version is)
NOTE2: Fixup commits are supposed to be squashed.
I copy&paste the description of the original MR from Vivek:
What is it?
A tracker element based on OpenCV's long-term tracker algorithm implementation from here.
Sample pipeline: gst-launch-1.0 filesrc location=/home/vivek/Desktop/GStreamer_plugin/t.mp4 ! decodebin ! videoconvert ! cvtracker object-initial-x=175 object-initial-y=40 object-initial-width=300 object-initial-height=150 algorithm=1 ! videoconvert ! xvimagesink
Input/Parameters
The tracker
element takes input: a bounding box
to initiate the tracker with the object to be tracked and algorithm
for tracking. The first frame passing through the tracker element is taken as the initialization frame and the tracker element tracks the object for the subsequent frames.
Properties:
object-initial-x: bounding box's x co-ordinate
object-initial-y: bounding box's y co-ordinate
object-initial-width: bounding box's width
object-initial-height: bounding box's height
algorithm: choose from 7 different tracking algorithms [0-6]
Output
Writes the tracked object's coordinates (x, y, width and height) to the GstVideoRegionOfInterest metadata to the buffer for each frame. Also draws a rectangle around the object on the video stream.
Uses
This element can be used to track any object using OpenCV's tracking implementation. The ROI stored in the metadata can be used to attach "silly hats" or filters to the area.
OPENCV PATCH FIX: While compiling gst-plugins-bad
from the master branch, it left out the bgsegm.hpp
header and the patch here fixes that.