Problem solved
Thanks to feedback from @grismar, I now avoid drawing the solid-line rectangles on the same layer as the transparent fill rectangles, but instead draw directly on the haystack image:
for rectangle in rectangles: # Determine the location position. top_left = (rectangle[0], rectangle[1]) bottom_right = (rectangle[0] + rectangle[2], rectangle[1] + rectangle[3]) # Draw a transparent, filled rectangle over the detected needle image. cv.rectangle(scribble_image, top_left, bottom_right, color = (0, 255, 0), thickness = -1) # Draw a solid line around the detected needle image. cv.rectangle(haystack_image, top_left, bottom_right, color = (0, 255, 0), thickness = 2, lineType = cv.LINE_4) result_image = cv.addWeighted(scribble_image, 0.25, haystack_image, 1 - 0.25, 0) # Display the image in a window. cv.imshow('Result', result_image)