Object tracking

website:https://learnopencv.com/object-tracking-using-opencv-cpp-python/#opencv-tracking-api

1.Introduction

OpenCV is a cross-platform computer vision and machine learning software library released under the BSD license (open source), which can run on Linux, Windows, Android and MacOS operating systems. [1] It is lightweight and efficient-consists of a series of C functions and a small number of C++ classes, and provides interfaces for languages such as Python, Ruby, and MATLAB, and implements many general-purpose algorithms in image processing and computer vision.

2.Introduction to Object Tracking

What is object tracking? Simply put, locating an object in successive frames of a video is called tracking. In our program, we want to track a blue object. Here are the few steps we have to do:

• Get every frame from the video

• Convert image to HSV space

• Set the HSV Threshold to the blue range.

• Get the blue object, of course we can do anything else we want, eg: draw a circle around the blue object

3. Code analysis

Code path: ~/astra_ws/src/astra_visual/foods_track

This document takes tracking blue objects as an example. If you want to track other color objects, please read the HSV color table.txt in the directory and modify the value of the code below.

image-20210908180521035

Next, analysis food_track_base_color.py file

image-20210908180521035

The following is the code to open the RDK-X3 camera.

image-20210908180521035

The code in this part is: it will run only when the camera is successfully opened. Track the blue object on the screen display of the camera, press the "ESC key" on the keyboard, and the program ends!

4. Output result

After writing the code, click Save, and enter python3 foods_track_base_color.py in the terminal.

You can clearly see the picture displayed by the camera, and track the blue object in the picture. The effect is as follows.

image-20210908180521035

image-20210908180521035

Another method--Object tracking

This method needs to install the expansion package of opencv

This method is to use the tracker of the expansion pack for object tracking

1.Advantages and disadvantages of the tracker (without any data training)

Advantages: It will not be disturbed by colors, and it can track objects. Disadvantage: Once an object is blocked by another object, the program has a high probability of tracking the new object.

2.Analysis code

The code is in the extension folder in this directory foods_track_extread.py

image-20210908180521035

This part of the code is used to open the camera and wait for the user to select an object on the displayed screen. After the selection is completed, press the Enter key.

image-20210908180521035

Then, the tracker will initialize and track the object selected by the user in real time. Press the "esc" key to end the program!

3.Experimental results

image-20210908180521035

image-20210908180521035

image-20210908180521035

image-20210908180521035