Manipulating Images and Video Frames

Translate an Image

To translate an image by shifting it on the x and y axes, use the edgeiq.edge_tools.translate() function.

translated_image = edgeiq.translate(image, x=x_shift, y=y_shift)

Rotate an Image

To rotate an image about a specific point use the rotate() function. The center defaults to the actual center of the image, and the scale factor defaults to 1.0 resulting in no scaling.

rotated_image = edgeiq.rotate(image, angle=90)

Resize an Image

To resize an image to be a specific width or height, provide only the desired dimension and leave keep_scale set to True. For example, to resize an image so that its width is now new_width:

resized_image = edgeiq.resize(image, width=new_width)

To resize an image so that it fits in a space no larger than max_width and max_height, do the following:

resized_image = edgeiq.resize(image, width=max_width, height=max_height)

Display Bounding Boxes

To display bounding boxes on an image, use the markup_image() function. The function will draw the bounding boxes on the image, optionally along with labels and confidences. Custom colors can be provided, and will be indexed according to the master label list of the model. One method to define custom colors would be to first create a dictionary of colors you’d like to set for specific labels. We’ll set “person” to blue, “pottedplant” to green, and all other detections to red. Note that the color values are in (B, G, R) format.

default_color = (0, 0, 255)
color_map = {
    "person": (255, 0, 0),
    "pottedplant": (0, 255, 0)

Now make the full colors list to pass into markup_image().

colors = [color_map.get(label, default_color) for label in obj_detect.labels]

Finally, pass the color list into markup_image() and your detections will be displayed with your custom colors.

new_image = edgeiq.markup_image(image, predictions, colors=colors)

Cut Out a Segment of an Image

A bounding box can also be used to cut out a segment of an image for further processing. The cutout_image() function takes a bounding box and returns the segment of the image outlined by the box.

image_segment = edgeiq.cutout_image(image,