-
Notifications
You must be signed in to change notification settings - Fork 0
/
Identicon.cpp
executable file
·71 lines (49 loc) · 1.58 KB
/
Identicon.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <ctime>
#include <stdlib.h>
#include <string>
using namespace std;
using namespace cv;
int red, green, blue;
void paint(Mat &image, int row, int col){
row = row * 2 + 1;
col = col * 2 + 1;
MatIterator_<Vec3b> p = image.begin<Vec3b>();
for(int i = 0; i < 2; i++){
for(int j = 0; j < 2; j++){
(*(p + ((row + i) * image.cols + (col + j))))[0] = blue;
(*(p + ((row + i) * image.cols + (col + j))))[1] = green;
(*(p + ((row + i) * image.cols + (col + j))))[2] = red;
(*(p + ((row + i) * image.cols + (image.cols - 1 - (col + j)))))[0] = blue;
(*(p + ((row + i) * image.cols + (image.cols - 1 - (col + j)))))[1] = green;
(*(p + ((row + i) * image.cols + (image.cols - 1 - (col + j)))))[2] = red;
}
}
}
int main() {
Mat image(Size(12, 12), CV_8UC3, Scalar(240, 240, 240));
time_t curTime;
srand(time(&curTime) + clock());
string fileName = asctime(localtime(&curTime));
fileName.pop_back();
fileName += ".png";
red = random() % 256;
green = random() % 256;
blue = random() % 256;
for(int i = 0; i < 5; i++){
for(int j = 0; j < 3; j++){
if( random() & 1 )
paint(image, i, j);
}
}
resize(image, image, Size(420, 420), 0, 0, INTER_NEAREST);
if( imwrite(fileName, image) ){
cout <<"File saved as : \"" <<fileName <<"\"\n";
}
else {
cout <<"ERROR Saving file\n";
}
return 0;
}