Data

Datastructures

Defines commonly used data structures for a convenient exchange format.

Note that collections.namedtuple are used for fast data exchange objects but they do not support docstring in Python 2. Setting the docstring is only possible in Python 3. So depending on the Python version that was used to compile the documentation the documentation for the datastructures are missing.

class Detection[source]

Bases: tuple

A Detection is one data point produced where (possibly) a bee was observed.

id

int or str – identifier for detection

timestamp

time representation – timestamp of detection

x

float – x position in image coordinates

y

float – y position in image coordinates

orientation

float – the orientation of the tag/bee (zrotation in schema)

beeId

int or iterable – interpretation of id

meta

dict – dictionary with further information about a detection like localizer scores, truth ids, camera ids…

class Track[source]

Bases: tuple

A Track is a group of Detection objects produced by (possibly) one bee.

To avoid handing a lot of data that we won’t need only the identifiers and timestamps are stored/provided in a Track. Specific data for a detection could be retrieved via the DataWrapper.

Depending on the DataWrapper implementation the detections are also stored as objects in the meta field. The key identifier for the list of detections in the meta field is DETKEY.

Note

It might be necessary to clear the meta dictionary after some processing steps to free memory.

id

int or str – identifier for Track

ids

list of Detection – iterable with ids of Detection

timestamps

iterable – iterable with timestamps of detections

meta

dict – dictionary with uncommon information about a Track like scoring metrics

class Score[source]

Bases: tuple

A Score defines how similar a Track object is with a truth path.

Example

This is an example for a Track and a resulting Score:

Track(id=1, ids=['A', 'A', 'B', 'B', 'C', 'C'], timestamps=(...), meta={})
Score(value=0.33, track_id=1, truth_id='A', calc_id='A',
      metrics=ScoreMetrics(), alternatives=['B', 'C'])
value

float – The scoring value calculated via a scoring function using the ScoreMetrics

track_id

int or strTrack id we are scoring

truth_id

int – truth id of the Track we are matching against

calc_id

int – the calculated id for this Track

metrics

ScoreMetrics – metrics describing the differences between Track objects

alternatives

list – alternative truth ids that have the same score

class ScoreMetrics[source]

Bases: tuple

A ScoreMetrics provides metrics to determine how similar two Track objects are.

Example

Assuming gap = 2

Truth Track Test Track Metric
_ _ Gap Match (gap_left = True)
_ _ Gap Match
A A Match
_ _ Gap Match
A B Mismatch
_ B Insert
A A Match
A _ Delete
_ _ Gap Match
A _ Delete (gap_right = False)

The following ScoreMetrics belongs to the track comparison in the table above.:

ScoreMetrics(track_length=5, truth_track_length=100, adjusted_length=10,
             id_matches=2, id_mismatches=1,
             inserts=1, deletes=1, gap_matches=4, gap_left=True, gap_right=False)
track_length

int – length of Track including gaps

truth_track_length

int – length of truth track we are matching against

adjusted_length

int – length of Track with added gaps left and right

id_matches

int – number of matched ids

id_mismatches

int – number of mismatched ids

inserts

int – basically number of False Positives in the Track

deletes

int – basically number of False Negatives in the Track

gap_matches

int – correctly matched gaps

gap_left

bool – correctly identified gap to the left

gap_right

bool – correctly identified gap to the right

Constants

Constants that are used e.g. as keys in the meta dictionary in Detection and Track.

CAMKEY = 'camId'

This key is used in Detection to mark the camera the detection is associated with.

DETKEY = 'detections'

This key is used in Track to store the Detection object while tracking.

TRUTHKEY = 'truthId'

This key is used in Track and Detection to store the truth id of the frame object for training and validation.

FRAMEIDXKEY = 'frameIdx'

This key is used on Track to save the index of the frame the track is associated with.

FPKEY = 'fp_track'

This key is used in Track to mark tracks that are identified as entirely consisting of False Positives while validation.

DataWrapper

Provides classes for abstract access to Detection and Track objects.

There are two abstract classes describing the interface of a DataWrapper. A DataWrapper is only providing access to data, whereas the DataWrapperTruth also considers ground truth data. This distinction has the following reasons:

  1. No accidental tracking on truth data (e.g. truth ids)
  2. Better performance in generation and access of data
  3. Smaller interface for production usage

There are currently three implementations:

DataWrapperBinary:
Directly integrates with bb_binary and is implemented with a focus on performance.
DataWrapperPandas:
Uses Pandas as backend. Therefore it is more complicated to generate an instance of this DataWrapper. But it offers more possibilities in using other data sources or performing experimens with data, that is not available in bb_binary.
DataWrapperTracks:
This is a DataWrapper to organize the access to Track objects to be able to perform tracking and validation on track level (assigning tracks to other tracks instead of detections to tracks).
class DataWrapper[source]

Bases: object

Abstract class that describes the access to detections.

get_camids(frame_object=None)[source]

Returns an iterable with camera ids.

If frame_object is None returns all available camera ids. Otherwise it returns the camera ids the Detection objects of frame_object are associated with. So possible multiple ids if frame_object is a Track and a single id if frame_object is a Detection.

Keyword Arguments:
 
  • frame_object (Optional Detection or Track) – frame object to restrict
  • ids to. (camera) –
Returns:

iterable structure with camera ids

Return type:

list of int

get_detection(detection_id)[source]

Returns all information concerning the Detection with detection_id.

Parameters:detection_id (int or str) – the id of the detection as used in the data schema
Returns:data formated as Detection
Return type:Detection
get_detections(detection_ids)[source]

Returns all information concerning the Detection objects with detection_ids.

Parameters:detection_ids (list of int or str) – iterable structure with detection ids
Returns:iterable structure with Detection objects
Return type:list of Detection
get_frame_objects(cam_id=None, timestamp=None)[source]

Gets all detections or tracks on cam_id in frame with timestamp.

Keyword Arguments:
 
  • cam_id (Optional int) – the cam to consider, starts with smallest cam id if None
  • timestamp (Optional timestamp) – frame with timestamp, starts with first frame if None
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_neighbors(frame_object, cam_id, radius=10, timestamp=None)[source]

Gets all detections or tracks in the neighborhood of the given frame_object.

Parameters:
  • frame_object (Detection or Track) – frame object to search neighborhood
  • cam_id (int) – usually cam_id is already available so use this parameter for speedup
Keyword Arguments:
 
  • radius (Optional int) – the radius to search in image coordinates
  • timestamp (Optional timestamp) – consider frame objects of frame with different timestamp
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_timestamps(cam_id=None)[source]

Extracts all timestamps as unique ordered Iterable.

Keyword Arguments:
 cam_id (Optional int) – select only timestamps that are available for this camera id
Returns:list with timestamps as ordered iterable
Return type:list of time representations
class DataWrapperTruth[source]

Bases: bb_tracking.data.datawrapper.DataWrapper

Special wrapper for truth data.

This is separated from DataWrapper for performance and convenience reasons.

The main difference is, that this class will merge ground truth data with pipeline output and generate truth tracks that can be used for training and validation.

fp_id = -1

int – id for possibly false positive detections (no matching truth_id)

code_unknown = 'unknown'

str – default value for readability

get_all_detection_ids()[source]

Returns the ids of all positives and false positives.

Returns:tuple containing:
  • positives (set): Ids of detections with associated truth id
  • false positives (set): Ids of detections without truth id
Return type:tuple
get_truth_track(truth_id, cam_id=None)[source]

Returns the Track to the given truth_id.

Parameters:truth_id (int or str) – we are using the truth_id to identify a certain track
Keyword Arguments:
 cam_id (Optional int) – the cam to consider
Returns:the track to the given truth_id
Return type:Track
get_truth_tracks(cam_id=None)[source]

Returns an iterator over all the truth tracks.

Keyword Arguments:
 cam_id (Optional int) – restrict on tracks on this camera
Returns:iterator over all the truth Tracks
Return type:iterator
get_truthid(frame_object)[source]

Returns the truth id for the corresponding frame_object id or None.

Keyword Arguments:
 frame_object (Detection or Track or id) – frame object or the id of the Detection so extract the truth id from
Returns:the truth id for the frame_object or fp_id if frame_object is a false positive
Return type:int or str
get_truthids(cam_id=None, frame_object=None)[source]

Returns all truth ids of either the whole truth data or restricted on some parameters.

Note

cam_id and frame_object can not be used together!

Keyword Arguments:
 
  • cam_id (Optional int) – get truth ids that are associated with this camera.
  • frame_object (Detection or Track) – get truth ids that are associated with this frame object.
Returns:

all the truth ids that might be associated with a frame object or camera.

Return type:

set

DataWrapperBinary

This implementations of DataWrapper are using dictionaries with shared data objects as backend. Therefore they are tuned for fast performance and not for data analysis on the detection data.

The DataWrapperBinary implementations are only compatible with bb_binary data. If have other data formats either try to convert them or use DataWrapperPandas.

class DataWrapperBinary(repository, meta_keys=None, position_scale=1.0, **kwargs)[source]

Bases: bb_tracking.data.datawrapper.DataWrapper

Class for fast access to detections via bb_binary Repository.

This class is recommended for performance reasons and only compatible to the bb_binary format. It uses dictionaries for fast lookup and cheap memory because the Detection objects are shared between the different dictionaries.

__init__(repository, meta_keys=None, position_scale=1.0, **kwargs)[source]

Necessary initialization to organize detection data.

Parameters:

repository (bb_binary.Repository) – bb_binary Repository with detections

Keyword Arguments:
 
  • meta_keys (Optional dict) – {detecion_key: meta_key} mapping that is added as meta field in detections (detection fields defined in the bb_binary schema)
  • (Optional (position_scale) – float:): rescaling factor for position data
  • **kwargs (dict) – keyword arguments for Repository.iter_frames()
detections_dict = None

dict{detection_id -- detection} mapping for Detection

frame_detections = None

dict{(cam_id, timestamp) -- detection} mapping for Detection

frame_trees = None

dict{(cam_id, timestamp) -- KDTree} mapping

position_scale = None

list of timestamp – sorted list with all available timestamps

cam_ids = None

list of int – sorted list with all available camera ids

timestamps = None

list of timestamp – sorted list with all available timestamps

cam_timestamps = None

dict{cam_id -- sorted list of timestamps} mapping

get_camids(frame_object=None)[source]

Returns an iterable with camera ids.

If frame_object is None returns all available camera ids. Otherwise it returns the camera ids the Detection objects of frame_object are associated with. So possible multiple ids if frame_object is a Track and a single id if frame_object is a Detection.

Keyword Arguments:
 
  • frame_object (Optional Detection or Track) – frame object to restrict
  • ids to. (camera) –
Returns:

iterable structure with camera ids

Return type:

list of int

get_detection(detection_id)[source]

Returns all information concerning the Detection with detection_id.

Parameters:detection_id (int or str) – the id of the detection as used in the data schema
Returns:data formated as Detection
Return type:Detection
get_detections(detection_ids)[source]

Returns all information concerning the Detection objects with detection_ids.

Parameters:detection_ids (list of int or str) – iterable structure with detection ids
Returns:iterable structure with Detection objects
Return type:list of Detection
get_frame_objects(cam_id=None, timestamp=None)[source]

Gets all detections or tracks on cam_id in frame with timestamp.

Keyword Arguments:
 
  • cam_id (Optional int) – the cam to consider, starts with smallest cam id if None
  • timestamp (Optional timestamp) – frame with timestamp, starts with first frame if None
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_neighbors(frame_object, cam_id, radius=10, timestamp=None)[source]

Gets all detections or tracks in the neighborhood of the given frame_object.

Parameters:
  • frame_object (Detection or Track) – frame object to search neighborhood
  • cam_id (int) – usually cam_id is already available so use this parameter for speedup
Keyword Arguments:
 
  • radius (Optional int) – the radius to search in image coordinates
  • timestamp (Optional timestamp) – consider frame objects of frame with different timestamp
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_timestamps(cam_id=None)[source]

Extracts all timestamps as unique ordered Iterable.

Keyword Arguments:
 cam_id (Optional int) – select only timestamps that are available for this camera id
Returns:list with timestamps as ordered iterable
Return type:list of time representations
class DataWrapperTruthBinary(repo_detections, repo_truth, radius, meta_keys=None, **kwargs)[source]

Bases: bb_tracking.data.datawrapper_binary.DataWrapperBinary, bb_tracking.data.datawrapper.DataWrapperTruth

Class for fast access to truth data via bb_binary Repository.

This class is recommended for performance reasons and only compatible to the bb_binary format. It uses dictionaries for fast lookup and cheap memory because the Detection objects are shared between the different dictionaries.

Note

The generation and access to the objects is not as fast as in DataWrapperBinary. This is no problem, because the truth data is most likely not as big as real datasets.

cam_false_positives = None

dict{cam_id -- set of detection ids} mapping

false_positives = None

set of ids – Ids of all the detections without associated truth id

positives = None

set of ids – Ids of all the detections with associated truth id

__init__(repo_detections, repo_truth, radius, meta_keys=None, **kwargs)[source]

Necessary initialization to organize detection data.

Parameters:
  • repo_detections (bb_binary.Repository) – Repository with detections
  • repo_truth (bb_binary.Repository) – Repository with truth data
  • radius (int) – merge detections and truth via distance
Keyword Arguments:
 
  • meta_keys (Optional dict) – {detecion_key: meta_key} mapping that is added as meta field in Detection objects
  • **kwargs (dict) – keyword arguments for Repository.iter_frames()
tracks = None

dict{truth_id -- Track} mapping for Track

cam_tracks = None

dict{cam_id -- {truth_id: Track}} mapping for Track

get_all_detection_ids()[source]

Returns the ids of all positives and false positives.

Returns:tuple containing:
  • positives (set): Ids of detections with associated truth id
  • false positives (set): Ids of detections without truth id
Return type:tuple
get_truth_track(truth_id, cam_id=None)[source]

Returns the Track to the given truth_id.

Parameters:truth_id (int or str) – we are using the truth_id to identify a certain track
Keyword Arguments:
 cam_id (Optional int) – the cam to consider
Returns:the track to the given truth_id
Return type:Track
get_truth_tracks(cam_id=None)[source]

Returns an iterator over all the truth tracks.

Keyword Arguments:
 cam_id (Optional int) – restrict on tracks on this camera
Returns:iterator over all the truth Tracks
Return type:iterator
get_truthid(frame_object)[source]

Returns the truth id for the corresponding frame_object id or None.

Keyword Arguments:
 frame_object (Detection or Track or id) – frame object or the id of the Detection so extract the truth id from
Returns:the truth id for the frame_object or fp_id if frame_object is a false positive
Return type:int or str
get_truthids(cam_id=None, frame_object=None)[source]

Returns all truth ids of either the whole truth data or restricted on some parameters.

Note

cam_id and frame_object can not be used together!

Keyword Arguments:
 
  • cam_id (Optional int) – get truth ids that are associated with this camera.
  • frame_object (Detection or Track) – get truth ids that are associated with this frame object.
Returns:

all the truth ids that might be associated with a frame object or camera.

Return type:

set

DataWrapperPandas

Provides classes for easy access to detections beyond data formats.

This DataWrapppers are using Pandas as backend. This helps when you are using data from other data sources, but the instantiation is a bit more complicated. You basically create a Pandas DataFrame and provide a mapping from required default names to the column names in your Pandas DataFrame.

Row lookups in Pandas are also quite expensive so this this classes are quite slow and not recommended for production.

Note

If not used for experiments in the future they might be removed.

Todo

Refactor detection cache and add cache for frame trees.

class DataWrapperPandas(detections, cols=None, duplicates_radius=None, meta_keys=None)[source]

Bases: bb_tracking.data.datawrapper.DataWrapper

Class for flexible access to detections.

This class is recommended for testing or data exploration. The data input is configurable and possible additional attributes are not discarded. But it is not as efficient as the DataWrapperBinary class in terms of memory and lookup speed.

beeId_digits = 12

int – number of digits use to encode a beeID on a tag

__init__(detections, cols=None, duplicates_radius=None, meta_keys=None)[source]

Necessary initialization to reformat detections dataframe.

Parameters:

detections (pd.DataFrame) – pandas dataframe with detections

Keyword Arguments:
 
  • cols (Optional dict) – dictionary with {key: key in dataframe} mapping.
  • duplicates_radius (Optional int) – distance to determine if detections are duplicates
  • meta_keys (Optional dict) – {detecion_key: meta_key} mapping that is added as meta field in detections
cols = None

obj`dict` – strings to identify certain columns

duplicates_radius = None

int – detections within this radius are considered to be duplicates

mean_duplicates_merge_columns = None

obj`dict` – use mean value for this columns when merge duplicates

detections = None

pd.DataFrame – pandas dataframe with all detections

detections_dict = None

obj`dict` – dictionary with {detection_id: detection} mapping for Detection

cam_timestamps = None

dict{cam_id -- sorted list of timestamps} mapping

clean_data(data)[source]

Clean the dataframes to use a common format to access all the data.

Parameters:data (pd.DataFrame) – pandas dataframe
Returns:clean dataframe
Return type:pd.DataFrame
get_camids(frame_object=None)[source]

Returns an iterable with camera ids.

If frame_object is None returns all available camera ids. Otherwise it returns the camera ids the Detection objects of frame_object are associated with. So possible multiple ids if frame_object is a Track and a single id if frame_object is a Detection.

Keyword Arguments:
 
  • frame_object (Optional Detection or Track) – frame object to restrict
  • ids to. (camera) –
Returns:

iterable structure with camera ids

Return type:

list of int

get_detection(detection_id)[source]

Returns all information concerning the Detection with detection_id.

Parameters:detection_id (int or str) – the id of the detection as used in the data schema
Returns:data formated as Detection
Return type:Detection
get_detections(detection_ids)[source]

Returns all information concerning the Detection objects with detection_ids.

Parameters:detection_ids (list of int or str) – iterable structure with detection ids
Returns:iterable structure with Detection objects
Return type:list of Detection
get_frame_objects(cam_id=None, timestamp=None)[source]

Gets all detections or tracks on cam_id in frame with timestamp.

Keyword Arguments:
 
  • cam_id (Optional int) – the cam to consider, starts with smallest cam id if None
  • timestamp (Optional timestamp) – frame with timestamp, starts with first frame if None
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_neighbors(frame_object, cam_id, radius=10, timestamp=None)[source]

Gets all detections or tracks in the neighborhood of the given frame_object.

Parameters:
  • frame_object (Detection or Track) – frame object to search neighborhood
  • cam_id (int) – usually cam_id is already available so use this parameter for speedup
Keyword Arguments:
 
  • radius (Optional int) – the radius to search in image coordinates
  • timestamp (Optional timestamp) – consider frame objects of frame with different timestamp
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_timestamps(cam_id=None)[source]

Extracts all timestamps as unique ordered Iterable.

Keyword Arguments:
 cam_id (Optional int) – select only timestamps that are available for this camera id
Returns:list with timestamps as ordered iterable
Return type:list of time representations
class DataWrapperTruthPandas(detections, truth, radius, merge_cols=None, **kwargs)[source]

Bases: bb_tracking.data.datawrapper_pandas.DataWrapperPandas, bb_tracking.data.datawrapper.DataWrapperTruth

Special wrapper for truth data with a Pandas Backend.

__init__(detections, truth, radius, merge_cols=None, **kwargs)[source]

Necessary initialization to reformat detections dataframe.

Also performs merge of detections and truth dataframes.

Parameters:
  • detections (pd.DataFrame) – pandas dataframe with detections
  • truth (pd.DataFrame) – pandas dataframe with truth
  • radius (int) – merge detections and truth via distance
Keyword Arguments:
 
  • merge_cols (dict) – {key in truth: new key in detections} mapping.
  • **kwargs (dict) – keyword arguments for DataWrapperPandas
duplicate_cols = None

tuple of str – columns to identify track duplicates

merge_cols = None

dict – strings to identify how columns in truth should be named in detections

clean_data(data)[source]

Clean the dataframes to use a common format to access all the data.

Parameters:data (pd.DataFrame) – pandas dataframe
Returns:clean dataframe
Return type:pd.DataFrame
get_all_detection_ids()[source]

Returns the ids of all positives and false positives.

Returns:tuple containing:
  • positives (set): Ids of detections with associated truth id
  • false positives (set): Ids of detections without truth id
Return type:tuple
get_truth_track(truth_id, cam_id=None)[source]

Returns the Track to the given truth_id.

Parameters:truth_id (int or str) – we are using the truth_id to identify a certain track
Keyword Arguments:
 cam_id (Optional int) – the cam to consider
Returns:the track to the given truth_id
Return type:Track
get_truth_tracks(cam_id=None)[source]

Returns an iterator over all the truth tracks.

Keyword Arguments:
 cam_id (Optional int) – restrict on tracks on this camera
Returns:iterator over all the truth Tracks
Return type:iterator
get_truthid(frame_object)[source]

Returns the truth id for the corresponding frame_object id or None.

Keyword Arguments:
 frame_object (Detection or Track or id) – frame object or the id of the Detection so extract the truth id from
Returns:the truth id for the frame_object or fp_id if frame_object is a false positive
Return type:int or str
get_truthids(cam_id=None, frame_object=None)[source]

Returns all truth ids of either the whole truth data or restricted on some parameters.

Note

cam_id and frame_object can not be used together!

Keyword Arguments:
 
  • cam_id (Optional int) – get truth ids that are associated with this camera.
  • frame_object (Detection or Track) – get truth ids that are associated with this frame object.
Returns:

all the truth ids that might be associated with a frame object or camera.

Return type:

set

DataWrapperTracks

This implementations of DataWrapper are also using dictionaries with shared data objects as backend. The difference to DataWrapperBinary is that they are managing Track objects instead of Detection objects. Therefore the DataWrapperTracks implementations have to know where a track starts and where it ends.

Sometimes it is necessary to have additional information about detections for training and validation purposes. So it is posssible to inject another instance of DataWrapper and DataWrapperTracks will delegate tasks it can not fullfill to this instance.

class DataWrapperTracks(tracks, cam_timestamps, data=None)[source]

Bases: bb_tracking.data.datawrapper.DataWrapper

Class for access to tracks.

This class is implemented with a focus on performance. It is possible to inject a DataWrapper for other, non performant related tasks.

__init__(tracks, cam_timestamps, data=None)[source]

Initialization for DataWrapperTracks

Note

The data keyword argument is optional, but sometimes it is convenient to have one DataWrapper that provides access to Track and Detection.

Parameters:
Keyword Arguments:
 

data (Optional DataWrapper) – A DataWrapper provides access to detections.

cam_ids = None

list of int – sorted list with all available camera ids

cam_timestamps = None

dict{cam_id -- sorted list of timestamps} mapping

timestamps = None

list of timestamp – sorted list with all available timestamps

data = None

DataWrapper – Optional DataWrapper instance to access detection data

frame_track_start = None

dict{(cam_id, timestamp) -- list of track} Track starts in frame

frame_track_end = None

dict{(cam_id, timestamp) -- list of track} Track ends in frame

tracks = None

dict{track_id -- track} mapping for Track

frame_trees = None

dict{(cam_id, timestamp) -- KDTree} mapping

get_camids(frame_object=None)[source]

Returns an iterable with camera ids.

If frame_object is None returns all available camera ids. Otherwise it returns the camera ids the Detection objects of frame_object are associated with. So possible multiple ids if frame_object is a Track and a single id if frame_object is a Detection.

Keyword Arguments:
 
  • frame_object (Optional Detection or Track) – frame object to restrict
  • ids to. (camera) –
Returns:

iterable structure with camera ids

Return type:

list of int

get_detection(*args)[source]

Returns all information concerning the Detection with detection_id.

Parameters:detection_id (int or str) – the id of the detection as used in the data schema
Returns:data formated as Detection
Return type:Detection
get_detections(*args)[source]

Returns all information concerning the Detection objects with detection_ids.

Parameters:detection_ids (list of int or str) – iterable structure with detection ids
Returns:iterable structure with Detection objects
Return type:list of Detection
get_track(track_id)[source]

Returns all information concerning the track with track_id.

Parameters:track_id (int or str) – the id of the track as used in the data scheme
Returns:data formated as Track
Return type:Track
get_tracks(track_ids)[source]

Same as get_track() but with multiple ids.

Parameters:track_ids (list of int or str) – Iterable structure with track ids
Returns:iterable structure with Track
Return type:list of Track
get_frame_objects(cam_id=None, timestamp=None)[source]

Gets all detections or tracks on cam_id in frame with timestamp.

Keyword Arguments:
 
  • cam_id (Optional int) – the cam to consider, starts with smallest cam id if None
  • timestamp (Optional timestamp) – frame with timestamp, starts with first frame if None
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_frame_objects_starting(cam_id=None, timestamp=None)[source]

Gets all tracks starting on cam_id in frame with timestamp.

Keyword Arguments:
 
  • cam_id (Optional int) – the cam to consider, starts with smallest cam if None
  • timestamp (Optional timestamp) – frame with timestamp, starts with first frame if None
Returns:

iterable structure with Track

Return type:

list of Track

get_neighbors(frame_object, cam_id, radius=10, timestamp=None)[source]

Gets all detections or tracks in the neighborhood of the given frame_object.

Parameters:
  • frame_object (Detection or Track) – frame object to search neighborhood
  • cam_id (int) – usually cam_id is already available so use this parameter for speedup
Keyword Arguments:
 
  • radius (Optional int) – the radius to search in image coordinates
  • timestamp (Optional timestamp) – consider frame objects of frame with different timestamp
Returns:

iterable structure with Detection or Track depending on DataWrapper implementation.

Return type:

list of Detection or Track

get_timestamps(cam_id=None)[source]

Extracts all timestamps as unique ordered Iterable.

Keyword Arguments:
 cam_id (Optional int) – select only timestamps that are available for this camera id
Returns:list with timestamps as ordered iterable
Return type:list of time representations
class DataWrapperTruthTracks(tracks, cam_timestamps, data, **kwargs)[source]

Bases: bb_tracking.data.datawrapper_tracks.DataWrapperTracks, bb_tracking.data.datawrapper.DataWrapperTruth

Class for access to tracks and truth data.

As DataWrapperTruthTracks are only used in the context of training and validation it is necessary to inject a DataWrapperTruth instance. This implementation will delegate all truth data related tasks to the implementation in DataWrapperTracks.data.

__init__(tracks, cam_timestamps, data, **kwargs)[source]

Initialization for DataWrapperTruthTracks

Parameters:
  • tracks (list of Track) – Iterable with Track
  • cam_timestamps (dict) – {cam_id: sorted list of timestamps} mapping
  • data (DataWrapperTruth) – A DataWrapper that provides access to truth data.
Keyword Arguments:
 

**kwargs (dict) – Keyword arguments for DataWrapperTracks without data.

get_all_detection_ids(*args, **kwargs)[source]

Returns the ids of all positives and false positives.

Returns:tuple containing:
  • positives (set): Ids of detections with associated truth id
  • false positives (set): Ids of detections without truth id
Return type:tuple
get_truth_track(*args, **kwargs)[source]

Returns the Track to the given truth_id.

Parameters:truth_id (int or str) – we are using the truth_id to identify a certain track
Keyword Arguments:
 cam_id (Optional int) – the cam to consider
Returns:the track to the given truth_id
Return type:Track
get_truth_tracks(*args, **kwargs)[source]

Returns an iterator over all the truth tracks.

Keyword Arguments:
 cam_id (Optional int) – restrict on tracks on this camera
Returns:iterator over all the truth Tracks
Return type:iterator
get_truthid(*args, **kwargs)[source]

Returns the truth id for the corresponding frame_object id or None.

Keyword Arguments:
 frame_object (Detection or Track or id) – frame object or the id of the Detection so extract the truth id from
Returns:the truth id for the frame_object or fp_id if frame_object is a false positive
Return type:int or str
get_truthids(*args, **kwargs)[source]

Returns all truth ids of either the whole truth data or restricted on some parameters.

Note

cam_id and frame_object can not be used together!

Keyword Arguments:
 
  • cam_id (Optional int) – get truth ids that are associated with this camera.
  • frame_object (Detection or Track) – get truth ids that are associated with this frame object.
Returns:

all the truth ids that might be associated with a frame object or camera.

Return type:

set