Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How can I get the values of the pixels that are inside a contour?

I'm developing an application that allows the user to load an image, make a selection of a certain region (by drawing a random closed shape) and I want to have the values of the pixels that are inside this region but I'm having trouble doing so. All the functionality of drawing the shape on top of the image I've done it with PyQt and later the image with the draw on it is passed to a function where I want to analyze it with OpenCV.

Here is an example of the input image:

image description

So basically I want to get the values of the pixels inside the red shape. I know OpenCV already has a ROI function, but unfortunately the ROI selection is a square shape and I can't make square selections. They have to be a shape drawn by the user.