7#include "samples_utility.hpp"
13void sobelExtractor(
const Mat img,
const Rect roi,
Mat& feat);
15int main(
int argc,
char** argv ){
19 " Usage: tracker <video_name>\n"
21 " example_tracking_kcf Bolt/img/%04d.jpg\n"
22 " example_tracking_kcf faceocc2.webm\n"
45 tracker->setFeatureExtractor(sobelExtractor);
49 std::string video = argv[1];
61 tracker->init(frame,roi);
64 printf(
"Start the tracking process, press ESC to quit.\n");
70 if(frame.rows==0 || frame.cols==0)
74 tracker->update(frame,roi);
89void sobelExtractor(
const Mat img,
const Rect roi,
Mat& feat){
96 if(roi.
x<0){region.
x=0;region.
width+=roi.
x;}
97 if(roi.
y<0){region.
y=0;region.
height+=roi.
y;}
104 patch=img(region).
clone();
109 int addTop,addBottom, addLeft, addRight;
110 addTop=region.
y-roi.
y;
112 addLeft=region.
x-roi.
x;
n-dimensional dense array class
Definition: core/include/opencv2/core/mat.hpp:829
CV_NODISCARD_STD Mat clone() const
Creates a full copy of the array and the underlying data.
int cols
Definition: core/include/opencv2/core/mat.hpp:2155
int rows
the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
Definition: core/include/opencv2/core/mat.hpp:2155
Template class for 2D rectangles.
Definition: modules/core/include/opencv2/core/types.hpp:444
_Tp x
x coordinate of the top-left corner
Definition: modules/core/include/opencv2/core/types.hpp:487
_Tp y
y coordinate of the top-left corner
Definition: modules/core/include/opencv2/core/types.hpp:488
_Tp width
width of the rectangle
Definition: modules/core/include/opencv2/core/types.hpp:489
_Tp height
height of the rectangle
Definition: modules/core/include/opencv2/core/types.hpp:490
Class for video capturing from video files, image sequences or cameras.
Definition: videoio.hpp:766
void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar &value=Scalar())
Forms a border around an image.
void merge(const Mat *mv, size_t count, OutputArray dst)
Creates one multi-channel array out of several single-channel ones.
@ BORDER_REPLICATE
aaaaaa|abcdefgh|hhhhhhh
Definition: core/include/opencv2/core/base.hpp:270
Scalar_< double > Scalar
Definition: modules/core/include/opencv2/core/types.hpp:709
std::shared_ptr< _Tp > Ptr
Definition: cvstd_wrapper.hpp:23
#define CV_32F
Definition: core/include/opencv2/core/hal/interface.h:78
@ GRAY
OpenCV color format. VideoReader and VideoWriter.
Definition: cudacodec.hpp:100
void sobel(InputArray _src, OutputArray _dx, OutputArray _dy, int kernel_size, int borderType, int borderValue)
Creates a 2D gradient image from source luminance data without normalization. Calculate X direction 1...
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
Rect selectROI(const String &windowName, InputArray img, bool showCrosshair=true, bool fromCenter=false, bool printNotice=true)
Allows users to select a ROI on the given image.
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
Converts an image from one color space to another.
@ COLOR_BGR2GRAY
convert between RGB/BGR and grayscale, color conversions
Definition: imgproc/include/opencv2/imgproc.hpp:555
void rectangle(InputOutputArray img, Point pt1, Point pt2, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)
Draws a simple, thick, or filled up-right rectangle.
void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)
Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: core/include/opencv2/core.hpp:107
Definition: contrib/modules/tracking/include/opencv2/tracking.hpp:118
bool compress_feature
activate the pca method to compress the features
Definition: contrib/modules/tracking/include/opencv2/tracking.hpp:130
int desc_pca
compressed descriptors of TrackerKCF::MODE
Definition: contrib/modules/tracking/include/opencv2/tracking.hpp:133
int desc_npca
non-compressed descriptors of TrackerKCF::MODE
Definition: contrib/modules/tracking/include/opencv2/tracking.hpp:134
int compressed_size
feature size after compression
Definition: contrib/modules/tracking/include/opencv2/tracking.hpp:132
This part explains how to set custom parameters and use your own feature-extractor function for the CN tracker. If you need a more detailed information to use cv::Tracker, please refer to Introduction to OpenCV Tracker.