I am using openCV with python bindings, and I can use the mouse as a paint brush. Suppose I have the following image, and I want to get all the colors inside the blue curve.
I'd thought I can save all the coordinates into a list, and if a point that is already there is appended, get the closed region.
BUT how can I do that, or is at least possible? Thanks!
EDIT:
I've used the method suggested by @Arijit Mukherjee and I've obtained the following:

How can I now get all the colors inside that contour? An irrational solution would be to parse every pixel of the mask image, and make a set. How can I do this in another way?
Ok I assume that the area is selected from mouse click Follow the steps below:

Example Code:
import cv2
import numpy as np
# original image
image = cv2.imread('image.png')
# mask (of course replace corners with yours)
mask = np.zeros(image.shape, dtype=np.uint8)
roi_corners = np.array(points, dtype=np.int32) #pointsOf the polygon Like [[(10,10), (300,300), (10,300)]]
white = (255, 255, 255)
cv2.fillPoly(mask, roi_corners, white)
# apply the mask
masked_image = cv2.bitwise_and(image, mask)
# display your handywork
cv2.imshow('masked image', masked_image)
cv2.waitKey()
cv2.destroyAllWindows()
to find the color of the ROI you can use any of these two methods according to your needs->
min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(imgray,mask = mask)
mean_val = cv2.mean(im,mask = mask)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With