0

I am trying to detect 3 different classes of objects in images using Tensorflow Object Detection. I would like to set the bounding box color for each class to a custom color of my choice in order to suit my application.

For example, Class 1: Red Class 2: Blue Class 3: Green

Unfortunately, Tensorflow object detection automatically sets this colors and I do not know how to change them.

I would be very gratefull for any suggestions and help.

1 Answer 1

3

You can achieve this by passing a track_ids to function visualize_boxes_and_labels_on_image_array.

Notice that when detection is performed, this plot function is called to visualize the bounding boxes on images.

Here is how to get the variable track_ids. First you should look at the STANDARD_COLORS list and get the index of the color you want to draw boxes with. For example, 'Red' color's index is 98. Then you should loop through the variable output_dict['detection_classes'] (this variable is also passed to the plot function), and when encounter class 1, track_ids is appended with 98. By doing this you will create a list of indexes of colors as track_ids, then transform this to a numpy array and pass it together into the plot function, then you should have all classes plotted as the color you assigned.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your awnser! it really worked. Also if you don't want the "ID: x" appearing in the bounding box text (I find it really ugly) you just need to pass the skip_track_ids as True in the function call.
Can you give an example of how to use track_ids in the function?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.