Frame Class

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.

__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