Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

how to extract part of an image by knowing MatOfPoint

I have two same size images:

Mat original;
Mat changed;

from Mat changed, I did extract contours by

 Imgproc.findContours

So now I have List<MatOfPoint> contours; My next task is to get color from each MatOfPoint. I can do that by applying function Scalar color = mean(contour); But the problem is that I need to find color of exactly same pixels from MatOfPoint but from Mat original;I can do that with Rect like this :

Rect rect = Imgproc.boundingRect(contour); 
Mat originalImageCropped = new Mat(original, rect); 
Scalar color = mean(originalImageCropped);

My qustion is how can I get color for each MatOfPoint from Mat original by List<MatOfPoint> contours from Mat changed

how to extract part of an image by knowing MatOfPoint

I have two same size images:

Mat original;
Mat changed;

from Mat changed, I did extract contours by

 Imgproc.findContours

So now I have List<MatOfPoint> contours; My next task is to get color from each MatOfPoint. I can do that by applying function Scalar color = mean(contour); But the problem is that I need to find color of exactly same pixels from MatOfPoint but from Mat original;I can do that with Rect like this :

Rect rect = Imgproc.boundingRect(contour); 
Mat originalImageCropped = new Mat(original, rect); 
Scalar color = mean(originalImageCropped);

My qustion is how can I get color for each MatOfPoint from Mat original by if I know List<MatOfPoint> contoursMatOfPoint from Mat changed

how to extract part of an image by knowing MatOfPoint

To find shapes I created a new copy of the original image and applied to it many different filters like cvtColor, blur, canny.I want to get the original color of the shape. I have two same size images:

Mat original;
Mat changed;

from Mat changed, I did extract contours by

 Imgproc.findContours

So now I have List<MatOfPoint> contours; My next task is to get color from each MatOfPoint. I can do that by applying function Scalar color = mean(contour); But the problem is that I need to find color of exactly same pixels from MatOfPoint but from Mat original;I can do that with Rect like this :

Rect rect = Imgproc.boundingRect(contour); 
Mat originalImageCropped = new Mat(original, rect); 
Scalar color = mean(originalImageCropped);

My qustion is how can I get color for MatOfPoint from Mat original if I know MatOfPoint from Mat changed

how to extract part of an image by knowing MatOfPoint

To find shapes I created a new copy of the original image and applied to it many different filters like cvtColor, blur, canny.I want to get the original color of the shape. I have two same size images:

Mat original;
Mat changed;

from Mat changed, I did extract contours by

 Imgproc.findContours

So now I have List<MatOfPoint> contours; My next task is to get color from each MatOfPoint. I can do that by applying function Scalar color = mean(contour); But the problem is that I need to find color of exactly same pixels from MatOfPoint but from Mat original;I can do that with Rect like this :

Rect rect = Imgproc.boundingRect(contour); 
Mat originalImageCropped = new Mat(original, rect); 
Scalar color = mean(originalImageCropped);

My qustion is how can I get color for MatOfPoint from Mat original if I know MatOfPoint from Mat changed

I'm trying this solution:

MatOfPoint contour = contours.get(i);

Point[] points = contour.toArray();
Mat cloned = contour.clone();

for (int j = 0; j < points.length; j++) {
      Point point = points[j];
      double[] data = original.get((int)point.x, (int)point.y);
      cloned.put((int)point.x, (int)point.y, data);
}

Scalar scalar = mean(cloned);

But it dosn't works