Notification texts go here Contact Us Buy Now!

OpenCV in Python: Rectangle with fill and stroke in one loop

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)

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.