Object tracking1.Introduction2.Introduction to Object Tracking3. Code analysis4. Output resultAnother method--Object tracking1.Advantages and disadvantages of the tracker (without any data training) 2.Analysis code3.Experimental results
website:https://learnopencv.com/object-tracking-using-opencv-cpp-python/#opencv-tracking-api
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.
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
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.
Next, analysis food_track_base_color.py file
The following is the code to open the RDK-X3 camera.
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!
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.
This method needs to install the expansion package of opencv
xxxxxxxxxx
pip3 install opencv-contrib-python
This method is to use the tracker of the expansion pack for object tracking
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.
The code is in the extension folder in this directory foods_track_extread.py
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.
Then, the tracker will initialize and track the object selected by the user in real time. Press the "esc" key to end the program!