C ++ | Change color in cv :: mat with setTo

I have a cv :: Mat file with vec3b values. These values ​​are the colors of the image. I would like to change some colors in this image.

I know the setTo () function for normal manipulation of matrices, but how to use it for my Mat file?

I tried something like this:

 image = image.setto(Vec3b(0,0,0), image == Vec3b(255,0,0))

thanks!

+4
source share
1 answer

For the image, imagewe want to find all the pixels in imagethat are equal Scalar(255,0,0), and then set the value for these pixels Scalar(0,0,0).

  • mask, mask 255, image Scalar(255,0,0), 0. inRange().

    Mat mask;
    inRange(image, Scalar(255,0,0), Scalar(255,0,0), mask);
    
  • setTo() image.

    image.setTo(Scalar(0,0,0), mask);
    
+4

All Articles