I am new to programming and been learning the tutorial in google colab for algorithm in object detection. Below is the code used in google object detection API https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/object_detection_tutorial.ipynb , it using single shot detector to output images. I added a global variable "count" and for loop to count the number of objects with score more than 0.5. This will work in the case for single class detection. Checked the result with several images and it's printed the count value correctly as in this Number of dogs. Now, I want to display this number on images. As an example, in the images it added a row, "Number of people: {count value}" Please show me how to edit the code below to achieve the result.
def show_inference(model, image_path):
global count
count=0
# the array based representation of the image will be used later in order to prepare
the result image with boxes and labels on it.
image_np = np.array(Image.open(image_path))
# Actual detection.
output_dict = run_inference_for_single_image(model, image_np)
# Visualization of the results of a detection.
vis_util.visualize_boxes_and_labels_on_image_array(
image_np,
output_dict['detection_boxes'],
output_dict['detection_classes'],
output_dict['detection_scores'],
category_index,
instance_masks=output_dict.get('detection_masks_reframed', None),
use_normalized_coordinates=True,
line_thickness=8)
display(Image.fromarray(image_np))
for o in output_dict['detection_scores']:
if o > 0.5:
count=count+1
print(count)
for image_path in TEST_IMAGE_PATHS:
show_inference(detection_model, image_path)
For your question, create boxes to count numbers you can do this easily by this example I use for object counters AI number counts.
Sample: Using basics boundary boxes with colors from Tensorflow, AI applications applied the same you can use YOLO or any NN. It as Bitmap drawing FN, you need to create an image over another image you can make it a collaboration.