Reputation: 1040
Using OpenCV, I am detecting a face, detecting the left and right eyes of that face, and extracting the eye into a new Mat image. I am then converting the eye image colour from BGR to HSV.
I am checking to see if the eye colour is in a certain range using inRange(). This displays the area of the eye that is red (see below image).
My question is: I would like to change the eye colour (detected using inRange()) from red to black. I'm not too sure where to go from here.
Any help is appreciated! Thanks!
Current result:
Upvotes: 0
Views: 2042
Reputation: 1531
You can do this with the following for loop if you want to make the eyes blue for instance
cv::Vec3b pixelColor(255,0,0);
for(int y=0;y<img.rows;y++){
for(int x=0;x<img.cols;x++){
cv::Point2f point(x, y);
if (mask.at<uchar>(point)) image.at<Vec3b>(cv::Point(x,y)) = pixelColor;
}
}
Upvotes: 1
Reputation: 560
You already have the mask, just do a for loop and set the pixels to black(.at = Vec3b(0,0,0), in BGR space of course) where the mask is 255.
Upvotes: 1