栏目分类:
子分类:
返回
文库吧用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
文库吧 > IT > 软件开发 > 后端开发 > C/C++/C#

C++ openCV图片的复古滤镜处理

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++ openCV图片的复古滤镜处理

偷偷拿来记录一下萌新的cs路——day 41 

R = 0.393r + 0.769g + 0.189b

G = 0.349r + 0.686g + 0.168b

B = 0.272r + 0.534g + 0.131b

#include
#include 
#include
using namespace cv;

int main()
{
	auto frame = imread("cat.jpg");  // 读取图像

	int width = frame.cols;
	int heigh = frame.rows;
	RNG rng;
	Mat img(frame.size(), CV_8UC3);
	for (int y = 0; y < heigh; y++)
	{
		uchar* P0 = frame.ptr(y);
		uchar* P1 = img.ptr(y);
		for (int x = 0; x < width; x++)
		{
			float B = P0[3 * x];
			float G = P0[3 * x + 1];
			float R = P0[3 * x + 2];
			float newB = 0.272 * R + 0.534 * G + 0.131 * B;
			float newG = 0.349 * R + 0.686 * G + 0.168 * B;
			float newR = 0.393 * R + 0.769 * G + 0.189 * B;
			if (newB < 0)newB = 0;
			if (newB > 255)newB = 255;
			if (newG < 0)newG = 0;
			if (newG > 255)newG = 255;
			if (newR < 0)newR = 0;
			if (newR > 255)newR = 255;
			P1[3 * x] = (uchar)newB;
			P1[3 * x + 1] = (uchar)newG;
			P1[3 * x + 2] = (uchar)newR;
		}
	}

	imshow("origin", frame);
	imshow("filter", img);
	waitKey();
	imwrite("E:/filter.jpg", img);  // 将img输出到图像文件
	destroyAllWindows();
	return 0;
}

运行结果

 

学了更多知识还会回来更新的!有误之处请大佬指正,感谢!

转载请注明:文章转载自 www.wk8.com.cn
本文地址:https://www.wk8.com.cn/it/1037088.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 wk8.com.cn

ICP备案号:晋ICP备2021003244-6号