Zones¶
-
load_zones_from_config
(filepath)¶ Takes a configuration file, as generated by the Zone Creator tool, as input. Returns a dictionary of
Zone
names andZone
objects, as well as the width and height ofZone
objects from the configuration. This dictionary can be used with theset_zones()
when creating a newZoneList
instance.
-
create_zone_from_bounding_box
(bounding_box, name='', description='', img_width=None, img_height=None)¶ Returns a
Zone
generated from the inputBoundingBox
.- Parameters
bounding_box (
BoundingBox
) – The box to generate aZone
for.name (string) – The name for the new
Zone
.description (string) – The description for the new
Zone
.width (int) – The width of the image that was used to generate the
Zone
.height (int) – The height of the image that was used to generate the
Zone
.
- Returns
a
Zone
with ZoneType.BOX.
-
create_bounding_box_from_zone
(zone)¶ Returns a
BoundingBox
generated from the inputZone
. If the zone_type is ZoneType.POLYGON, a box that fits the outermost edges will be generated.- Parameters
- Returns
the generated
BoundingBox
.
-
convert_polygon_to_box_zone
(zone)¶ Creates a new
Zone
with all of the attributes of the inputZone
, with ZoneType.BOX, and which fits the outermost edges of the inputZone
.
-
class
Zone
(name='', points=None, type=None, description='', width=None, height=None)¶ Class representing a region of interest in a static view.
-
property
width
¶ The width of the image that was used to generate the Zone.
- Type
int
-
property
height
¶ The height of the image that was used to generate the Zone.
- Type
int
-
property
zone_mask
¶ The binary mask representing the Zone within the associated width and height of the static image view it was generated with.
- Type
numpy array
-
property
name
¶ The Zone name.
- Type
string
-
property
points
¶ The Zone coordinates.
- Type
list of [x, y] coordinates
-
property
description
¶ The description for the Zone.
- Type
string
-
generate_scaled_zone_points
(width, height)¶ Generates a new set of
Zone
points scaled to the input dimensions.- Parameters
width (int) – The new width to scale to.
height (int) – The new height to scale to.
- Returns
a list of [x, y] coordinates representing the scaled
Zone
coordinates.
-
create_zone_mask
(width=None, height=None)¶ Generates and returns a binary mask of the
Zone
in the context of the provided dimensions, where areas corresponding to theZone
are marked 1, and all other points are marked 0.If width or height is not provided, the original value will be used.
If the width or height has not been properly set, None will be returned.
- Parameters
width (int) – The width to use for the mask.
height (int) – The height to use for the mask.
- Returns
numpy array.
-
check_object_detection_prediction_within_zone
(prediction)¶ Checks whether a prediction is inside the
Zone
.- Parameters
prediction (
ObjectDetectionPrediction
) – The prediction to check for zone affiliation.- Returns
True if the prediction is in the
Zone
, and False otherwise.
-
property
-
class
ZoneList
(filepath=None)¶ Work with regions of interest in your applications. Configuration files can be generated with the Zone Creator tool, available through the alwaysAI CLI.
Typical usage:
my_zones = edgeiq.ZoneList("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) zone_detect_results = my_zones.filter_results_by_zone(results) obj_detect.publish_analytics(zone_detect_results) image = my_zones.markup_image_with_zones( image, fill_zones=True, color=(255, 0, 0))
- Parameters
filepath (string) – The path to the JSON file to configure
Zone
objects.
-
set_zones
(zones_dict)¶ Updates the zones property by passing in a dictionary as is returned by the
load_zones_from_config()
function.
-
update_dimensions
(width=None, height=None)¶ Updates the dimensions of the
ZoneList
and all includedZone
objects. Re-scales points and updates the masks of eachZone
in response to dimension updates.- Parameters
height (int) – The height to update to. Defaults to None.
height – The height to update to. Defaults to None.
-
add_zone
(zone)¶ Add a new
Zone
to theZoneList
, which is a deep copy of the inputZone
. If the name of the inputZone
already exists in theZoneList
, the newZone
will replace the original.
-
remove_zone
(zone)¶
-
get_zones_for_prediction
(prediction)¶ Returns a
ZoneList
containingZone
objects that this prediction is currently inside.- Parameters
prediction (
ObjectDetectionPrediction
) – The prediction to check for associatedZone
objects.- Returns
a
ZoneList
containingZone
objects that this prediction is currently inside.
-
get_results_for_zone
(results, zone_name)¶ Returns only the results that are inside the
Zone
.- Parameters
results (Results returned from
update()
ordetect_objects()
) – The results to check forZone
affiliation.zone_name (string) – The name of the
Zone
to get results for.
- Returns
The results that are in the selected
Zone
.
-
create_sub_zone_list
(name_list)¶ Creates a new
ZoneList
object containingZone
objects that correspond to the names in the input list.
-
markup_image_with_zones
(frame, zone_names=None, show_labels=True, show_boundaries=True, fill_zones=False, color=(255, 0, 0), line_thickness=2, font_size=0.5, font_thickness=2, alpha=0.5)¶ Marks up the input image with all of the
Zone
objects in the input list; defaults to allZone
objects in theZoneList
.- Parameters
frame (numpy array) – The image to mark up.
zone_names (a list of strings) – The list of names that correspond to
Zone
objects whose boundaries should be drawn.show_lables (boolean) – True if
Zone
names should be drawn.show_boundaries (boolean) – True if
Zone
boundaries should be drawn.fill_zones (boolean) – True if
Zone
objects should have a transparent overlay.color (tuple of (B, G, R)) – 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.
alpha (float in range [0.0, 1.0]) – 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.
- Returns
numpy array – The marked-up image.
-
filter_results_by_zone
(results)¶ Filters results returned by
update()
or bydetect_objects()
by all of theZones
in theZoneList
.- Parameters
results (Results returned by
detect_objects()
orupdate()
) – a dictionary as is returned byupdate()
- Returns
A dictionary where all tracking results are listed under an ‘zones’ key. Each list item contains the ‘id’ of the zone, and the associated results for that zone.