-
Notifications
You must be signed in to change notification settings - Fork 6
/
LaneDetection.cpp
82 lines (60 loc) · 1.83 KB
/
LaneDetection.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
//
// TestBed.cpp
// Lane Guard
//
// Created by Igor Afonov on 12/22/16.
// Copyright © 2016 Igor Afonov. All rights reserved.
//
#include "opencv2/opencv.hpp"
#include "LaneDetection/Detector.hpp"
#include "Console/EventsDelegate.hpp"
using namespace cv;
using namespace std;
int currentMode = 0;
void mainWindowCallback(int event, int x, int y, int flags, void* userdata) {
if (event == EVENT_LBUTTONDOWN) {
currentMode++;
if (currentMode > 2) {
currentMode = 0;
}
}
}
int main(int argc, char** argv) {
namedWindow("video", 1);
setMouseCallback("video", mainWindowCallback, NULL);
// Screen points - points on screen (pixels)
vector<Point2f> ptsSrc;
// Left
ptsSrc.push_back(Point2f(123, 205));
ptsSrc.push_back(Point2f(176, 150));
// Right
ptsSrc.push_back(Point2f(276, 150));
ptsSrc.push_back(Point2f(332, 205));
// On-Road points - points on road (inches)
vector<Point2f> ptsDst;
// Left
ptsDst.push_back(Point2f(240 + -45, 203));
ptsDst.push_back(Point2f(240 + -45, 98));
// Right
ptsDst.push_back(Point2f(240 + 45, 98));
ptsDst.push_back(Point2f(240 + 45, 203));
LaneDetection::Configuration::getInstance().setup(480, 270, ptsSrc, ptsDst, 1);
Console::ScreenEventsDelegate *screenEventsDelegate = new Console::ScreenEventsDelegate();
LaneDetection::Detector* detector = new LaneDetection::Detector(screenEventsDelegate);
VideoCapture cap(argv[1]);
for(;;)
{
Mat frame;
cap >> frame;
if (frame.empty()) {
break;
}
detector->processFrame(frame, currentMode);
screenEventsDelegate->render(frame);
imshow("video", frame);
if (waitKey(25) >= 0) break;
}
delete detector;
delete screenEventsDelegate;
return 0;
}