-
Notifications
You must be signed in to change notification settings - Fork 0
/
Practice.cpp
77 lines (57 loc) · 1.67 KB
/
Practice.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
#include "cv.hpp" //Header
#include "opencv2/opencv.hpp" //Header include all
using namespace std;
using namespace cv;
int main(){
int i = 0;
int key, frame_rate = 30;
VideoCapture capture("C:\\Users\\Administrator\\Desktop\\Study\\4Çгâ\\°øÇÁ±â\\OpenCV\\challenge.mp4");
Mat src, det, gray, hough;
Mat origin;
Scalar y_from(0, 180, 180);
Scalar y_to(120, 255, 255);
Scalar w_from(180, 180, 180);
Scalar w_to(255, 255, 255);
Mat morph;
Mat kernel = getStructuringElement(0, Size(5, 5));
vector<Mat> v(3);
capture >> src;
if (!src.data){
printf("NO IMAGE\n");
return -1;
}
split(src, v);
while (capture.read(src)){
hough = src.clone();
inRange(src, y_from, y_to, v[0]);
Canny(v[0], v[0], 50, 100, 3);
morphologyEx(v[0], v[0], MORPH_CLOSE, kernel);
vector<Vec4i> lines;
HoughLinesP(v[0], lines, 1, CV_PI / 90, 500, 150, 100);
for (i = 0; i < lines.size(); i++){
Vec4i l = lines[i];
line(src, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 255, 255), 3);
}
inRange(src, w_from, w_to, v[1]);
Canny(v[1], v[1], 50, 100, 3);
morphologyEx(v[1], v[1], MORPH_CLOSE, kernel);
vector<Vec4i> liness;
HoughLinesP(v[1], liness, 1, CV_PI / 180, 80, 30, 10);
for (i = 0; i < liness.size(); i++){
Vec4i l = liness[i];
line(src, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0, 255, 0), 3);
}
cvtColor(src, v[2], CV_BGR2GRAY);
merge(v, morph);
/*imshow("LINE", src);
imshow("YELLOW", v[0]);
imshow("WHITE", v[1]);
imshow("HOUGH", hough);
*/
imshow("RESULT", src);
imshow("LINE", hough);
key = waitKey(frame_rate);
if (key == 27)
break;
}
}