连环画滤镜
连环画滤镜的公式为:


代码实现
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
// comic-filter.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// @mango
#include<iostream>
#include<cmath>
#include<opencv2/opencv.hpp>
int main()
{
cv::Mat img = cv::imread("fruit.jpg");
for (size_t i = 0; i < img.rows; i++)
{
for (size_t j = 0; j < img.cols; j++)
{
int r = img.at<cv::Vec3b>(i, j)[2];
int g = img.at<cv::Vec3b>(i, j)[1];
int b = img.at<cv::Vec3b>(i, j)[0];
double R = std::abs(g - b + g + r) * r / 256;
double G = std::abs(b - g + b + r) * r / 256;
double B = std::abs(b - g + b + r) * g / 256;
img.at<cv::Vec3b>(i, j)[0] = cv::saturate_cast<uchar>(B);
img.at<cv::Vec3b>(i, j)[1] = cv::saturate_cast<uchar>(G);
img.at<cv::Vec3b>(i, j)[2] = cv::saturate_cast<uchar>(R);
}
}
cv::imshow("连环画滤镜", img);
cv::waitKey(0);
return 0;
}
|
滤镜效果

本文由芒果浩明发布,转载请注明来源。
本文链接:https://blog.mangoeffect.net/opencv/comic-filter.html
