#include<opencv2/opencv.hpp>
#include<opencv2/imgproc.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img,img2;
img = imread("E:/test.jpg");
imshow("BGR", img);
int i = 0;
int j = 0;
int cPointB, cPointG, cPointR;
for (i = 1; i < img.rows; i++)
for (j = 1; j < img.cols; j++)
{
cPointB = img.at<Vec3b>(i, j)[0];
cPointG = img.at<Vec3b>(i, j)[1];
cPointR = img.at<Vec3b>(i, j)[2];
if (cPointB > 100 & cPointR < 100 & cPointG < 100)
{
img.at<Vec3b>(i, j)[0] = 0;
img.at<Vec3b>(i, j)[1] = 0;
img.at<Vec3b>(i, j)[2] = 0;
}
}
imshow("da", img);
waitKey(0);
system("pause");
return 0;
}
C++改变图像颜色
最新推荐文章于 2024-04-24 12:01:50 发布
本文介绍了一种使用OpenCV库处理图像的方法,通过遍历图像的每个像素并根据特定条件(蓝色分量大于100而红色和绿色分量小于100)将这些像素转换为黑色,从而实现从原始彩色图像到黑白图像的转换。
1339

被折叠的 条评论
为什么被折叠?



