-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanny.cpp
More file actions
110 lines (99 loc) · 2.32 KB
/
Copy pathcanny.cpp
File metadata and controls
110 lines (99 loc) · 2.32 KB
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
#include <iostream>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <ctime>
#include <cstdlib>
using namespace std;
using namespace cv;
int top_slider = 10;
int top_slider_max = 200;
int JITTER = 3;
int JITTER_max = 5;
int RAIO = 3;
int RAIO_max = 8;
int STEP = 5;
int STEP_max = 8;
Mat image, border,cannyponto, points2, points;
void on_trackbar_canny(int, void*){
int width, height, gray;
Mat image1, frame;
vector<int> yrange;
vector<int> xrange;
int x, y;
width = image.size().width;
height = image.size().height;
if (STEP < 1){
STEP = 1;
}
if (JITTER < 1){
JITTER = 1;
}
if (RAIO < 1){
RAIO = 1;
}
xrange.resize(height / STEP);
yrange.resize(width / STEP);
iota(xrange.begin(), xrange.end(), 0);
iota(yrange.begin(), yrange.end(), 0);
for (uint i = 0; i < xrange.size(); i++){
xrange[i] = xrange[i] * STEP + STEP / 2;
}
for (uint i = 0; i < yrange.size(); i++){
yrange[i] = yrange[i] * STEP + STEP / 2;
}
points = Mat(height, width, CV_8U, Scalar(255));
random_shuffle(xrange.begin(), xrange.end());
for (auto i : xrange){
random_shuffle(yrange.begin(), yrange.end());
for (auto j : yrange){
x = i + rand() % (2 * JITTER) - JITTER + 1;
y = j + rand() % (2 * JITTER) - JITTER + 1;
gray = image.at<uchar>(x, y);
circle(points,
cv::Point(y, x),
RAIO,
CV_RGB(gray, gray, gray),
-1,
CV_AA);
}
}
points2 = points.clone();
Canny(image, border, top_slider, 3 * top_slider);
cannyponto = 0.8 * points2 + 0.2 * border;
imshow("canny", cannyponto);
}
int main(int argc, char**argv){
image = imread("image1.png", CV_LOAD_IMAGE_GRAYSCALE);
srand(time(0));
if (!image.data){
cout << "nao abriu" << endl;
exit(0);
}
while (true){
namedWindow("canny", 1);
createTrackbar("Threshold", "canny",
&top_slider,
top_slider_max,
on_trackbar_canny);
createTrackbar("Jitter", "canny",
&JITTER,
JITTER_max,
on_trackbar_canny);
createTrackbar("Raio", "canny",
&RAIO,
RAIO_max,
on_trackbar_canny);
createTrackbar("Step", "canny",
&STEP,
STEP_max,
on_trackbar_canny);
on_trackbar_canny(top_slider, 0);
break;
}
waitKey();
return 0;
}