Zones
- class Zone(name, points, image_width, image_height, description='', **kwargs)
A region of interest in a static view.
- Parameters:
name (
str
) – The name for the zone.points (
List
[Tuple
[int
,int
]]) – The coordinates of the zone.image_width (
int
) – The width of the image that was used to generate the zone.image_height (
int
) – The height of the image that was used to generate the zone.description (
str
) – A short description of the zone.
- classmethod from_bounding_box(name, box, image_width, image_height, description='')
Create a
Zone
from aBoundingBox
.- Parameters:
name (
str
) – The name for the zone.box (
BoundingBox
) – A bounding box to be used to generate a zone.image_width (
int
) – The width of the image that was used to generate the zone.image_height (
int
) – The height of the image that was used to generate the zone.description (
str
) – A short description of the zone.
- Return type:
- property mask: ndarray
The binary mask representing the zone.
This is a numpy array of 0 and 1 with data type np.uint8. It’s dimensions match the width and height of the image it was generated with.
- to_bounding_box()
Get a
BoundingBox
representing the zone.A box that fits the outermost edges of the Zone will be generated.
- Return type:
- Returns:
A
BoundingBox
representing theZone
- update_image_dimensions(image_width=None, image_height=None)
Update the dimensions of the
ZoneList
and all includedZone
objects.
- check_prediction_within_zone(prediction, **kwargs)
Check whether a prediction is inside the
Zone
.- Parameters:
prediction (
ObjectDetectionPrediction
) – The prediction to check for zone affiliation.- Return type:
- Returns:
True if the prediction is in the
Zone
, and False otherwise.
- get_predictions_in_zone(results, **kwargs)
Get the predictions that are within this zone.
- Parameters:
results (
ObjectDetectionResults
) – TheObjectDetectionResults
to check against the given zone.- Return type:
- Returns:
A :class:
ObjectDetectionResults
containing predictions that are within this zone
- get_tracked_objects_in_zone(objects)
Get the tracked objects that are within this zone.
- Parameters:
results – The
TrackingResults
to check against the given zone.- Return type:
- Returns:
A
TrackingResults
containing predictions that are within this zone.
- compute_prediction_overlap_with_zone(prediction)
Compute the fraction of prediction box which is overlapped by the Zone.
- Parameters:
prediction (
ObjectDetectionPrediction
) – The prediction to compute overlap.- Return type:
- Returns:
A value [0.0, 1.0] indicating the fraction of prediction box which is overlapped by the Zone.
- class ZoneList(zones, image_width, image_height)
A managed list of
Zone
objects.Work with regions of interest in your applications. Each
Zone
must have a unique name and they all must have matching image dimensions.Typical usage:
my_zones = edgeiq.ZoneList.from_config_file("zone_config.json") <get image> results = obj_detect.detect_objects(image, confidence_level=.5) image = edgeiq.markup_image( image, results.predictions, colors=obj_detect.colors) obj_detect.publish_analytics(zone_detect_results) image = my_zones.markup_image_with_zones( image, fill_zones=True, color=(255, 0, 0))
- Parameters:
- Raises:
ValueError if zones are invalid (duplicate name or mismatching image dimensions)
- classmethod from_config_file(filepath)
Create
ZoneList
from a Zone Creator configuration file.The Zone Creator tools is available with the alwaysAI CLI.
- property alpha: float
Transparency of the filled
Zone
objects, if the fill_zones option is selected.The closer alpha is to 1.0, the more opaque the overlay will be. Similarly, the closer alpha is to 0.0, the more transparent the overlay will appear.
- update_image_dimensions(image_width=None, image_height=None)
Update the dimensions of the
ZoneList
and all includedZone
objects.
- get_zones_for_prediction(prediction, **kwargs)
Get the
Zone
objects that this prediction is currently within.- Parameters:
prediction (
ObjectDetectionPrediction
) – The prediction to check for associatedZone
objects.- Return type:
- Returns:
A
ZoneList
containingZone
objects that this prediction is currently within.
- get_zone_for_prediction(prediction, **kwargs)
Get the
Zone
object that this prediction is currently within. If there are intersecting zones the zone with the higher index is returned. Returns None if no zone is present- Parameters:
prediction (
ObjectDetectionPrediction
) – The prediction to check for associatedZone
object.- Return type:
- Returns:
A
Zone
object that this prediction is currently within.
- get_predictions_in_zone(results, zone_name, **kwargs)
Get the predictions that are within the given zone.
- Parameters:
results (
ObjectDetectionResults
) – TheObjectDetectionResults
to check against the given zone.zone_name (
str
) – The name of zone to check results against.
- Return type:
- Returns:
A :class:
ObjectDetectionResults
containing predictions that are within the given zone.- Raises:
ValueError if the given zone name doesn’t match a zone.
- get_tracked_objects_in_zone(results, zone_name)
Get the tracked objects that are within the given zone.
- Parameters:
results (
TrackingResults
) – TheTrackingResults
to check against the given zone.zone_name (
str
) – The name of zone to check results against.
- Return type:
- Returns:
A
TrackingResults
containing predictions that are within the given zone.- Raises:
ValueError if the given zone name doesn’t match a zone.
- create_sub_zone_list(zone_names)
- markup_image_with_zones(image, show_labels=True, show_boundaries=True, fill_zones=False, line_thickness=2, font_size=0.5, font_thickness=2, text_box_padding=10, text_box_corner_radius=0, text_alignment=('left', 'top'), text_box_position=('left', 'top'))
Mark all zones on the given input image.
- Parameters:
frame – The image to mark up.
show_boundaries (
bool
) – True ifZone
boundaries should be drawn.fill_zones (
bool
) – True ifZone
objects should have a transparent overlay.color – The color to draw the
Zone
boundaries in.line_thickness (
int
) – The boundary thickness.font_size (
float
) – The font size to use in marking up the labels.font_thickness (
int
) – The font thickness to use in marking up the labels. size.text_box_padding (
int
) – The padding around the text in each text box.text_box_corner_radius (
int
) – The corner radius for the text boxes.text_alignment (
Tuple
[Literal
['left'
,'center'
,'right'
],Literal
['top'
,'middle'
,'bottom'
]]) – Specifies the alignment of the text in reference to the origin point (x, y). Accepts a tuple of horizontal (‘left’, ‘center’, ‘right’) and vertical (‘top’, ‘middle’, ‘bottom’) alignment literals.text_box_position (
Union
[Tuple
[Literal
['left'
,'center'
,'right'
],Literal
['top'
,'middle'
,'bottom'
]],Tuple
[int
,int
]]) – Defines the position of the text box’s reference point relative to the zone box. Can either be a tuple of alignment literals (horizontal, vertical) for automatic positioning, or a tuple of integers (offset_x, offset_y) specifying a custom offset from the center of the bounding box.
- Return type:
- Returns:
The marked-up image.
Note: fill_zones is time-intensive. fill_zones = True will generate the zone mask upon first call.