Body Class
- 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- __dict__ = mappingproxy({'__module__': 'plotbee.body', 'y_offset': 0, 'width': 200, 'height': 400, 'scale': 1.0, 'out_width': None, 'out_height': None, 'cX': None, 'cY': None, 'ignore_angle': False, 'pollen_threshold': 0.5, 'valid_function': <function valid_fn>, 'load_body': <classmethod object>, '__init__': <function Body.__init__>, 'annotate': <function Body.annotate>, 'set_metadata': <function Body.set_metadata>, 'annotations': <property object>, 'metadata': <property object>, 'valid': <property object>, 'frameid': <property object>, 'tag_id': <property object>, 'video_name': <property object>, 'connections': <property object>, 'id': <property object>, 'parts': <property object>, 'center': <property object>, 'angle': <property object>, 'pollen': <property object>, '_image': <function Body._image>, 'image': <property object>, 'skeleton_image': <property object>, 'prev': <property object>, 'next': <property object>, 'set_id': <function Body.set_id>, 'cbox': <function Body.cbox>, 'boundingBox': <function Body.boundingBox>, 'skeleton': <property object>, '__len__': <function Body.__len__>, '__repr__': <function Body.__repr__>, 'save': <function Body.save>, 'info': <function Body.info>, 'tag_erased_image': <function Body.tag_erased_image>, 'tag_image': <function Body.tag_image>, 'params': <function Body.params>, '__dict__': <attribute '__dict__' of 'Body' objects>, '__weakref__': <attribute '__weakref__' of 'Body' objects>, '__doc__': None, '__annotations__': {}})
- __init__(parts, center, angle_conn, connections, frame, body_id=- 1, suppressed=False, pollen_score=0.0, tag=None, features=None, virtual=False, annotations={}, metadata={})
Default Constructor
- Parameters
parts (dict[list[tuple(x:int, y:int)]]) – detected parts
center (int) – part used for keypoint tracking
angle_conn (tuple(int, int)) – connection used to compute angle
connections (list[list[x:int, y:int]]) – predicted connection configuration, note this can be different for each body
frame (Frame) – Frame object which this body belongs
body_id (int, optional) – track_if if -1 the body do not have an id assigned, defaults to -1
suppressed (bool, optional) – True if this body is suppressed, defaults to False
pollen_score (float, optional) – pollen score predicted from a pollen detection model, defaults to 0.0
tag (dict, optional) – tag dictionary computed by apriltag, defaults to None
features (np.ndarray, optional) – identity features computed by a identity model, defaults to None
virtual (bool, optional) – True, if this body wasn not detected by beepose but detected by tracking, defaults to False
annotations (dict, optional) – annotations (key-value), defaults to dict()
metadata (dict, optional) – metadata (key-value), defaults to dict()
Note
The parts is a list of list of keypoints, if there is a case that a body has two detected keypoint of on part because a duplicate detection due to the skeleton association. Ideally, this list should contain the keypoints with more confidence first. I believe I never found a case for this, but the part attribute was left as this just in case.
- __len__()
Return the number of detected parts(not duplicates)
- Returns
number of detected parts
- Return type
int
- __module__ = 'plotbee.body'
- __repr__()
Print body info
- Returns
Show body id, parts points and if virtual
- Return type
str
- __weakref__
list of weak references to the object (if defined)
- _image(width=None, height=None, cX=None, cY=None, scale=None, ignore_angle=None, erase_tag=False)
Get a body image
- Parameters
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
- Returns
body image
- Return type
numpy.ndarray
Note
If the following params width, height, cX, cY, scale and ignore_angle are set to None, default values will be used. These default values are the class attributes Body.`param` (e.g. Body.width).
Tip
For a batch image extraction or plotting use class attributes to change image extarction at global (Body) level.
- 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
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)