I have an image and I need to erase all the green elements.
Right now I'm doing this,
hsv = cv.cvtColor(img,cv.COLOR_BGR2HSV)
lower_green, upper_green = np.array([36, 25, 25]), np.array([70, 255, 255])
mask1 = cv.inRange(hsv, lower_green, upper_green)
result = cv.bitwise_and(img, img, mask=mask)
cv.imwrite("logo.png", result)
The problem is if I do this, I extract all the colors from my image except the green and I want the opposite. I want to keep the original image without green.
For this reason I tried to use two masks, using the green values as limiters. But now I obtain a black image and furthermore I think I'm complicating the method.
hsv = cv.cvtColor(img,cv.COLOR_BGR2HSV)
lower_green, upper_green = np.array([36, 25, 25]), np.array([70, 255, 255])
mask1 = cv.inRange(hsv, np.array([0, 25, 25]), lower_green)
mask2 = cv.inRange(hsv, upper_green, np.array([179, 25, 25]))
mask = cv.bitwise_or(mask1, mask2)
result = cv.bitwise_and(img, img, mask=mask2)
cv.imwrite("logo.png", result)
I'm doing correctly? How can I do this? I always find explanations about how to find the color to eliminate the rest, but not my goal.
Thank you!