babysister.drawer module

Drawing routines

babysister.drawer.create_unique_color_float(tag, hue_step=0.41)

Create a unique RGB color code for a given track id (tag).

The color code is generated in HSV color space by moving along the hue angle and gradually changing the saturation.

Parameters:
  • tag (int) – The unique target identifying tag.
  • hue_step (float) – Difference between two neighboring color codes in HSV space (more specifically, the distance in hue channel).
Returns:

RGB color code in range [0, 1].

Return type:

(float, float, float)

babysister.drawer.create_unique_color_uchar(tag, hue_step=0.41)

Create a unique RGB color code for a given track id (tag).

The color code is generated in HSV color space by moving along the hue angle and gradually changing the saturation.

Parameters:
  • tag (int) – The unique target identifying tag.
  • hue_step (float) – Difference between two neighboring color codes in HSV space (more specifically, the distance in hue channel).
Returns:

RGB color code in range [0, 255].

Return type:

(int, int, int)

babysister.drawer.draw_detection(im, box, score, label, classes, do_show_class=True, box_color=None, txt_color=(255, 255, 255), fontFace=0, fontScale=0.35, fontThickness=1, boxThickness=2)

Draw detections.

Parameters:
  • im (ndarray) – image to draw to.
  • box (list of int) – box coordinate in format [x0, y0, x1, y1].
  • score (float) – confidence score.
  • label (int) – label index.
  • classes (dict) – labels data {id: name}.
  • bg_color (int, list of 3 int) – Background color RGB code.
  • txt_color (int, list of 3 int) – Text color RGB code.
  • fontFace – OpenCV Font type.
  • fontScale (float) – Font scale factor that is multiplied by the font-specific base size.
  • fontThickness (int) – Thickness of the lines used to draw text.
babysister.drawer.draw_roi(im, roi, n_detected_objs, box_color=(0, 0, 0), txt_color=(255, 255, 255), fontFace=0, fontScale=0.35, fontThickness=1, boxThickness=2)

Draw ROI.

Parameters:
  • im (ndarray) – image to draw to.
  • roi (dict) – ROI data with keys [“id”, “x”, “y”, “w”, “h”].
  • bg_color (int, list of 3 int) – Background color RGB code.
  • txt_color (int, list of 3 int) – Text color RGB code.
  • fontFace – OpenCV Font type.
  • fontScale (float) – Font scale factor that is multiplied by the font-specific base size.
  • fontThickness (int) – Thickness of the lines used to draw text.
babysister.drawer.draw_tracking(im, track, box_color=None, txt_color=(255, 255, 255), fontFace=0, fontScale=0.35, fontThickness=1, boxThickness=2)

Draw tracking.

Parameters:
  • im (ndarray) – image to draw to.
  • track (ndarray) – tracking data in format [[x0,y0,x1,y1,id], …]
  • bg_color (int, list of 3 int) – Background color RGB code.
  • txt_color (int, list of 3 int) – Text color RGB code.
  • fontFace – OpenCV Font type.
  • fontScale (float) – Font scale factor that is multiplied by the font-specific base size.
  • fontThickness (int) – Thickness of the lines used to draw text.
babysister.drawer.put_line_bg(im, line, top_left, bg_color=(0, 0, 0), txt_color=(255, 255, 255), fontFace=0, fontScale=0.35, fontThickness=1)

Put a line of text with background.

Parameters:
  • im (ndarray) – image to draw to.
  • line (str) – a line of text.
  • top_left (list of 2 int) – top_left of text box.
  • bg_color (int, list of 3 int) – Background color RGB code.
  • txt_color (int, list of 3 int) – Text color RGB code.
  • fontFace – OpenCV Font type.
  • fontScale (float) – Font scale factor that is multiplied by the font-specific base size.
  • fontThickness (int) – Thickness of the lines used to draw text.
Returns:

(w, h) is size of text box. baseLine is y-coordinate of the baseline wrt the bottom-most text point.

Return type:

((w, h), baseLine)

babysister.drawer.put_lines_bg(im, lines, top_left, bg_color=(0, 0, 0), txt_color=(255, 255, 255), fontFace=0, fontScale=0.35, fontThickness=1)

Put lines of text with background.

Parameters:
  • im (ndarray) – image to draw to.
  • line (list of str) – lines of text.
  • top_left (list of 2 int) – top_left of text box.
  • bg_color (int, list of 3 int) – Background color RGB code.
  • txt_color (int, list of 3 int) – Text color RGB code.
  • fontFace – OpenCV Font type.
  • fontScale (float) – Font scale factor that is multiplied by the font-specific base size.
  • fontThickness (int) – Thickness of the lines used to draw text.
Returns:

(w, h) is size of bottom-most text box. baseLine is y-coordinate of the baseline wrt the bottom-most text point.

Return type:

((w, h), baseLine)