-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoabs.cpp
116 lines (105 loc) · 2.76 KB
/
videoabs.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <sstream>
#include <vector>
using namespace cv;
using namespace std;
int main( int argc, char** argv ){
int count = 0;
while(1){
Mat input, output;
Mat dog, pre_dog, bilateral, lab, lum, wrap;
stringstream ss;
ss << "img/imagem" << count << ".jpg";
input = imread(ss.str().c_str(), CV_LOAD_IMAGE_COLOR);
output = input.clone();
Size sz1 = input.size();
Size sz2 = output.size();
if(! input.data ){
cout << "Could not open or find the image" << std::endl ;
return -1;
}
//RGB to Lab Conversion
cvtColor(input, lab, CV_BGR2Lab);
//Applying Bilateral Filter
bilateralFilter(input, bilateral, 9, 50, 50);
pre_dog = bilateral.clone();
for(int i = 0; i < 5; i++){
bilateralFilter(bilateral.clone(), bilateral, 9, 50, 50);
}
//imshow("bilateral", bilateral);
cvtColor(bilateral, lab, CV_BGR2Lab);
//Luminance Quantization
int q = 5;
for(int i = 0; i < lab.size().height; i++){
for(int j = 0; j < lab.size().width; j++){
Vec3b value = lab.at<Vec3b>(i,j);
float tax = value.val[0] / 255.0;
value.val[0] = (round(tax * q)/q)*255;
lab.at<Vec3b>(i,j) = value;
}
}
Mat tmp;
cvtColor(lab, tmp, CV_Lab2BGR);
//imshow("lab", tmp);
//Applying Difference of Gaussians
Mat g1, g2;
int sub_factor;
GaussianBlur(pre_dog,g1,Size(sqrt(1.6),sqrt(1.6)),0);
GaussianBlur(pre_dog,g2,Size(25,25),0);
dog = g2 - g1;
bitwise_not(dog,dog);
cvtColor(dog,dog,CV_Lab2BGR);
cvtColor(dog,dog,CV_BGR2GRAY);
dog = dog < 128;
//imshow("dog", dog);
//Generating presentation
for(int i = 0; i < lab.size().height; i++){
for(int j = 0; j < lab.size().width; j++){
if((int)dog.at<uchar>(i,j) == 0){
output.at<Vec3b>(i,j) = Vec3b(0,127,127);
} else {
output.at<Vec3b>(i,j) = lab.at<Vec3b>(i,j);
}
}
}
cvtColor(output, output, CV_Lab2BGR);
Mat output2 = output.clone();
for(int i = 0; i < bilateral.size().height; i++){
for(int j = 0; j < bilateral.size().width; j++){
if((int)dog.at<uchar>(i,j) == 0){
output2.at<Vec3b>(i,j) = Vec3b(0,0,0);
} else {
output2.at<Vec3b>(i,j) = bilateral.at<Vec3b>(i,j);
}
}
}
//cvtColor(output, output, CV_Lab2BGR);
Mat image;
hconcat(input, output2, image);
hconcat(image, output, image);
namedWindow( "Real Time Video Abstraction", WINDOW_AUTOSIZE );
imshow( "Real Time Video Abstraction", image );
int c = waitKey(0);
switch(c){
case 81:
if(count > 0)
count--;
else
count = 12;
break;
case 83:
if(count < 12)
count++;
else
count = 0;
break;
case 27:
cout << "fechando programa" << endl;
return 0;
break;
}
}
}