I am using OpenCV and Python to work on a project that involves tracking defects on a surface, and I am using binary images to find defects and draw a rectangle around it. The application uses advanced edge detection algorithms to identify defects in the images. Once detected, each defect is highlighted with a defect box for easy visualization. The physical dimensions of each defect are calculated using the provided parameters. This function of the code tracks defects and draws a box around it. And then mark the height and width of the rectangles in the processed image.
my code
# Get the width and height from the rect and convert to micrometers
width, height = rect[1]
width_um = width * scale_factor
height_um = height * scale_factor
# Combine width and height in one line
dimensions_text = f'W:{width_um:.1f}um H:{height_um:.1f}um'
# Position to draw the text
text_position = (int(rect[0][0]), int(rect[0][1]))
# Draw the combined width and height in micrometers on the image
cv2.putText(image, dimensions_text, text_position, cv2.FONT_HERSHEY_SIMPLEX, 0.4,
(255, 0, 0), 1, cv2.LINE_AA)
In this code enter image description here height and width annotations are overlapped. I am expecting it to be enter image description here