10
Hello, I’m learning to use the features that Opencv offers for image processing and the following question has arisen:
How do I edit only a predetermined area of an image?
To facilitate the understanding of my doubt, I will use the function cv::cvtColor()
and change a color image (RGB) to grayscale (Gray Scale), but would like the proposed solution to work with any other function. What I’ve already done:
Loading and Displaying a disk image:
cv::Mat img = cv::imread("/home/anderson/Pictures/Outras/house.jpeg");
if (img.empty()) {
std::cout << "Falha ao carregar o arquivo do disco!" << std::endl;
}
cv::namedWindow("RGB");
cv::imshow("RGB", img);
Select an area and turn to grayscale:
cv::Mat imgMod(img, cv::Rect(100,100,150,150));
cv::Mat imgModOut;
cv::cvtColor(imgMod, imgModOut, CV_BGR2GRAY);
cv::namedWindow("Gray");
cv::imshow("Gray", imgModOut);
So far so good, though how I do to combine the gray cutout with the original image and create a new partially gray image (cropped area)?
How to turn your friend into an Indian by using Opencv.
– karlphillip
The original image used in the demonstration can be found here.
– karlphillip
It’s good to make it clear that it’s not lupus.
– Lucas Lima
@karlphillip Thanks for the excellent reply, it worked perfectly!
– AndersonBS