plotbee package

Submodules

plotbee.annotate module

class plotbee.annotate.BodyAnnotator(video, options={'blurry': ['yes', 'a bit', 'no', '?'], 'crowded': ['yes', 'no', '?'], 'lighting': ['sunny', 'dark', '?'], 'occluded': ['yes', 'no', '?'], 'pollen': ['no_pollen', 'yellow', 'black', 'white', 'red', '?'], 'tag': ['yes', 'no', 'blurred', '?'], 'tag_id': '', 'track': '', 'view': ['top', 'bottom', 'side', 'back', 'front', '?']}, defaults={'blurry': 'no', 'crowded': 'no', 'lighting': 'sunny', 'occluded': 'no', 'pollen': 'no_pollen', 'tag': 'no', 'tag_id': '-1', 'track': '-1', 'view': 'top'}, shuffle=True, display_fn=<function show_body>, output_file=None)

Bases: object

ACTIVE = 'lightgreen'
DEACTIVE = None
activate_buttons()
annotate_bodies(bodies)
annotate_video()
back(btn)
clear_annotation(btn)
clear_colors()
clear_task_button(task_name)
collect_annotations()
property current_annotation
property current_body
deactivate_buttons()
default_buttons()
display_body_annotations()
go_back()
go_next(btn)
next_body_batch(batch_size=20)
plot_action_buttons()
plot_options_buttons(label_options)
plot_textareas(label_captions)
preload_bodies(command='next')

preload images in the lru_cache

prev_body_batch(batch_size=20)
record(btn)
save(btn)
set_status_text(command=None)
show(default=True)
show_next()
skip(btn)
split_options(options)

Split options in buttons and Text Areas

update(i)
class plotbee.annotate.MultiLabelButton(description, task_name)

Bases: object

plotbee.annotate.body_info_str(body)
plotbee.annotate.count_annotated_bodies(bodies, options)
plotbee.annotate.isAnnotationComplete(annotations, options)
plotbee.annotate.isBodyAnnotated(body)
plotbee.annotate.isBodyCompletedAnnotated(options, body)
plotbee.annotate.load_image(body)
plotbee.annotate.preload_bodies(bodies)

preload images in the lru_cache

plotbee.annotate.record_annotation(body, annotation)
plotbee.annotate.show_body(body)

plotbee.body module

class plotbee.body.Body(parts, center, angle_conn, connections, frame, body_id=- 1, suppressed=False, pollen_score=0.0, tag=None, features=None, virtual=False, annotations={}, metadata={})

Bases: object

property angle

Return angle

Returns

Return angle in degrees from the angle connection

Return type

float

annotate(key, value)

Make a body annotation

Parameters
  • key (Any hashable (ideal str)) – name of the annotation field.

  • value (Any) – Value of the annotation.

Note

Note that annotation can overwrite previous annotations.

property annotations

get annotation dictionary

Returns

annotations

Return type

dict

boundingBox()

Get keypoint of a rotated bounding box of the body

Returns

4 x-y points of the rotated bounding box.

Return type

tuple(tuple(x, y))

Note

this bounding box uses the following as parameters self.center, self.angle, Body.width and Body.height.

cX = None

Class Attribute for cX for plotting

cY = None

Class Attribute for cX for plotting

cbox(w_size=100, h_size=200)

Get keypoint of a rectangle in the center of the body

Parameters
  • w_size (int, optional) – rectangle width, defaults to 100

  • h_size (int, optional) – rectangle height, defaults to 200

Returns

rectangle points (top-left x, top-left y, bottom-right x, bottom-right y)

Return type

tuple(x1, y1, x2, y2)

property center

get body center

Returns

get center point

Return type

tuple(x, y)

Note

y = Body.center.y - Body.y_offset

property connections

Get parts connections (skeleton)

Returns

list of parts connections

Return type

list[list[x:int, y:int]]

property frameid

Get frame id

Returns

frame id

Return type

int

height = 400

Class Attribute for height for plotting

property id

Get body id

Returns

get track id

Return type

int

ignore_angle = False

Class Attribute for ignore_angle for plotting (this is used to extract images without angle normalization)

property image

Get Body image

Returns

body image

Return type

numpy.ndarray

info()

Get body info as dictionary

Returns

body info

Return type

dict

Warning

This is old. Better use self.params.

classmethod load_body(body_dict, frameobj)

Body Constructor from dictionary and Frame object

Parameters
  • body_dict (dict) – recieves a dictionary with the following:

  • frameobj (Frame) – parent frame (or future parent frame)

Returns

Body object

Return type

Body

Note

body_dict have the following keys:

  • parts

  • center_part

  • angel_conn

  • connections

  • id

  • suppressed

  • pollen_score

  • tag (optional)

  • features (optional)

  • virtual (optional)

  • annotations (optional)

  • metadata (optional)

see Body constructor for more information about these keys.

Note

Frame object is used to have a two-way link between Frame and Body. Generally, frameobj is a new and empty frame that will be populated with the data from body_dict.

property metadata

get metadata dictionary

Returns

metdatda

Return type

dict

property next

Get the next body in the track. This is only work with tracks.

Warning

Not sure id new tracking support this linked-list track.

out_height = None

Class Attribute for out_height for plotting

out_width = None

Class Attribute for out_width for plotting

params()

Get body dictionary

Returns

return a dictionary of the body.

Return type

dict

Warning

For developers. If body has new attributes, these attributes should be manually code into this function to be able save and load bodies.

property parts

Get detected parts

Returns

detected parts

Return type

dict[list[tuple(x:int, y:int)]]

property pollen

Return if the body has pollen

Returns

return if is body with pollen

Return type

bool

Note

Pollen decision is based on self.pollen_score > Body.pollen_threshold

pollen_threshold = 0.5

Class Attribute for pollen_threshold this is used as self.pollen_score > Body.pollen_threshold

property prev

Get the previous body in the track. This is only work with tracks.

Warning

Not sure id new tracking support this linked-list track.

save(path, width=None, height=None, cX=None, cY=None, erase_tag=False)

Save body image

Parameters
  • path (str) – path to save the image

  • width (int, optional) – image width, defaults to None

  • height (int, optional) – image height, defaults to None

  • cX (int, optional) – x of the center point in the output rectangle of the body image, defaults to None

  • cY (int, optional) – y of the center point in the output rectangle of the body image, defaults to None

  • scale (float, optional) – scale of the body image, defaults to None

  • ignore_angle (bool, optional) – ignore angle normalization, defaults to None

  • erase_tag (bool, optional) – if body is a tagged bee then the tag will be erase from the image, defaults to False

scale = 1.0

Class Attribute for scale for plotting

set_id(i)

Set track id (body id)

Parameters

i (int) – body id

set_metadata(key, value)

Set metadata

Parameters
  • key (Any hashable (ideal str)) – name of the metadata field.

  • value (Any) – Value of metadata.

Note

Note that set_metadata can overwrite previous metadata.

property skeleton

Get skeleton

Returns

Skeleton connections (list of lines)

Return type

list[tuple(tuple(x:int, y:int))]

property skeleton_image

Get body image with skeleton overlay

Returns

body image with skeleton on top

Return type

numpy.ndarray

suppressed

Instance attribute to suppress body. Generally, use during tracking to remove double detections.

tag_erased_image()

Get tag erased image

Returns

return body image. If body is tagged then erase the tag.

Return type

numpy.ndarray

property tag_id

Tag id

Returns

None if is the body is not tagged

Return type

float

tag_image()

Return image

Returns

If body is tagged then return image of the Apriltag else return np.array([])

Return type

np.ndarray

property valid

Return if body is a valid

Returns

check if body is a valid body with the function defined on Body.valid_function().

Return type

bool

Tip

This is customizable, and be useful to filter bodies in multiple scenarios such as plotting or Frame.bodies

valid_function()

Class Attribute (function) for to decided what is a valid body

property video_name

Get video name

Returns

video name

Return type

str

width = 200

Class Attribute for width for plotting

y_offset = 0

Class Attribute for y_offset for Body.center()

Note

This was used to centralize the body center when there is not a center keypoint available. For example, in my case I used to move the center to the thorax using the neck keypoint as Body.center.

plotbee.body.parse_parts(parts)
plotbee.body.valid_fn(body)

Default Valid function Filters suppressed bodies and bodies with id = -1.

Parameters

body (Body) – body check

Returns

True if body is valid else False

Return type

bool

plotbee.events module

plotbee.events.track_classification(video, inside=300, outside=600, threshold=5, pollen_score='average', tag='mode')

plotbee.export module

plotbee.export.bodies2csv(video)
plotbee.export.body_annotation(body, keypoints, annotation_id, image_id, width=300, height=450)
plotbee.export.coco_file_init(keypoints, skeleton)
plotbee.export.convert_labelbee(video)
plotbee.export.decode_image(im)
plotbee.export.extract_annotations(video, width=300, height=450)
plotbee.export.extract_body_annotation(body)
plotbee.export.extract_frame_annotations(frame)
plotbee.export.extract_images(output_folder, video)
plotbee.export.get_body(skeleton, frame_obj, skeletons)
plotbee.export.get_frame(frame, skeletons)
plotbee.export.get_full_skeleton(video)
plotbee.export.get_images(track)
plotbee.export.get_track_frame(track, body)
plotbee.export.image_annotation(video_name, frame_id, image_id, width=2560, height=1440)
plotbee.export.parse_body_entry(body)
plotbee.export.parse_skeleton(skeleton)
plotbee.export.parse_skeletons(skeletons)
plotbee.export.parse_track_entry(track)
plotbee.export.parse_videos(videos)
plotbee.export.parts_annotations(body, keypoints)
plotbee.export.sleap2pb(sleap_json)
plotbee.export.tracks2csv(video)
plotbee.export.video2analysis(video)
plotbee.export.video2coco(video_fname, output_folder, image_extraction=False, width=300, height=450)
plotbee.export.video2labelbee(video_fname, output_fname)

plotbee.frame module

class plotbee.frame.Frame(bodies, frame_id, image=None, mapping=None, parts=None)

Bases: object

Frame object

Parameters
  • bodies (list[Body]) – list of beepose detection

  • frame_id (int) – frame id of the video

  • image (np.array, optional) – frame image., defaults to None

  • mapping (dict, optional) – Beepose connection or limbs predictions, defaults to None

  • parts (dict, optional) – Beepose keypoint prediction, defaults to None

Returns

return a Frame object

Return type

Frame

TRACK_DIRECTION = 'forward'

Set a default TRACK_DIRECTION for all Frame’s instances, default to “forward”

Note

This is a class attribute.

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'plotbee.frame', '__doc__': 'Frame object\n\n\n    :param bodies: list of beepose detection\n    :type bodies: list[Body]\n    :param frame_id: frame id of the video\n    :type frame_id: int\n    :param image: frame image., defaults to None\n    :type image: np.array, optional\n    :param mapping: Beepose connection or limbs predictions, defaults to None\n    :type mapping: dict, optional\n    :param parts: Beepose keypoint prediction, defaults to None\n    :type parts: dict, optional\n    :return: return a Frame object\n    :rtype: Frame\n    ', 'TRACK_DIRECTION': 'forward', '__init__': <function Frame.__init__>, 'set_video': <function Frame.set_video>, 'get_track': <function Frame.get_track>, 'id': <property object>, 'bodies': <property object>, 'valid_bodies': <property object>, 'delete_virtual_bodies': <function Frame.delete_virtual_bodies>, 'update': <function Frame.update>, 'video_name': <property object>, '_image': <function Frame._image>, 'draw_frame_image': <function Frame.draw_frame_image>, 'bbox_image': <function Frame.bbox_image>, 'skeleton_image': <property object>, 'track_image': <function Frame.track_image>, 'parts_image': <property object>, 'event_image': <property object>, 'image': <property object>, 'extract_patch': <function Frame.extract_patch>, '_extract_bodies_images': <staticmethod object>, 'bodies_images': <function Frame.bodies_images>, '__repr__': <function Frame.__repr__>, '__len__': <function Frame.__len__>, '__getitem__': <function Frame.__getitem__>, 'bodies_at_point': <function Frame.bodies_at_point>, 'save': <function Frame.save>, '__dict__': <attribute '__dict__' of 'Frame' objects>, '__weakref__': <attribute '__weakref__' of 'Frame' objects>, '__annotations__': {}})
__getitem__(index)

Get body by their ‘detection id’

Parameters

index (int) – index of the body in the bodies list

Returns

body with detection id in the frame

Return type

Body

Note

Note that up to now there is not a detection id explicitly coded. For now we are using the index in the bodies list.

__init__(bodies, frame_id, image=None, mapping=None, parts=None)

constructor method

Parameters
  • bodies (list[Body]) – list of beepose detection

  • frame_id (int) – frame id of the video

  • image (np.array, optional) – frame image., defaults to None

  • mapping (dict, optional) – Beepose connection or limbs predictions, defaults to None

  • parts (dict, optional) – Beepose keypoint prediction, defaults to None

__len__()

Return the number of detection in the frame

Returns

number of detection in the frame

Return type

int

__module__ = 'plotbee.frame'
__repr__()

Print frame

Returns

shows frame id and bodies in the frame

Return type

str

__weakref__

list of weak references to the object (if defined)

static _extract_bodies_images(image, frame_data, width=None, height=None, cX=None, cY=None, scale=None, suppression=False, min_parts=- 1)

Extract bodies images from frame image

Parameters
  • image (numpy.ndarray) – image (ideally should be frame image)

  • frame_data (Frame) – frame object

  • width (int, optional) – body image width, defaults to None

  • height (int, optional) – body image height, defaults to None

  • cX (int, optional) – x of the center point in the output rectangle of the body image, defaults to None

  • cY (int, optional) – y of the center point in the output rectangle of the body image, defaults to None

  • scale (float, optional) – scale of the body image, defaults to None

  • suppression (bool, optional) – if True will not return body images from suppressed bodies, defaults to False

  • min_parts (int, optional) – this functions only returns bodies that len(body) >= min_parts, defaults to -1

Returns

list of bodies images

Return type

list[numpy.ndarray]

_image(**kwargs)

Get Frame’s image with draw_frame_image() options

Returns

Frame image with options ()

Return type

numpy.ndarray

bbox_image(idtext=False, suppression=False)

Get frame image with bounding boxes

Parameters
  • idtext (bool) – if True shows the id on the image, default to False

  • suppression (bool, optional) – if True not show suppressed bodies, defaults to False

Returns

image with bounding boxes

Return type

numpy.ndarray

property bodies

Get all bodies in the frame.

Returns

all bodies in the frame

Return type

list[Body]

bodies_at_point(p, silent=False)

Returns bodies that intersect the point p

Parameters
  • p (tuple(int, int)) – point to intersec

  • silent (bool, optional) – if True will not show warnings, defaults to False

Returns

bodies that intersect the point p

Return type

list[Body]

bodies_images()

Return bodies images from frame image

Returns

list of images of bodies

Return type

list[numpy.ndarray]

delete_virtual_bodies()

Remove all virtual bodies in the frame

draw_frame_image(frame_image, skeleton=False, bbox=False, tracks=False, events=False, min_parts=- 1, track_direction='forward', idtext=False, fontScale=1.5, fontThickness=3, thickness=7)

draws options in frame image

Parameters
  • frame_image (numpy.ndarray) – Frame image

  • skeleton (bool, optional) – if True draws frame’s skeletons on the frame_image, defaults to False

  • bbox (bool, optional) – if True draws frame’s detections bounding boxes on the frame_image, defaults to False

  • tracks (bool, optional) – if True draws frame’s detections tracks on the frame_image, defaults to False

  • events (bool, optional) – if True draws frame’s detections events on the frame_image, defaults to False (see note below)

  • min_parts (int, optional) – this functions only draws bodies that len(body) >= min_parts, defaults to -1

  • track_direction (str, optional) – track direction can be “full” show the whole path of the track, “backward” only show tracks from the current and the previous frames or “forward” only show tracks from the current and the next frames, defaults to “forward”

  • idtext (bool, optional) – if True shows track id on the image, defaults to False

  • fontScale (float, optional) – idtext font scale, defaults to 1.5

  • fontThickness (int, optional) – idtext fontsize, defaults to 3

  • thickness (int, optional) – bounding box line thickness, defaults to 7

Returns

image with requested options

Return type

numpy.ndarray

Note

Events are tracks classified as entrance, exit or pollen (this shows a tracks with color)

property event_image

Get frame image with events

Returns

frame image with events

Return type

numpy.ndarray

Note

Events are tracks classified as entrance, exit or pollen (this shows a tracks with color)

extract_patch(x, y, angle=0, width=160, height=320, cX=None, cY=None)

Extract a rotated path from frame

Parameters
  • x (int) – x of the center point in the input rectangle

  • y (int) – y of the center point in the input rectangle

  • angle (float, optional) – angle in degrees, defaults to 0

  • width (int, optional) – width of the patch rectagle,, defaults to 160

  • height (int, optional) – height of the patch rectagle, defaults to 320

  • cX (int, optional) – x of the center point in the output rectangle, defaults to None

  • cY (int, optional) – y of the center point in the output rectangle, defaults to None

Returns

image path

Return type

numpy.ndarray

get_track(body)

Get track from a body in the same video.

Parameters

body (Body) – The body to find the tracks.

Returns

returns the body’s track.

Return type

Track

property id

Get frame id

Returns

frame id

Return type

int

property image

Get frame image

Returns

frame image

Return type

numpy.ndarray

property parts_image

Get frame image with keypoints (parts)

Returns

frame image with keypoints

Return type

numpy.ndarray

save(folder, skeleton=True, bbox=True, tracks=False, events=True, min_parts=- 1, idtext=False, fontScale=2.5, fontThickness=8)

Save image with requested option on <folder>/{frame_id:09d}.jpg

Parameters
  • folder (str) – folder to save the image

  • skeleton (bool, optional) – if True draws frame’s skeletons on the frame_image, defaults to False

  • bbox (bool, optional) – if True draws frame’s detections bounding boxes on the frame_image, defaults to False

  • tracks (bool, optional) – if True draws frame’s detections tracks on the frame_image, defaults to False

  • events (bool, optional) – if True draws frame’s detections events on the frame_image, defaults to False

  • min_parts (int, optional) – this functions only draws bodies that len(body) >= min_parts, defaults to -1

  • idtext (bool, optional) – if True shows track id on the image, defaults to False

  • fontScale (float, optional) – idtext font scale, defaults to 1.5

  • fontThickness (int, optional) – idtext fontsize, defaults to 3

  • thickness (int, optional) – bounding box line thickness, defaults to 7

Note

This function was mean to run in parrallel or concurrent with other frames. This approach didn’t result on the best approach therefore, this is not used anymore.

set_video(video)

set Frame’s parent Video object

Parameters

video (Video) – Video object in which this frame object belong

Note

This was implemented to have a two-way link from video to frame.

property skeleton_image

Get frame image with skeletons

Returns

image with skeletons

Return type

numpy.ndarray

track_image(direction=None)

Get frame image with tracks

Parameters

direction (str, optional) – track direction can be “full” show the whole path of the track, “backward” only show tracks from the current and the previous frames or “forward” only show tracks from the current and the next frames, defaults to “forward”, defaults to None

Returns

frame image with tracks

Return type

numpy.ndarray

update(bodies)

Add new bodies to the frame

Parameters

bodies (list[Body]) – new bodies to add

property valid_bodies

Get valid bodies

Returns

Valid bodies in the frame.

Return type

list[Body]

Note

A valid body is a body that is not supressed (suppressed()). Generally, this is used internally for tracking.

property video_name

get video filename

Returns

video_name from the parent video

Return type

str

plotbee.pollen module

plotbee.sort module

SORT: A Simple, Online and Realtime Tracker Copyright (C) 2016-2020 Alex Bewley alex@bewley.ai This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

class plotbee.sort.KalmanBoxTracker(bbox)

Bases: object

This class represents the internal state of individual tracked objects observed as bbox.

count = 0
get_state()

Returns the current bounding box estimate.

predict()

Advances the state vector and returns the predicted bounding box estimate.

update(bbox)

Updates the state vector with observed bbox.

class plotbee.sort.Sort(max_age=1, min_hits=3)

Bases: object

update(dets=array([], shape=(0, 5), dtype=float64))
Params:

dets - a numpy array of detections in the format [[x1,y1,x2,y2,score],[x1,y1,x2,y2,score],…]

Requires: this method must be called once for each frame even with empty detections (use np.empty((0, 5)) for frames without detections). Returns the a similar array, where the last column is the object ID. NOTE: The number of objects returned may differ from the number of detections provided.

plotbee.sort.associate_detections_to_trackers(detections, trackers, iou_threshold=0.3)

Assigns detections to tracked object (both represented as bounding boxes) Returns 3 lists of matches, unmatched_detections and unmatched_trackers

plotbee.sort.convert_bbox_to_z(bbox)
Takes a bounding box in the form [x1,y1,x2,y2] and returns z in the form

[x,y,s,r] where x,y is the centre of the box and s is the scale/area and r is the aspect ratio

plotbee.sort.convert_x_to_bbox(x, score=None)
Takes a bounding box in the centre form [x,y,s,r] and returns it in the form

[x1,y1,x2,y2] where x1,y1 is the top left and x2,y2 is the bottom right

plotbee.sort.iou(bb_test, bb_gt)

Computes IUO between two bboxes in the form [x1,y1,x2,y2]

plotbee.sort.jit(func)
plotbee.sort.linear_assignment(cost_matrix)
plotbee.sort.parse_args()

Parse input arguments.

plotbee.tag module

plotbee.tag.detect_tags(det, image)
plotbee.tag.detect_tags_on_frame(det, frame)
plotbee.tag.detect_tags_on_video(video, max_workers=5)
plotbee.tag.detect_tags_on_video_frame_level(video, max_workers=5)
plotbee.tag.dist(a, b)
plotbee.tag.filter_corners(detections)
plotbee.tag.get_tag_image()
plotbee.tag.match_tag2body(frame, tag, min_dist=50)
plotbee.tag.requires_apriltag(func)
plotbee.tag.tagDetector()

plotbee.tagged module

class plotbee.tagged.TagVideoCollection(video_collection)

Bases: object

DataFrame()
bodies()
export(folder)
filter(func)
get_body(i)
get_occurence(video_name, frame_id, tag_id)
json()
classmethod load(video_folder, json_path)
save(path)
select(df)
plotbee.tagged.days_histogram(df, figsize=(10, 20), ax=None)
plotbee.tagged.hour_histogram(df, figsize=(10, 20), ax=None)
plotbee.tagged.parse_name(name)

plotbee.track module

class plotbee.track.Track(body)

Bases: object

property end
property event
params()
property pollen
property start
property tag
property tag_id
property track_shape

plotbee.tracking module

class plotbee.tracking.IntegerIDGen

Bases: object

plotbee.tracking.body_cbox_overlaping_ratio(body_a, body_b)
plotbee.tracking.body_distance(body_a, body_b)
plotbee.tracking.cost_matrix_tracks_skeleton(frame, next_frame, threshold)
plotbee.tracking.cost_matrix_tracks_vectorized(ground_t, detections, threshold)
plotbee.tracking.hungarian_tracking(video, cost=200, nms_overlap_fraction=0.6)
plotbee.tracking.hungarian_tracking_with_prediction(video, max_dist=100, part='2', nms_min_dist=50, max_step=4, min_track_length=1, decay_alpha=0.5, debug=False, progress=True)

This function track detections in time by matching prediction with detections using the hungarian algorithm. It is expecting to receive an instance of detections. Please check documentation for data structure.

Inputs:
  • video : Video datastructure from which to extract the detections

  • max_dist : Maximum euclidean distance allowed

NOT USED - part : Id of the part to use as reference keypoint in a body (default thorax ‘2’) NOT USED - nms_min_dist : Distance below which non-maximum keypoints are suppressed - max_step : largest frame step since last observed detection (1 does not allow any gap) - min_track_length : minimum number of nodes to keep a track (1 keep all tracks) - decay_alpha : exponential decay for velocity estimation

Return:
  • track_raw data structure indexed as track_raw[trackid][fieldname] where fieldname in startframe,endframe,data… and track_raw[trackid][‘data’][frame] is a dict with fields detid, pos,score,vel,cost, predictpos,predictvel

plotbee.tracking.matchIds(bboxes, predbboxes)
plotbee.tracking.nms_euclid(det, min_dist)

det is Nx3 array, each row [x,y,score,…]

return bool vector, True if keep, False if suppress

plotbee.tracking.non_max_supression(frame, overlapThreshold)

This function filter out overlaping bodies using a Overlapping threshold.

plotbee.tracking.non_max_supression_video(video, overlapThreshold)
plotbee.tracking.sort_tracking(video, bbox=200, nms_overlap_fraction=0.6)

plotbee.utils module

plotbee.utils.angleBetweenPoints(p1, p2)
plotbee.utils.bound_box_points(p)
plotbee.utils.find_connections(body, detsByLimbs)
plotbee.utils.getRotationMatrix(image_size, x, y, angle, w, h, cX=None, cY=None, scale=1.0)
plotbee.utils.get_fname(path)
plotbee.utils.hash1(i)
plotbee.utils.hash2(i)
plotbee.utils.hash3(i)
plotbee.utils.id2color(i)
plotbee.utils.plot_bounding_box(frame, p, color)
plotbee.utils.pointInRotatedBbox(p, center, angle, width, height)
plotbee.utils.read_json(path)
plotbee.utils.rescale_image(image, rescale_factor=4)
plotbee.utils.rotate_around_point(xy, radians, origin=(0, 0))

Rotate a point around a given point.

I call this the “high performance” version since we’re caching some values that are needed >1 time. It’s less readable than the previous function but it’s faster.

plotbee.utils.rotate_bound2(image, x, y, angle, w, h, cX=None, cY=None, scale=1.0)
plotbee.utils.rotatedBoundBoxPoints(p, angle, width, height)
plotbee.utils.save_json(path, data)
plotbee.utils.trackevent2color(track)

plotbee.video module

class plotbee.video.Video(frames, tracks, config, start=0, stop=None, step=1)

Bases: object

append(video)

Concatenate a video at the end

Parameters

video (Video) – Video to concatenate

clear_ids()

Clear track ids of all bodies in the video.

clear_tags()

Clear tags for all body in the video.

property config

Get video config file

Returns

config file

Return type

dict

events_counter()

Count Events

Returns

frequecy per event

Return type

dict

export(folder, skeleton=True, bbox=True, tracks=True, events=False, min_parts=- 1, max_workers=5, idtext=False, fontScale=2.5, fontThickness=8)

Export video images with plotting options on folder.

Parameters
  • folder (str) – folder to save the frame images

  • skeleton (bool, optional) – if True images will show the predicted skeleton, defaults to True

  • bbox (bool, optional) – if True images will show the bounding boxes of the predicted bodies, defaults to True

  • tracks (bool, optional) – if True images will show the tracks of the predicted bodies, defaults to True

  • events (bool, optional) – if True draws frame’s detections events on the frame_image, defaults to False

  • min_parts (int, optional) – this functions only draws bodies that len(body) >= min_parts, defaults to -1

  • idtext (bool, optional) – if True shows track id on the image, defaults to False

  • fontScale (float, optional) – idtext font scale, defaults to 1.5

  • fontThickness (int, optional) – idtext fontsize, defaults to 3

  • thickness (int, optional:param events: , defaults to False) – bounding box line thickness, defaults to 7

  • max_workers (int, optional) – workers to process this task in parallel, defaults to 5

export_bodies(folder, width=None, height=None, cX=None, cY=None, workers=5)

Export bodies and body images into a JSON format and image folder

Parameters
  • folder (str) – folder to save the exported json file and images

  • width (int, optional) – width of the patch rectagle,, defaults to 160

  • height (int, optional) – height of the patch rectagle, defaults to 320

  • cX (int, optional) – x of the center point in the output rectangle, defaults to None

  • cY (int, optional) – y of the center point in the output rectangle, defaults to None

  • workers (int, optional) – amount of workers to process this task in parallel, defaults to 5

export_pollen(output_folder, limit=None, sorted_scores=False)

Export pollen detection dataset

Parameters
  • output_folder (str) – folder to save the dataset

  • limit (int, optional) – set a limit of detection to export, defaults to None

  • sorted_scores (bool, optional) – if True the pollen score will be sorted and take the the top limit//2 and the bottom limit//2 to export, defaults to False

Note

This function was design to provide aditional training data for pollen classification in active learning fashion.

export_tagged(output_folder, save_images=True)

Export all tagged bodies in a JSON file and optionally all the body images.

Parameters
  • output_folder (str) – folder to save the images and json file

  • save_images (bool, optional) – if True will export tagged bodies images, defaults to True

Tip

This function will serve to create a dataset of tagged bees.

frame_image(index)

Get frame image at index position

Parameters

index (int) – index of the request frame image

Returns

return image of the requested frame

Return type

numpy.ndarray

property frames

Get a list of frames

Returns

list of video frames

Return type

list[Frame]

classmethod from_config(config, load_image=False)

Video Constructor from config dict (this is used to import beepose format file)

Parameters
  • config (dict) – A dictionary containing the beepose files path - DETECTIONS_PATH path to detection file - VIDEO_PATH path to video - TRACK_PATH path to tracks optional - ID_TRACK_PATH path to the ids of tracks optional

  • load_image (bool, optional) – if True will load images from the video, defaults to False

Returns

Video object

Return type

Video

Warning

load_image = True is not recommended for large videos. This option will result in slower performance and high memory usage.

Warning

This is old, generally Video.load is used.

classmethod from_detections(detections, video_path=None, load_images=False)

Beepose dictionary constructor

Parameters
  • detections (dict) – Beepose dictionary with detections

  • video_path (str, optional) – video path, defaults to None

  • load_images (bool, optional) – if True images will load at loading time, defaults to False

Returns

Video Object

Return type

Video

Note

This function is mostly internal. This function runs on beepose implementation to generate plotbee output.

get_frame_with_untracked_body()

Get the first frame with an untracked body

Returns

First frame that at least has one detection without a tracking id

Return type

Frame

Note

This was implemented to help to annotate bodies for a track evaluation.

get_video_stream(start=None, stop=None, step=None)

Get video stream

Parameters
  • start (int, optional) – frame to start, defaults to None

  • stop (int, optional) – frame to stop, defaults to None

  • step (int, optional) – frame step, defaults to None

Returns

An “efficient” VideoCapture Wrapper

Return type

VideoCaptureWrapper

hungarian_tracking(predictive=True, **kwargs)

Hungarian Tracking

Parameters

predictive (bool, optional) – if True in case that a body was misdetected at frame t+1 then this will be filled with a virtual detection in order to continue with the track, defaults to True

json()

Export Video to JSON format

Returns

Video as JSON format

Return type

dict

classmethod load(json_path)

JSON Constructor

Parameters

json_path (str) – plotbee file path. Normally, with suffix “_skeleton.json”

Returns

Video Object

Return type

Video

load_tags(tags_file, virtual=False)

Load tags from Tag multi-file format

Parameters
  • tags_file (str) – path to the tag file to load

  • virtual (bool, optional) – if True will attach tags to virtual body, defaults to False

load_video(video_file)

Set the video path to load images

Parameters

video_file (str) – path to the video file

Note

load_video is critical for all plotting. To load the frame image it is important that Video knows the location to load the frame image.

non_max_supression(nms_overlap_fraction=0.6)

Non maximum supression will supress all the bodies detection that hava an overlap greater or equal to nms_overlap_fraction to remove potential detection duplicates.

Parameters

nms_overlap_fraction (float, optional) – amount of overlaping fraction to supress a detection, defaults to 0.6

process_pollen(model_path, weights=None, workers=4, gpus=['1', '0'], model_size=2048, scale=1.0)

Process polle

Parameters
  • model_path (str) – path to the pollen detection model

  • weights (str, optional) – path to the weights of the model, defaults to None

  • workers (int, optional) – amount of workers to process this task in parallel, defaults to 4

  • gpus (list, optional) – which GPU this task will use, defaults to [“1”, “0”]

  • model_size (int, optional) – size of the model, defaults to 2048

  • scale (float, optional) – upsampling (resize) scale of the body image (scale > 1.0 => zoom), defaults to 1.0

save(path)

Save video as JSON

Parameters

path (str) – path to save the video data

sort_tracking(bbox=200, nms_overlap_fraction=0.6)

SORT tracking

Parameters
  • bbox (int, optional) – the size of the tracking box, defaults to 200

  • nms_overlap_fraction (float, optional) – amount of overlaping fraction to supress a detection, defaults to 0.6

tag_detection(max_workers=5, frame_level=False)

Tag detection of the video

Parameters
  • max_workers (int, optional) – amount of worker to perform the task in parallel, defaults to 5

  • frame_level (bool, optional) – if True the tag will be detected at frame level and then match the close body to the detected tag. if False the tag detection will be perform to each body image on the video, defaults to False

tagged()

Get all tagged body.

Returns

list of body with tags detected

Return type

list[Body]

track_clasification(**kwargs)

Track Classification This will classify all the tracks in the video.

property tracks

Get tracks

Returns

video tracks

Return type

dict

property video_name

Get video name

Returns

video name

Return type

str

property video_path

Get video path

Returns

video path

Return type

str

plotbee.video.create_bodies_from_mapping(tracking_limb, tracking_part, mapping, tracks, id_tracks, frame)
plotbee.video.dist(a, b)
plotbee.video.divide_video(video, fname, N)
plotbee.video.find_bodyid(body_point, tracks, id_tracks, frame_id)
plotbee.video.find_connections(point, part, mappings)
plotbee.video.frames_from_detections(detections, tracks, id_tracks, tracking_limb=(1, 3), tracking_part=3, video_path=None, load_image=False)

Create Video from Ivan’s detections and tracks JSON objects

plotbee.video.get_mappings_by_limb(maps)
plotbee.video.get_video(video_path, start=0, end=inf, step=1)
plotbee.video.image_from_video(video_path, frameid)
plotbee.video.load_json_model(json_file)
plotbee.video.load_pollen_model(model_path)
plotbee.video.match_tags(frame, tag_list, virtual=False, th_dist=50)
plotbee.video.merge_videos(video_names)
plotbee.video.point_in_frame(track_id, id_tracks, frame_id)
plotbee.video.preprocess_input(image, rescale_factor=1)
plotbee.video.process_frame(image, frame, img_folder, file_format)
plotbee.video.process_frame_consumer(video_path, q, lock, pbar)
plotbee.video.process_pollen(video, model_path, model_weights, workers=4, gpus=['1', '0'], model_size=2048, scale=1.0)
plotbee.video.process_video(frames, video_path, start, end, img_folder, file_format, lock, pbar)
plotbee.video.tfv2_pollen_classifier(video_filename, model_path, weigths_path, gpu, gpu_fraction, model_size=2048, scale=1.0)

plotbee.video_wrapper module

class plotbee.video_wrapper.VideoCaptureWrapper(video_path, start=0, stop=inf, step=1)

Bases: object

read()
release()

plotbee.videoplotter module

class plotbee.videoplotter.VideoAnimation(video, skeleton=False, bbox=True, tracks=False, events=False, min_parts=- 1, track_direction='forward', idtext=False, fontScale=2.5, fontThickness=8, rescale_factor=4)

Bases: object

get_animate(video_stream, pbar)
get_init()
save(filename, fps=20)
show()
plotbee.videoplotter.bbox(frame, idtext=False, ax=None, suppression=False)
plotbee.videoplotter.bbox_drawer(frame_image, body, idtext=False, idpos='avg', fontScale=1.5, fontThickness=3, linethick=7)
plotbee.videoplotter.bodies_bbox_drawer(frame_image, bodies, **kwargs)
plotbee.videoplotter.bodies_event_track_drawer(frame_image, bodies, **kwargs)
plotbee.videoplotter.bodies_skeleton_drawer(frame_image, bodies, **kwargs)
plotbee.videoplotter.bodies_track_drawer(frame_image, bodies, **kwargs)
plotbee.videoplotter.contact_sheet(bee_list, save_path=None, cols=10)
plotbee.videoplotter.event_track_drawer(frame, body, track, thickness=3)
plotbee.videoplotter.events(frame)
plotbee.videoplotter.extract_body(frame, body, width=200, height=400, cX=None, cY=None, scale=1.0, ignore_angle=False)
plotbee.videoplotter.imshow(frame, **kwargs)
plotbee.videoplotter.parts(frame)
plotbee.videoplotter.parts_drawer(frame_image, parts_dict)
plotbee.videoplotter.plot(frame, skeleton=False, bbox=False, tracks=False, min_parts=5)
plotbee.videoplotter.skeleton(frame)
plotbee.videoplotter.skeleton_drawer(frame_image, body, idtext=False, thickness=7)
plotbee.videoplotter.tag_images(video, save_folder=None, black_listed_ids=[15, 16, 13])
plotbee.videoplotter.tagged_contact_sheet(bee_list, save_path=None, cols=10, bodies=True)
plotbee.videoplotter.track_drawer(frame, body, thickness=3, direction='forward')
plotbee.videoplotter.track_images(track, figsize=(10, 20))
plotbee.videoplotter.tracks(frame, direction='forward')

Module contents