forked from ryoppippi/Gasyori100knock
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
answer_6.cpp
38 lines (30 loc) · 842 Bytes
/
answer_6.cpp
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
37
38
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <math.h>
// Dedcrease color
cv::Mat decrease_color(cv::Mat img){
int height = img.cols;
int width = img.rows;
int channel = img.channels();
cv::Mat out = cv::Mat::zeros(height, width, CV_8UC3);
for(int y = 0; y < height; y++){
for(int x = 0; x < width; x++){
for(int c = 0; c < channel; c++){
out.at<cv::Vec3b>(y, x)[c] = (uchar)(floor((double)img.at<cv::Vec3b>(y, x)[c] / 64) * 64 + 32);
}
}
}
return out;
}
int main(int argc, const char* argv[]){
// read image
cv::Mat img = cv::imread("imori.jpg", cv::IMREAD_COLOR);
// decrease color
cv::Mat out = decrease_color(img);
//cv::imwrite("out.jpg", out);
cv::imshow("answer", out);
cv::waitKey(0);
cv::destroyAllWindows();
return 0;
}