Skip To Main Content
Support Knowledge Base

Unable to Generate Bounding Boxes around Objects in the Image for Custom Object Detection Application

Content Type: Product Information & Documentation   |   Article ID: 000092809   |   Last Reviewed: 02/16/2023

Description

Cannot understand how to draw bounding boxes around objects in the image for custom object detection application.

Resolution

Example code for generating bounding boxes:

For box in boxes:   
  #Pick a confidence factor from the last place in an array.    
   conf=box[-1]   
   If conf > threshold:  
     #Convert float to int and multiply corner position of each box by x and y ration.    
     #If the bounding box is found that the top of the image  
     #Position the upper box bar little lower to make it visible on the image    
    (x_min, y_min, x_max, y_max) = [
        int (max(corner_position*ratio_y, 10)) if idx%2
        else int (corner_position*ratio_x)
        for idx, corner_position in enumerate(box[:-1])  

    #Draw a box base on the position, parameters in rectangle function are: image,start_point, end_point, color, thickness.
   rgb_image = cv2.rectangle(rgb_image, (x_min,y_min), (x_max,y_max), 
       colors["green"], 3)

Additional information

Refer to Object Detection Python* Demo source code to learn the OpenVINO™ Inference Engine API usage for creating bounding boxes and how to handle the model.

Related Products

This article applies to 1 products.