Video Sequence Matching

py_fort_myrmidon.VideoSegment

class py_fort_myrmidon.VideoSegment

A VideoSegment represents a part of a Video file with its associated tracking data.

VideoSegment are most often queried with Query.FindVideoSegments(). Once queried, they are blank, i.e. no query results will appears in VideoSegment.Data. One would call Match() to associate queries results with these segments. Finally a VideoSequence context manager can be used to iterate over each video frame of the VideoSegmentList.

Note

Query.FindVideoSegment(), Match() and VideoSequence use a VideoSegmentList as return value or arguments. Indeed it could happen that the desired sequence of images span over multiple video file.

Example

import py_fort_myrmidon as fm

e = fm.Experiment.Open("file.myrmidon")

# note it would be extremly computationally intensive to
# iterate over the whole experiment, we select a time region.
start = fm.Time.Parse('2019-11-02T20:00:00.000Z')
end = start.Add(30 * fm.Duration.Second)

## step 0: make some query on the experiment
trajectories = fm.Query.ComputeAntTrajectories(e,start=start,end=end)

## step 1: look up segments bet
segments = fm.Query.FindVideoSegments(e,
                                      space = 1,
                                      start = start,
                                      end = end)

## step 2: match queried data with video frames
fm.VideoSegment.Match(segments,trajectories)

## step 3: iterate over all video frame and matched data
with fm.VideoSequence(segments) as sequence:
    for frame,data in sequence:
        ## step 3.1 on each cv2.Mat `frame` do something based
        ## on `data`
        pass
property AbsoluteFilePath

the absolute filepath to the video file

Type:

str

property Begin

the first video frame position in the video file corresponding to the segment

Type:

int

property Data

matched query result with the video frame in the list. If no tracking data is associated with a given frame, there will be no corresponding object in this field.

Type:

List[VideoFrameData]

property End

the last+1 video frame postion in the video file corresponding to the segment

Type:

int

static Match(*args, **kwargs)

Overloaded function.

  1. Match(segments: py_fort_myrmidon.VideoSegmentList, identifiedFrames: List[py_fort_myrmidon.IdentifiedFrame]) -> None

Matches IdentifiedFrame with a VideoSegmentList

Parameters:
  • segments (VideoSegmentList) – the segments to associate data with

  • identifiedFrames (List[IdentifiedFrame]) – the IdentifiedFrames to match with segments.

Raises:

ValueError – if the all segments are not from the same Space

  1. Match(segments: py_fort_myrmidon.VideoSegmentList, collisionData: List[Tuple[py_fort_myrmidon.IdentifiedFrame, py_fort_myrmidon.CollisionFrame]]) -> None

Matches CollisionData with a VideoSegmentList

Parameters:
  • segments (VideoSegmentList) – the segments to associate data with

  • collisionData (List[CollisionData]) – the CollisionData to match with segments.

Raises:

ValueError – if the all segments are not from the same Space

  1. Match(segments: py_fort_myrmidon.VideoSegmentList, trajectories: List[py_fort_myrmidon.AntTrajectory]) -> None

Matches AntTrajectory with a VideoSegmentList

Parameters:
  • segments (VideoSegmentList) – the segments to associate data with

  • trajectories (List[AntTrajectory]) – the AntTrajectories to match with segments.

Raises:

ValueError – if the all segments are not from the same Space

  1. Match(segments: py_fort_myrmidon.VideoSegmentList, interactions: List[py_fort_myrmidon.AntInteraction]) -> None

Matches AntInteraction with a VideoSegmentList

Parameters:
  • segments (VideoSegmentList) – the segments to associate data with

  • interactions (List[AntInteraction]) – the AntInteractions to match with segments.

Raises:

ValueError – if the all segments are not from the same Space

property Space

the Space the segment belongs to

Type:

int

py_fort_myrmidon.VideoSegmentList

class py_fort_myrmidon.VideoSegmentList

An opaque list of VideoSegment.

It works just as a list of VideoSegment.

append(self: py_fort_myrmidon.VideoSegmentList, x: py_fort_myrmidon.VideoSegment) None

Add an item to the end of the list

clear(self: py_fort_myrmidon.VideoSegmentList) None

Clear the contents

deepcopy(self: py_fort_myrmidon.VideoSegmentList) py_fort_myrmidon.VideoSegmentList

Performs a deepcopy of the list.

The main purpose is for the unittest implementation.

extend(*args, **kwargs)

Overloaded function.

  1. extend(self: py_fort_myrmidon.VideoSegmentList, L: py_fort_myrmidon.VideoSegmentList) -> None

Extend the list by appending all the items in the given list

  1. extend(self: py_fort_myrmidon.VideoSegmentList, L: Iterable) -> None

Extend the list by appending all the items in the given list

insert(self: py_fort_myrmidon.VideoSegmentList, i: int, x: py_fort_myrmidon.VideoSegment) None

Insert an item at a given position.

pop(*args, **kwargs)

Overloaded function.

  1. pop(self: py_fort_myrmidon.VideoSegmentList) -> py_fort_myrmidon.VideoSegment

Remove and return the last item

  1. pop(self: py_fort_myrmidon.VideoSegmentList, i: int) -> py_fort_myrmidon.VideoSegment

Remove and return the item at index i

py_fort_myrmidon.VideoFrameData

class py_fort_myrmidon.VideoFrameData

The tracking data and query results associated with a Video frame.

Note

After a call to Query.FindMovieSegments() this structure will contain no matched data. One must call VideoSequence.Match() to associate query results with the VideoFrameData present in the VideoSegmentList.

Warning

In the unlikely case of a VideoFrameData without any tracking data ( the movie frame was exported but no tracking was reported ), the value of VideoFrameData.Time will be set to Time.SinceEver() and all other query result field will be set to None.

property Collided

the ants collision (if previously matched)

Type:

CollisionFrame

Empty(self: py_fort_myrmidon.VideoFrameData) bool

Indicates the (unlikely) case where no tracking data is associated with this video frame.

Returns:

True if there is no tracking data (even a timeout / frame drop report) associated with this video frame.

Return type:

bool

property Identified

the ants position (if previously matched)

Type:

IdentifiedFrame

property Interactions

the interactions in this frame (if previously matched)

Type:

List[AntInteraction]

property Position

the frame position in the video file

Type:

int

property Time

the video frame acquisition time (if available)

Type:

Time

property Trajectories

the trajectories in this frame (if previously matched)

Type:

List[AntTrajectory]

py_fort_myrmidon.VideoSequence

class py_fort_myrmidon.VideoSequence

A contextmanager for iterating over Video Frame and matched data.

Examples

import py_fort_myrmidon as fm

## will iterate over all video frame of space 1
segments = fm.Query.FindVideoSegments(e,space = 1)
with fm.VideoSequence(segments) as sequence:
    for frame, data in sequence:
        pass