PyFastTrack package

Detector

class pyfasttrack.base_detector.BaseDetector

Bases: object

Abstract class to implement an objects detector.

abstract detect(image)

Abstract method to be implemented.

This method will take a full image with all the objects to detect and will return a list of tuples (mask, left_corner_coordinate [x, y]) with one object by mask, the object represented by non-zero pixels and the background by zero pixels.

Parameters

imagendarray

The full image.

Returns

dict

List of (mask, left_corner_coord).

get_direction(mask, features)

Get the object direction.

The object orientation is updated with the correct direction.

Parameters

maskndarray

Mask of one object.

featuresdict

Object features.

Returns

bool

Is object left oriented.

ndarray

Rotated mask.

ndarray

Rotation matrix.

get_features(mask)

Get the object features using equivalent ellipse.

Parameters

maskndarray

Mask of one object.

static modulo(angle)

Provide the mathematical 2pi modulo.

Parameters

maskfloat

Angle in radian.

Returns

float

Angle between 0->2pi

process(image)

Process one image.

Parameters

imagendarray

The full image.

Returns

list

List of detected objects and their features.

class pyfasttrack.ft_detector.FtDetector(params)

Bases: BaseDetector

Implement the classic FastTrack detector.

detect(image)

Detect objects

Parameters

imagendarray

Image as GRAYSCALE.

Returns

list

List of masks as [(mask, left_corner), …].

set_background(image)

Set the background image.

Parameters

imagendarray

Background image.

class pyfasttrack.yolo_detector.YoloDetector(params)

Bases: BaseDetector

detect(image)

Detect objects

Parameters

imagendarray

Image as BGR.

Returns

list

List of masks as [(mask, left_corner), …].

Tracker

class pyfasttrack.tracker.Tracker(params=None, detector=None)

Bases: object

Tracker class to determine assignment from previous and current coordinates.

static angle_difference(a, b)

Get the minimal difference, a-b), between two angles.

Parameters

afloat

First angle.

bfloat

Second angle.

Returns

float

a-b.

assign(prev, current)

Find the optimal assignent.

Parameters

prevlist

List of dict. Each dict is one object with 4 key “0”, “1”, “2”, “3”. 0,1,2 is the {center, orientation} of the head, tail and body respectively. 3 is {area, perim} of the object.

currentlist

List of dict. Each dict is one object with 4 key “0”, “1”, “2”, “3”. 0,1,2 is the {center, orientation} of the head, tail and body respectively. 3 is {area, perim} of the object.

Returns

list

Assignment.

clean(current, counter, lost, idty)

Delete objects that were lost. Only counter is copied in this function. Other lists act as pointer.

Parameters

currentlist

List to clean.

counterlist

Counter of losses.

lostlist

Lost objects.

idtylist

Objects’ identity

Returns

list

Cleaned list.

list

Updated counter.

compute_cost(var, norm)

Compute the cost.

Parameters

varList

List of variable.

normlist

Normalization coefficient associated to var.

Returns

float

Cost.

static div(a, b)

Division by zero, a/0=0.

Parameters

afloat

Dividend.

bfloat

Divisor.

Returns

float

a/b.

find_lost(assignment)

Find object lost at previous step.

Parameters

assignmentlist

Assignment indexes.

Returns

list

Indexes of lost objects.

initialize(image)

Initialize the tracker.

Parameters

imagendarray

Image, channels depending on the detector.

Returns

list

List of detected objects as dict.

process(image)

Process an image.

Parameters

imagendarray

Image, channels depending on the detector.

Returns

list

List of detected objects as dict.

reassign(past, current, order)

Reassign current based on order.

Parameters

prevlist

List of dict of previous detections.

currentlist

List of dict of current detections.

orderlist

Reassingment

Returns

list

Reordered current.

set_detector(detector)

Set the detector.

Parameters

detectorBaseDetector

Detector that is an implementation of the BaseDetector.

set_params(params)

Set the parameters.

Parameters

paramsdict

Parameters.

Data

class pyfasttrack.data.Configuration

Bases: object

Class to read and write configuration files compatible with FastTrack.

get_key(key)

Get a parameter from its key.

Parameters

keystr

Key.

Returns

Any

Parameter.

get_keys(keys)

Get parameters from their keys.

Parameters

keyslist

List of keys.

Returns

List

Parameters.

read_db(path)

Read a configuration file from database.

Parameters

pathstr

Path pointing to the sqlite database.

Returns

Dict

Parameters.

read_toml(path)

Read a configuration file from text file.

Parameters

pathstr

Path pointing to the toml file.

Returns

Dict

Parameters.

write_toml(path)

Write a configuration file.

Parameters

pathstr

Path pointing to the toml file.

class pyfasttrack.data.Result(path)

Bases: object

Class to write result files compatible with FastTrack.

add_data(dat)

Append data in the database.

Parameters

datdict or list of dicts

Data.