0

So, I'm fairly novice to OpenCV, but I've done lots of searching and don't think I can find the solution anywhere online.

I have a three channel RGB image that I would like to find the ROI of. To clarify, everything but a small rectangular subset of the image (defined with a separate image) should be black.

I achieved this earlier using the following:

def roi(image, vertices):
    mask = np.zeros_like(image)
    cv2.fillPoly(mask, vertices, 255)
    masked = cv2.bitwise_and(image, mask)
    return masked

However, this, of course, only works with a greyscale image. Achieving it with a colour image has stumped me. Any advice or help as to how I could achieve this would be greatly appreciated.

Many thanks.

Polyrogue
  • 15
  • 1
  • 4
  • Try changing the (single-channel greyscale) white `255` to a (3-channel RGB) white `(255,255,255)`. – Mark Setchell Feb 06 '19 at 21:27
  • Thanks for the response. I thought of this, but am not sure how to achieve this using the function above, since I think bitwise_and takes single dimension matrices? But either way, I also can't seem to figure out how to get an equivalent of `fillPoly` with 3-channels. Sorry if I'm being slow. Thanks very much. – Polyrogue Feb 06 '19 at 21:47
  • Never mind! It turns out it did work exactly as you said. The problems I was having was apparently that the vertices had to be explicitly converted into int32s? I didn't have to do that when using only single-channel images, but there you go. Cheers! – Polyrogue Feb 06 '19 at 23:16

0 Answers0