Skip to content

Commit

Permalink
Fixed typos, implemented main
Browse files Browse the repository at this point in the history
  • Loading branch information
ozcanovunc committed Apr 21, 2016
1 parent e3121db commit ed88cac
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 8 deletions.
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
54 changes: 54 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <opencv2\opencv.hpp>
#include <iostream>

#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<Vec4i> lanes;
vector<Rect> 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;
}
17 changes: 10 additions & 7 deletions modules/lane-detector/lane_detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -41,10 +41,13 @@ Mat LaneDetector::GetWhiteMask(Mat image, bool maskFlag) {
vector<Mat> 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
Expand All @@ -57,13 +60,13 @@ Mat LaneDetector::GetWhiteMask(Mat image, bool maskFlag) {

vector<Vec4i> LaneDetector::GetLanes(Mat image) {

Mat red_mask = GetWhiteMask(image, true);
Mat white_mask = GetWhiteMask(image, true);
vector<Vec4i> 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;
}
Expand Down
5 changes: 4 additions & 1 deletion modules/lane-detector/lane_detector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

0 comments on commit ed88cac

Please sign in to comment.