From ed88caca55e54851dafa2409727a777bf4d7f5a6 Mon Sep 17 00:00:00 2001 From: ozcanovunc Date: Thu, 21 Apr 2016 14:05:21 +0300 Subject: [PATCH] Fixed typos, implemented main --- Makefile | 33 +++++++++++++++ main.cpp | 54 +++++++++++++++++++++++++ modules/lane-detector/lane_detector.cpp | 17 ++++---- modules/lane-detector/lane_detector.h | 5 ++- 4 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 Makefile create mode 100644 main.cpp diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..128439d --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +CC = g++ +CFLAGS = -g -Wall + +SRC = main.cpp \ +modules/lane-detector/lane_detector.cpp \ +modules/pedestrian-detector/pedestrian_detector.cpp \ +modules/stopping-distance-calculator/stopping_distance_calculator.cpp + +EXE = main.exe + +# C:\opencv\build\x86\install\x86\mingw\lib +LIB = -llibopencv_calib3d310 \ +-llibopencv_core310 \ +-llibopencv_features2d310 \ +-llibopencv_flann310 \ +-llibopencv_highgui310 \ +-llibopencv_imgcodecs310 \ +-llibopencv_imgproc310 \ +-llibopencv_ml310 \ +-llibopencv_objdetect310 \ +-llibopencv_photo310 \ +-llibopencv_shape310 \ +-llibopencv_stitching310 \ +-llibopencv_superres310 \ +-llibopencv_video310 \ +-llibopencv_videoio310 \ +-llibopencv_videostab310 + +OPENCV = -I"C:\opencv\build\x86\install\include" \ +-L"C:\opencv\build\x86\install\x86\mingw\lib" + +$(EXE) : $(SRC) + $(CC) $(CFLAGS) -o $(EXE) $(SRC) $(OPENCV) $(LIB) \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..9ddb706 --- /dev/null +++ b/main.cpp @@ -0,0 +1,54 @@ +#include +#include + +#include "modules/lane-detector/lane_detector.h" +#include "modules/pedestrian-detector/pedestrian_detector.h" +#include "modules/stopping-distance-calculator/stopping_distance_calculator.h" + +#define LANE_COLOR Scalar(0, 255, 0) + +using namespace std; +using namespace cv; + +int main(int argc, const char** argv) +{ + Mat in; + vector lanes; + vector pedestrians; + bool is_out_of_lane = false, + is_distance_safe = true, + contains_pedestrian = false; + + in = imread("1.png"); + + LaneDetector* lane_detector = new LaneDetector(in); + PedestrianDetector* pedestrian_detector = new PedestrianDetector(); + + while (true) { + + in = imread("1.png"); + + // Stopping Distance Calculator Module + is_distance_safe = StoppingDistanceCalculator::IsSafe(in); + if (!is_distance_safe) { + cout << "NOT SAFE" << endl; + } +#if 0 + // Pedestrian Detector Module + contains_pedestrian = pedestrian_detector->ContainsPedestrian(in); + if (contains_pedestrian) { + pedestrians = pedestrian_detector->GetBoundingRectangles(in); + } +#endif + // Lane Detector Module + lanes = lane_detector->GetLanes(in); + is_out_of_lane = lane_detector->IsOutOfLane(in); + lane_detector->DrawLanes(in, lanes, LANE_COLOR, 3); + + + imshow("PROJECT", in); + waitKey(10); + } + + return 0; +} \ No newline at end of file diff --git a/modules/lane-detector/lane_detector.cpp b/modules/lane-detector/lane_detector.cpp index 9767571..69e36f4 100644 --- a/modules/lane-detector/lane_detector.cpp +++ b/modules/lane-detector/lane_detector.cpp @@ -32,7 +32,7 @@ LaneDetector::LaneDetector(Mat image) { LaneDetector::mask_for_elim = temp; } -Mat LaneDetector::GetWhiteMask(Mat image, bool maskFlag) { +Mat LaneDetector::GetWhiteMask(Mat image, bool apply_mask) { Mat tresh_saturation, tresh_value, @@ -41,10 +41,13 @@ Mat LaneDetector::GetWhiteMask(Mat image, bool maskFlag) { vector channels; // Convert image to HSV, split it to channels - if (maskFlag) + if (apply_mask) { cvtColor(LaneDetector::mask_for_elim & image, hsv, CV_BGR2HSV); - else + } + else { cvtColor(image, hsv, CV_BGR2HSV); + } + split(hsv, channels); // http://i.stack.imgur.com/mkq1P.png @@ -57,13 +60,13 @@ Mat LaneDetector::GetWhiteMask(Mat image, bool maskFlag) { vector LaneDetector::GetLanes(Mat image) { - Mat red_mask = GetWhiteMask(image, true); + Mat white_mask = GetWhiteMask(image, true); vector lanes; - erode(red_mask, red_mask, Mat(), Point(-1, -1), 1, 1, 1); - dilate(red_mask, red_mask, Mat(), Point(-1, -1), 2, 1, 1); + erode(white_mask, white_mask, Mat(), Point(-1, -1), 1, 1, 1); + dilate(white_mask, white_mask, Mat(), Point(-1, -1), 2, 1, 1); - HoughLinesP(red_mask, lanes, 1, CV_PI / 360, 50, 50, 1); + HoughLinesP(white_mask, lanes, 1, CV_PI / 360, 50, 50, 1); return lanes; } diff --git a/modules/lane-detector/lane_detector.h b/modules/lane-detector/lane_detector.h index 5cd1734..a43daf2 100644 --- a/modules/lane-detector/lane_detector.h +++ b/modules/lane-detector/lane_detector.h @@ -18,7 +18,10 @@ class LaneDetector private: // Returns a binary image in which // 1 corresponds to white area, 0 corresponds to other colors - static Mat GetWhiteMask(Mat image, bool maskFlag); + // apply_mask flag myst be true if we are detecting lanes, false o/w + static Mat GetWhiteMask(Mat image, bool apply_mask); static Mat mask_for_elim; + + // Treshold value for checking if the vehice is in the middle of lanes const static double kLaneTresh; }; \ No newline at end of file