-
Notifications
You must be signed in to change notification settings - Fork 2
/
old.cpp
118 lines (95 loc) · 2.62 KB
/
old.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
117
118
/**
* @file filter2D_demo.cpp
* @brief Sample code that shows how to implement your own linear filters by using filter2D function
* @author OpenCV team
*/
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>
using namespace cv;
#define P(mat, i, j) (mat.data + mat.step[0]*i + mat.step[1]*j)
#define V(mat, i, j, type) (*((type *) P(mat, i, j)))
/**
* @function main
*/
int main ( int, char** argv )
{
/// Declare variables
Point anchor;
double delta;
int ddepth;
int kernel_size;
const char* window_name = "filter2D Demo";
int c;
Mat src, dst, in;
/// Load an image
in = imread( argv[1] );
if( !in.data ){
printf("no image");
return -1; }
cvtColor( in, src, CV_BGR2GRAY);
float a[9]={ -1.0/4.0,0,1.0/4.0,
-2.0/4.0,0,2.0/4.0,
-1.0/4.0,0,1.0/4.0};
Mat kernel( 3, 3, CV_32F, a);
/// Create window
namedWindow( window_name, CV_WINDOW_AUTOSIZE );
/// Initialize arguments for the filter
anchor = Point( -1, -1 );
delta = 0;
ddepth = -1;
int i;
int j;
/// Loop - Will filter the image with different kernel sizes each 0.5 seconds
int ind = 0;
//for(;;)
//{
c = waitKey(500);
/// Press 'ESC' to exit the program
if( (char)c == 27 )
//{ break; }
/// Update kernel size for a normalized box filter
kernel_size = 3;
//kernel = Mat( kernel_size, kernel_size, src.type(), a);
/*i = 0;
j = 0;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = -1;
i = 0;
j = 1;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = -2;
i = 0;
j = 2;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = -1;
i = 1;
j = 0;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = 0;
i = 1;
j = 1;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = 0;
i = 1;
j = 2;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = 0;
i = 2;
j = 0;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = 1;
i = 2;
j = 1;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = 2;
i = 2;
j = 2;
*(kernel.data + kernel.step[0]*i + kernel.step[1]*j) = 1;
*/
/// Apply filter
filter2D(src, dst, ddepth , kernel, anchor, delta, BORDER_DEFAULT );
for(int i=0 ; i < kernel.rows; i++){
for (int j=0; j < kernel.cols; j++){
printf("%f,", V(kernel, i, j, float));
}
printf("\n");
}
imshow( window_name, abs(dst) );
ind++;
// }
return 0;
}