When I mask the image in opencv, lots of things inside image appears in white color, but I only want a particular region of the image in white color. These are the co-ordinates of that region : 540:740,340:440 How can I mask only this region from the entire image?.
CodePudding user response:
Just set that part of the matrix to your desired color.
import numpy as np
mask = 255 * np.ones(((740-540),(440-340),3),dtype=int)
image[540:740,340:440,:] = mask
CodePudding user response:
You can do it with a methode. I used this methode for a ai that only need a part of a picture. So "vertices" has to be a np array which includes the coords
def roi(img, vertices):
mask = np.zeros_like(img)
cv2.fillPoly(mask, vertices, 255)
masked = cv2.bitwise_and(img, mask)
return masked