OpenCV Learning Record: filter: comic picture
When I was in elementary school, I read the small comic book of the Dragon Ball many times, and I borrowed the book from the bookstore next to the school. At that time, I thought I was a Chinese author. I was wondering why some people were named such strange names. My tears have fallen :(.
The main algorithm idea of the loop painting filter:
1. Use the following formula to calculate the new RGB value:
R = (| 2 * g-B + r | * r)> 8;
G = (| 2 * B-g + r | * r)> 8;
B = (| 2 * B-g + r | * r)> 8;
The 8-digit shift to the right is equivalent to dividing by 256.
2. Calculate the gray value using the average value method:
Gray = (R + G + B)/3
3. Set the new RGB value:
R = Gray + 10;
G = Gray + 10;
B = Gray;
The RGB value must be between 0 and 255.
The complete code is as follows:
# Include
# Include
Using namespace cv; using namespace std; void lihuan1_filter (Mat & srcImage); int main () {Mat srcImage = imread ("longzhu.jpg"); if (! SrcImage. data) {cout <"An error occurred while reading the image! "<
(J); for (int I = 0; I
> 8; int G = (abs (2 * B-g + r) * r)> 8; int B = (abs (2 * B-g + r) * r)> 8; R = max (0, min (R, 255); G = max (0, min (G, 255 )); B = max (0, min (B, 255); int gray = (R + G + B)/3; R = min (255, gray + 10 ); data [I * 3 + 2] = R; data [I * 3 + 1] = R; data [I * 3] = gray ;}} imshow ("loop filter ", srcImage );}
Laizhang longzhu's: