• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * GStreamer
3  * Copyright (C) 2020 Vivek R <123vivekr@gmail.com>
4  * Copyright (C) 2021 Cesar Fabian Orccon Chipana <cfoch.fabian@gmail.com>
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  *
24  * Alternatively, the contents of this file may be used under the
25  * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
26  * which case the following provisions apply instead of the ones
27  * mentioned above:
28  *
29  * This library is free software; you can redistribute it and/or
30  * modify it under the terms of the GNU Library General Public
31  * License as published by the Free Software Foundation; either
32  * version 2 of the License, or (at your option) any later version.
33  *
34  * This library is distributed in the hope that it will be useful,
35  * but WITHOUT ANY WARRANTY; without even the implied warranty of
36  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
37  * Library General Public License for more details.
38  *
39  * You should have received a copy of the GNU Library General Public
40  * License along with this library; if not, write to the
41  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
42  * Boston, MA 02110-1301, USA.
43  */
44 
45 #ifndef __GST_CVTRACKER_H__
46 #define __GST_CVTRACKER_H__
47 
48 #include <gst/video/gstvideometa.h>
49 #include <gst/opencv/gstopencvvideofilter.h>
50 #include <opencv2/core.hpp>
51 #include <opencv2/imgproc.hpp>
52 #include <opencv2/tracking.hpp>
53 
54 #define GST_OPENCV_CHECK_VERSION(major,minor,revision) \
55   (CV_VERSION_MAJOR > (major) || \
56    (CV_VERSION_MAJOR == (major) && CV_VERSION_MINOR > (minor)) || \
57    (CV_VERSION_MAJOR == (major) && CV_VERSION_MINOR == (minor) && \
58     CV_VERSION_REVISION >= (revision)))
59 
60 #if GST_OPENCV_CHECK_VERSION(4, 5, 1)
61 #include <opencv2/tracking/tracking_legacy.hpp>
62 #endif
63 
64 G_BEGIN_DECLS
65 
66 /* #defines don't like whitespacey bits */
67 #define GST_TYPE_OPENCV_TRACKER \
68   (gst_cvtracker_get_type())
69 #define GST_OPENCV_TRACKER(obj) \
70   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OPENCV_TRACKER,GstCVTracker))
71 #define GST_OPENCV_TRACKER_CLASS(klass) \
72   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OPENCV_TRACKER,GstCVTrackerClass))
73 #define GST_IS_OPENCV_TRACKER(obj) \
74   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OPENCV_TRACKER))
75 #define GST_IS_OPENCV_TRACKER_CLASS(klass) \
76   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OPENCV_TRACKER))
77 
78 typedef struct _GstCVTracker  GstCVTracker;
79 typedef struct _GstCVTrackerClass GstCVTrackerClass;
80 
81 struct _GstCVTracker
82 {
83   GstOpencvVideoFilter element;
84 
85   guint x;
86   guint y;
87   guint width;
88   guint height;
89   gint algorithm;
90   gboolean draw;
91   gboolean post_debug_info;
92 
93   cv::Ptr<cv::Tracker> tracker;
94 #if GST_OPENCV_CHECK_VERSION(4, 5, 1)
95   cv::Ptr<cv::Rect> roi;
96 #else
97   cv::Ptr<cv::Rect2d> roi;
98 #endif
99 };
100 
101 typedef enum {
102   GST_OPENCV_TRACKER_ALGORITHM_BOOSTING,
103   GST_OPENCV_TRACKER_ALGORITHM_CSRT,
104   GST_OPENCV_TRACKER_ALGORITHM_KCF,
105   GST_OPENCV_TRACKER_ALGORITHM_MEDIANFLOW,
106   GST_OPENCV_TRACKER_ALGORITHM_MIL,
107   GST_OPENCV_TRACKER_ALGORITHM_MOSSE,
108   GST_OPENCV_TRACKER_ALGORITHM_TLD,
109 } GstOpenCVTrackerAlgorithm;
110 
111 struct _GstCVTrackerClass
112 {
113   GstOpencvVideoFilterClass parent_class;
114 };
115 
116 GType gst_cvtracker_get_type (void);
117 
118 GST_ELEMENT_REGISTER_DECLARE (cvtracker);
119 
120 G_END_DECLS
121 
122 #endif /* __GST_CVTRACKER_H__ */
123