Skip to content

haydengunraj/MotionTracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MotionTracker

Based on the (messy) tracking code contained in daphTrack, I decided to make a neater, more generalized toolset for tracking and analyzing the motion of objects. MotionTracker allows for object tracking using HSV thresholding. Moreover, a coordinate system and scale can be set on the video using simple drag and drop commands in order to convert image coordinates into real-world spatial coordinates. As a result, position, velocity, and acceleration values for the object are computed in terms of real-world dimensions, allowing for meaningful analysis of the tracker data.

Track

Example Usage

# import Tracker
from MotionTracker.tracker import Tracker

# Create Tracker instance with parameters
t = Tracker(videoPath="inputName.mov", hsvLow=(39, 0, 27), hsvHigh=(130, 255, 74))

# Alternatively:
#   t = Tracker()
#   t.setVideo("inputName.mov")
#   t.setThresh((39, 0, 27), (130, 255, 74))

# Track, with the image width being reset to 700p
# Notably, output needs to be a .avi to work properly
t.track(outputName="outputName.avi", resizeWidth=700)

At this point, a video will be shown depicting the tracking of the object, as shown in the GIF above.

Next, we need to set a coordinate system and scale for our tracker.

# Set axes and scale for the image
t.setScale()

Here, the final frame of the tracking image will be shown, as well as axes and a scaling line (see below). The axes and scaling line operate on drag-and-drop controls at the red circles. The y-axis is yellow and the x-axis is red, and the control point on the y-axis is used to rotate the axes. After moving the scaling line, the real-world length of the scaling line can be set using the trackbar.

Scale

Notably, the example above is sideways, but can still be analysed in a 'normal' coordinate system by changing the axes.

We can new release our video capture, compute values which represent the object's motion, and plot these values.

# Release video capture
t.release()

# Compute motion values
t.computeMotion()

# Plot positions
t.plotPos()
t.plotPos(comp=True, cont=True)

# Plot speed and velocity components
t.plotVel()
t.plotVel(comp=True, cont=True)

# Plot acceleration and its components
t.plotAcc()
t.plotAcc(comp=True, cont=True)

# Show all plots
t.showPlots()

The plotting functions above display position, velocity, and acceleration values in terms of real-world quantities. Some samples taken from the ball drop example are shown below.

Pos Acc

Dependencies

About

Set of functions for tracking an object in a video and computing position, velocity, and acceleration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages