├── AndroidManifest.xml
├── LICENSE
├── README.md
├── build.gradle
├── build.xml
├── ic_launcher-web.png
├── jni
├── Android.mk
├── Application.mk
├── LaneCalculations.cpp
├── LaneCalculations.h
├── LaneDetector.cpp
├── lane_detector.h
├── lane_test.h
├── lanemetrics.h
├── linefinder.h
└── tum_andrive_Andrive.h
├── libs
├── android-support-v4.jar
├── armeabi-v7a
│ ├── libLaneDetectionNative.so
│ ├── libnative_camera_r2.2.0.so
│ ├── libnative_camera_r2.3.3.so
│ ├── libnative_camera_r3.0.1.so
│ ├── libnative_camera_r4.0.0.so
│ ├── libnative_camera_r4.0.3.so
│ ├── libnative_camera_r4.1.1.so
│ ├── libnative_camera_r4.2.0.so
│ └── libopencv_java.so
├── armeabi
│ ├── libLaneDetectionNative.so
│ ├── libnative_camera_r2.2.0.so
│ ├── libnative_camera_r2.3.3.so
│ ├── libnative_camera_r3.0.1.so
│ ├── libnative_camera_r4.0.0.so
│ ├── libnative_camera_r4.0.3.so
│ ├── libnative_camera_r4.1.1.so
│ ├── libnative_camera_r4.2.0.so
│ └── libopencv_java.so
├── mips
│ ├── libLaneDetectionNative.so
│ ├── libnative_camera_r4.0.3.so
│ ├── libnative_camera_r4.1.1.so
│ ├── libnative_camera_r4.2.0.so
│ └── libopencv_java.so
└── x86
│ ├── libLaneDetectionNative.so
│ ├── libnative_camera_r2.3.3.so
│ ├── libnative_camera_r3.0.1.so
│ ├── libnative_camera_r4.0.3.so
│ ├── libnative_camera_r4.1.1.so
│ ├── libnative_camera_r4.2.0.so
│ └── libopencv_java.so
├── lint.xml
├── local.properties
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ ├── activity_lane_test.xml
│ └── activity_selection.xml
├── values-sw600dp
│ └── dimens.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── tum
└── andrive
└── lanedetection
├── LaneDetector.java
├── VerticalSeekBar.java
├── VerticalSliderActivity.java
└── package-info.java
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
23 |
24 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 wahib-ul-haq
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | android-opencv-lanedetection
2 | ============================
3 |
4 | This project was developed as a semester project during my MSc. Computer Science at TUM. The Android app detects lanes on road, overlays using a red line and calculate estimated values of Standard Deviation of Lane Position (SDLP) based on position of car in the lain. The motivation of developing this android app as a proof of concept was to help researchers in domain of ergonomics to investigate driver’s behavior in different scenarios. Proposed system acquires the front view using an android phone camera mounted on the vehicle's dashboard and then applying few processes in order to detect the lanes. The "lane detection" code is primarily used from https://github.com/jdorweiler/lane-detection to provide the baseline functionality which is developed to run on Desktop. Code is ported to Android NDK project and then improved further and features added as per project requirement.
5 |
6 | This Android project is using the core lane detection module from project "Lane detection using OpenCV" http://www.transistor.io/revisiting-lane-detection-using-opencv.html . I have ported, implemented it in Android NDK, modified and added several optimization techniques to make it efficient for smartphones.
7 |
8 | Project Report can be downloaded at https://www.academia.edu/11329425/Computer_vision_on_nomadic_devices_for_human_factors_engineering
9 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'android'
2 |
3 | dependencies {
4 | compile fileTree(dir: 'libs', include: '*.jar')
5 | compile project(':OpenCV Library - 2.4.6')
6 | }
7 |
8 | android {
9 | compileSdkVersion 18
10 | buildToolsVersion "18.1.0"
11 |
12 | sourceSets {
13 | main {
14 | manifest.srcFile 'AndroidManifest.xml'
15 | java.srcDirs = ['src']
16 | resources.srcDirs = ['src']
17 | aidl.srcDirs = ['src']
18 | renderscript.srcDirs = ['src']
19 | res.srcDirs = ['res']
20 | assets.srcDirs = ['assets']
21 | }
22 |
23 | // Move the tests to tests/java, tests/res, etc...
24 | instrumentTest.setRoot('tests')
25 |
26 | // Move the build types to build-types/
27 | // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
28 | // This moves them out of them default location under src//... which would
29 | // conflict with src/ being used by the main source set.
30 | // Adding new build types or product flavors should be accompanied
31 | // by a similar customization.
32 | debug.setRoot('build-types/debug')
33 | release.setRoot('build-types/release')
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
29 |
30 |
31 |
35 |
36 |
37 |
38 |
39 |
40 |
49 |
50 |
51 |
52 |
56 |
57 |
69 |
70 |
71 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/ic_launcher-web.png
--------------------------------------------------------------------------------
/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | #OpenCv
6 | OPENCV_CAMERA_MODULES:=on
7 | OPENCV_INSTALL_MODULES:=on
8 |
9 | include $(OPENCVSDK)/native/jni/OpenCV.mk
10 |
11 | LOCAL_MODULE := LaneDetectionNative
12 | LOCAL_SRC_FILES := LaneDetector.cpp
13 | LOCAL_LDLIBS += -llog -ldl -landroid -lGLESv2 -lEGL
14 |
15 | CPPFLAGS += -fno-strict-aliasing -mfpu=vfp -mfloat-abi=softfp
16 | LOCAL_CPP_FEATURES := rtti exceptions
17 |
18 | include $(BUILD_SHARED_LIBRARY)
19 |
--------------------------------------------------------------------------------
/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_STL := gnustl_static
2 | APP_CPPFLAGS := -frtti -fexceptions
3 | APP_ABI := all
4 | APP_PLATFORM := android-18
5 | APP_OPTIM := release
6 |
7 |
--------------------------------------------------------------------------------
/jni/LaneCalculations.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "LaneCalculations.h"
3 | #include
4 | #include
5 |
6 | #include
7 |
8 | // Global static pointer used to ensure a single instance of the class.
9 | LaneCalculations* LaneCalculations::m_pInstance = NULL;
10 |
11 | /** This function is called to create an instance of the class.
12 | Calling the constructor publicly is not allowed. The constructor
13 | is private and is only called by this Instance function.
14 | */
15 |
16 | LaneCalculations* LaneCalculations::Instance()
17 | {
18 | if (!m_pInstance) // Only allow one instance of class to be generated.
19 | m_pInstance = new LaneCalculations;
20 |
21 | return m_pInstance;
22 | }
23 |
24 |
25 | double LaneCalculations::calculateMeanLateralPosition()
26 | {
27 | return LaneCalculations::Instance()->sumLateralPosition/LaneCalculations::Instance()->countLateralPosition;
28 |
29 | }
30 |
31 | double LaneCalculations::calculateSDLP()
32 | {
33 | double mean = calculateMeanLateralPosition();
34 |
35 | double sumOfVariance = 0;
36 | for(int i=0; i< LaneCalculations::Instance()->countLateralPosition; i++)
37 | {
38 | double temp1 = (LaneCalculations::Instance()->arrayLateralPosition[i] - mean) * (LaneCalculations::Instance()->arrayLateralPosition[i] - mean);
39 | sumOfVariance += temp1;
40 |
41 |
42 | }
43 |
44 | double variance = sumOfVariance/LaneCalculations::Instance()->countLateralPosition;
45 | double sdlp = sqrt(variance); //dividing to calculate sdlp with respect to single lane
46 | sdlp = floor(sdlp*100 + 0.5)/100; //rounding off to 2 d.p
47 |
48 |
49 | return sdlp;
50 | }
51 |
52 |
--------------------------------------------------------------------------------
/jni/LaneCalculations.h:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------------------------*\
2 | Logging lane metrics to help in understanding driver's behavior aka SDLP
3 |
4 | \*------------------------------------------------------------------------------------------*/
5 |
6 | //#if !defined LINEF
7 | //#define LINEF
8 |
9 | #include
10 | #include
11 |
12 | #include
13 |
14 | #define PI 3.1415926
15 |
16 | using namespace cv;
17 | using namespace std;
18 |
19 | class LaneCalculations {
20 |
21 | private:
22 |
23 | LaneCalculations()//:sumLateralPosition(0), meanLateralPosition(0), countLateralPosition(0)
24 | {
25 | sumLateralPosition = 0;
26 | meanLateralPosition = 0;
27 | countLateralPosition = 0;
28 | arrayLateralPosition = new double[50000];
29 | __android_log_print(ANDROID_LOG_ERROR, "LANE Calculations", "Constructur : %s", "Yes called");
30 |
31 | };
32 |
33 | LaneCalculations(LaneCalculations const&){};
34 | LaneCalculations& operator = (LaneCalculations const&){};
35 | static LaneCalculations* m_pInstance;
36 |
37 |
38 |
39 | // LineFinder() : deltaRho(1), deltaTheta(PI/180), minVote(10), minLength(0.), maxGap(0.) {}
40 |
41 |
42 | public :
43 |
44 | //Mean Lateral Position value
45 | double sumLateralPosition;
46 | double meanLateralPosition;
47 | int countLateralPosition;
48 |
49 | //Standard Deviation of Lateral Position (SDLP)
50 | double* arrayLateralPosition;
51 |
52 | static LaneCalculations* Instance();
53 |
54 | double calculateMeanLateralPosition();
55 | double calculateSDLP();
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | };
65 |
66 | //#endif
67 |
--------------------------------------------------------------------------------
/jni/LaneDetector.cpp:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | *
4 | * @author Wahib-Ul-Haq, wahib.tech@gmail.com, 2014
5 | *
6 | *
7 | * contains code taken from:
8 | *
9 | * "Lane detection using OpenCV"
10 | * https://github.com/jdorweiler/lane-detection
11 | * Acknowledgments: jdorweiler
12 | * Contact: jason@transistor.io
13 | */
14 |
15 |
16 | #include
17 | #include "lane_detector.h"
18 | #include
19 | #include
20 |
21 | #include
22 | #include
23 | #include
24 |
25 |
26 | #include
27 | #include
28 | #include
29 |
30 | #include "linefinder.h"
31 | #include "lanemetrics.h"
32 |
33 | #include
34 |
35 | #define PI 3.1415926
36 |
37 | using namespace std;
38 | using namespace cv;
39 |
40 |
41 | JNIEXPORT void JNICALL Java_tum_andrive_lanedetection_LaneDetector_mainDelegate
42 | (JNIEnv *env, jobject obj, jlong in, jlong out, jint houghValue)
43 | {
44 |
45 |
46 | //tried using VideoCapture but didn't work and getting no access to camera. reason is ndk doesn't allow to access camera in this native way like on desktop.
47 | //somehow it is also not recommended
48 |
49 | //__android_log_print(ANDROID_LOG_ERROR, "LANEDETECTOR++", "%s", "start mainDelegate");
50 |
51 | Mat& imageOrig = *(Mat*)in;
52 | Mat& output = *(Mat*)out;
53 |
54 | //////reducing the image size////
55 | Mat image;
56 | resize(imageOrig, image, Size(),0.25,0.25, cv::INTER_LINEAR); //to reduce it to quarter of size
57 |
58 |
59 | int houghVote = houghValue;
60 | __android_log_print(ANDROID_LOG_ERROR, "LANEDETECTOR++", "hough value : %d", houghVote);
61 |
62 |
63 | bool showSteps = false; //if set to true it shows multiple windows of intermediate steps
64 |
65 |
66 | //double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
67 | //double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
68 |
69 | //cout << "Frame Size = " << dWidth << "x" << dHeight << endl;
70 |
71 |
72 | if (image.empty())
73 | {
74 | //break;
75 | __android_log_print(ANDROID_LOG_ERROR, "LANEDETECTOR++", "%s", "Cannot access the camera");
76 |
77 | exit(0);
78 | }
79 |
80 | Mat gray;
81 | cvtColor(image,gray,CV_RGB2GRAY); //convert image to grayscale
82 | vector codes;
83 | Mat corners;
84 | findDataMatrix(gray, codes, corners);
85 | drawDataMatrixCodes(image, codes, corners);
86 |
87 | /*ROI returns a matrix that is pointing to the ROI of the original image, located at the place specified by the rectangle.
88 | so imageROI is really the Region of Interest (or subimage/submatrix) of the original image "image".
89 | If you modify imageROI it will consequently modify the original, larger matrix.
90 | Rect region_of_interest = Rect(x, y, w, h); current parameters try to take the lower half of the image on vertical frame*/
91 |
92 | Rect roi(0,image.cols/3,image.cols-1,image.rows - image.cols/3);// set the ROI (region of interest) for the image
93 | //Rect roi(0,image.cols/2,image.cols-1,image.rows - image.cols/2);// set the ROI (region of interest) for the image
94 |
95 | Mat imgROI = image(roi);
96 |
97 | // Display the image
98 | if(showSteps){
99 |
100 | namedWindow("Original Image");
101 | imshow("Original Image",imgROI);
102 | imwrite("original.bmp", imgROI);
103 | }
104 |
105 | /* Canny Edge Detector algorithm : canny (source image, edge output image, first threshold for the hysteresis procedure,
106 | , second threshold for the hysteresis procedure, apersturesize i.e set to be 3 by default , L2gradient )
107 | threshold2 is recommended to be 3 times to threshold1 */
108 |
109 | Mat contours;
110 | Canny(imgROI,contours, 80,250,3); //50, 150,3); //in original code => 50,250);
111 |
112 | /* Thresholding is to differentiate the pixels we are interested in from the rest */
113 | Mat contoursInv;
114 | threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
115 |
116 | // Display Canny image
117 | if(showSteps){
118 | namedWindow("Contours");
119 | imshow("Contours1",contoursInv);
120 | imwrite("contours.bmp", contoursInv);
121 | }
122 |
123 | /*
124 | Hough tranform for line detection with feedback
125 | Increase by 25 for the next frame if we found some lines.
126 | This is so we don't miss other lines that may crop up in the next frame
127 | but at the same time we don't want to start the feed back loop from scratch.
128 | */
129 |
130 |
131 | vector lines;
132 | if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset
133 | houghVote = houghValue; //previously it was set to 200 always
134 | }
135 | else{ houghVote += 25;}
136 |
137 | //ensuring lines size is 5
138 | while(lines.size() < 5 && houghVote > 0){
139 | HoughLines(contours,lines,1,PI/180, houghVote);
140 | houghVote -= 5;
141 | }
142 |
143 | //cout << houghVote << "\n";
144 | Mat result(imgROI.size(),CV_8U,Scalar(255));
145 | imgROI.copyTo(result);
146 |
147 |
148 |
149 |
150 | // Draw the lines
151 | vector::const_iterator it= lines.begin();
152 | Mat hough(imgROI.size(),CV_8U,Scalar(0));
153 |
154 |
155 |
156 | while (it != lines.end())
157 | {
158 |
159 | //__android_log_print(ANDROID_LOG_INFO, "LANEDETECTOR++", "%s", "while of lines");
160 |
161 | float rho= (*it)[0]; // first element is distance rho
162 | float theta= (*it)[1]; // second element is angle theta
163 |
164 | // filter to remove vertical and horizontal lines
165 | //if(theta is between 5 degrees and 84 degrees) or if(theta is between 95 degrees and 180 degrees )
166 | if((theta > 0.09 && theta < 1.48) || (theta < 3.14 && theta > 1.66))
167 | {
168 | // point of intersection of the line with first row
169 | Point pt1(rho/cos(theta),0);//y = 0
170 |
171 | // point of intersection of the line with last row
172 | Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);//y = row count
173 |
174 |
175 | //This draws lines but without ends and in shape of X
176 | line( hough, pt1, pt2, Scalar(255), 10); //this is working and shows red lines of thickness 10
177 |
178 |
179 |
180 | }
181 |
182 | // cout << "line: (" << rho << "," << theta << ")\n";
183 | ++it;
184 | }
185 |
186 | // Display the detected line image
187 | if(showSteps)
188 | {
189 | namedWindow("Detected Lines with Hough");
190 | imshow("Detected Lines with Hough",result);
191 | imwrite("hough.bmp", result);
192 | }
193 |
194 |
195 | // Create LineFinder instance
196 | LineFinder ld;
197 |
198 | // Set probabilistic Hough parameters
199 | ld.setLineLengthAndGap(60,10);
200 | ld.setMinVote(4);
201 |
202 | // Detect lines
203 | vector li= ld.findLines(contours); //applying probablity hough transform
204 |
205 | Mat houghP(imgROI.size(),CV_8U,Scalar(0));
206 | ld.setShift(0);
207 | ld.drawDetectedLines(houghP);
208 | //cout << "First Hough" << "\n";
209 |
210 | if(showSteps){
211 | namedWindow("Detected Lines with HoughP");
212 | imshow("Detected Lines with HoughP", houghP);
213 | imwrite("houghP.bmp", houghP);
214 | }
215 |
216 | // bitwise AND of the two hough images.
217 | //1) Normal Hough -> without end points 2) Probabilistic Hough -> with end points
218 |
219 | bitwise_and(houghP,hough,houghP);
220 | Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
221 | Mat dst(imgROI.size(),CV_8U,Scalar(0));
222 | threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
223 |
224 | if(showSteps){
225 | namedWindow("Detected Lines with Bitwise");
226 | imshow("Detected Lines with Bitwise", houghPinv);
227 | }
228 |
229 |
230 | Canny(houghPinv,contours, 100,350);//100,150); //100,350);
231 | li= ld.findLines(contours);
232 |
233 | // Display Canny image
234 | if(showSteps){
235 | namedWindow("Contours");
236 | imshow("Contours2",contours);
237 | imwrite("contours.bmp", contoursInv);
238 | }
239 |
240 | // Set probabilistic Hough parameters
241 | //These parameters set min and max values. If you set minvote as 100 then even if you set 60 from slider, it won't
242 | //show any lines
243 |
244 | ld.setLineLengthAndGap(5,2); //5,2 original
245 | ld.setMinVote(1); //1 original
246 |
247 | ld.setShift(image.cols/3);
248 | ld.drawDetectedLines(image);
249 |
250 |
251 |
252 |
253 | //to show the number of line segments found in a frame
254 | //putText(image, stream.str(), Point(10,image.rows-10), 4, 1, Scalar(0,255,255),0);
255 |
256 |
257 | lines.clear();
258 |
259 | //Hough Processing ends here
260 |
261 |
262 |
263 | resize(image, image, Size(),4,4, cv::INTER_LINEAR);
264 | output = image;
265 |
266 | //__android_log_print(ANDROID_LOG_ERROR, "LANEDETECTOR++", "%s", "end mainDelegate");
267 |
268 | }
269 |
270 |
271 |
--------------------------------------------------------------------------------
/jni/lane_detector.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class tum_andrive_Andrive */
4 |
5 |
6 | #ifndef _Included_tum_andrive_LaneDetection_LaneDetector
7 | #define _Included_tum_andrive_LaneDetection_LaneDetector
8 | #ifdef __cplusplus
9 | extern "C" {
10 | #endif
11 | /*
12 | * Class: tum_andrive_lanedetection_LaneDetector
13 | * Method: mainDelegate
14 | * Signature: (JJ)V
15 | */
16 |
17 | JNIEXPORT void JNICALL Java_tum_andrive_lanedetection_LaneDetector_mainDelegate
18 | (JNIEnv *env, jobject obj, jlong in, jlong out, jint houghValue);
19 |
20 |
21 | #ifdef __cplusplus
22 | }
23 | #endif
24 | #endif
25 |
--------------------------------------------------------------------------------
/jni/lane_test.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class tum_andrive_Andrive */
4 |
5 | #ifndef _Included_tum_andrive_LaneDetection_TestMain
6 | #define _Included_tum_andrive_LaneDetection_TestMain
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: tum_andrive_lanedetection_TestMain
12 | * Method: nativeThreshold
13 | * Signature: (JJ)V
14 | */
15 | JNIEXPORT void JNICALL Java_tum_andrive_lanedetection_TestMain_nativeThreshold
16 | (JNIEnv *, jobject, jlong, jlong);
17 |
18 | JNIEXPORT void JNICALL Java_tum_andrive_lanedetection_TestMain_nativeCannyEdge
19 | (JNIEnv *, jobject, jlong, jlong);
20 |
21 | #ifdef __cplusplus
22 | }
23 | #endif
24 | #endif
25 |
--------------------------------------------------------------------------------
/jni/lanemetrics.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Logging lane metrics to help in understanding driver's behavior aka SDLP
3 | */
4 |
5 |
6 |
7 | #if !defined LINEF
8 | #define LINEF
9 |
10 | #include
11 | #include
12 |
13 | #include
14 |
15 | #define PI 3.1415926
16 |
17 | using namespace cv;
18 | using namespace std;
19 |
20 | class LaneMetrics {
21 |
22 | private:
23 |
24 |
25 | //Mean Lateral Position value
26 | static double sumLateralPosition;
27 | static double meanLateralPosition;
28 | static int countLateralPosition;
29 |
30 | //Standard Deviation of Lateral Position (SDLP)
31 | static double* arrayLateralPosition;
32 |
33 | LaneMetrics() : sumLater;
34 | // LineFinder() : deltaRho(1), deltaTheta(PI/180), minVote(10), minLength(0.), maxGap(0.) {}
35 |
36 |
37 | public :
38 |
39 | static LaneMetrics& instance()
40 | {
41 | static LaneMetrics INSTANCE;
42 | return INSTANCE;
43 | }
44 |
45 | static getSumLaterationPosition
46 | {
47 | return sumLateralPosition;
48 | }
49 |
50 |
51 |
52 |
53 | };
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/jni/linefinder.h:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | *
4 | * @author Wahib-Ul-Haq, wahib.tech@gmail.com, 2014
5 | *
6 | *
7 | * contains code taken from:
8 | *
9 | * "Lane detection using OpenCV"
10 | * https://github.com/jdorweiler/lane-detection
11 | * Acknowledgments: jdorweiler
12 | * Contact: jason@transistor.io
13 | */
14 |
15 | #if !defined LINEF
16 | #define LINEF
17 |
18 | #include
19 | #include
20 |
21 | #include
22 | #include "LaneCalculations.cpp"
23 | #include
24 | #include
25 |
26 | #define PI 3.1415926
27 |
28 | using namespace cv;
29 | using namespace std;
30 |
31 | class LineFinder {
32 |
33 | private:
34 |
35 | // original image
36 | Mat img;
37 |
38 | // vector containing the end points
39 | // of the detected lines
40 | vector lines;
41 |
42 | // accumulator resolution parameters
43 | double deltaRho;
44 | double deltaTheta;
45 |
46 | // minimum number of votes that a line must receive before being considered.
47 | //The minimum number of intersections to “detect” a line
48 | int minVote;
49 |
50 | // min length for a line
51 | double minLength;
52 |
53 | // max allowed gap along the line
54 | double maxGap;
55 |
56 | // distance to shift the drawn lines down when using a ROI
57 | int shift;
58 |
59 |
60 |
61 |
62 | public:
63 |
64 | // Default accumulator resolution is 1 pixel by 1 degree
65 | // no gap, no mimimum length
66 | LineFinder() : deltaRho(1), deltaTheta(PI/180), minVote(10), minLength(0.), maxGap(0.){}
67 |
68 |
69 |
70 | // Set the resolution of the accumulator
71 | void setAccResolution(double dRho, double dTheta) {
72 |
73 | deltaRho= dRho;
74 | deltaTheta= dTheta;
75 | }
76 |
77 | // Set the minimum number of votes
78 | void setMinVote(int minv) {
79 |
80 | minVote= minv;
81 | }
82 |
83 | // Set line length and gap
84 | void setLineLengthAndGap(double length, double gap) {
85 |
86 | minLength= length;
87 | maxGap= gap;
88 | }
89 |
90 | // set image shift
91 | void setShift(int imgShift) {
92 |
93 | shift = imgShift;
94 | }
95 |
96 | // Apply probabilistic Hough Transform
97 | vector findLines(Mat& binary) {
98 |
99 | lines.clear();
100 | HoughLinesP(binary,lines,deltaRho,deltaTheta,minVote, minLength, maxGap);
101 |
102 | return lines;
103 | }
104 |
105 | // Draw the detected lines on an image
106 | void drawDetectedLines(Mat &image, Scalar color=Scalar(255)) {
107 |
108 | // Draw the lines
109 | vector::const_iterator it2= lines.begin();
110 |
111 |
112 |
113 | while (it2!=lines.end()) {
114 |
115 | Point pt1((*it2)[0],(*it2)[1]+shift); //end coordinate
116 | Point pt2((*it2)[2],(*it2)[3]+shift); //start coordinate
117 |
118 |
119 | //This is to draw the line with end points
120 | line( image, pt1, pt2, color, 10 );
121 | //cout << " HoughP line: ("<< pt1 <<"," << pt2 << ")\n";
122 |
123 | ///This chunk of code is commented to disable SDLP calculation and display of its values///
124 |
125 | /*
126 | int Houghpt2x = (*it2)[2];
127 |
128 | //__android_log_print(ANDROID_LOG_ERROR, "HoughP line point 2", "Lane Type: %s, Value: %d", "Left Most Lane", Houghpt2x);
129 |
130 | int laneStatus = -1;
131 | stringstream stream;
132 |
133 |
134 | if(Houghpt2x >= 100 && Houghpt2x < 180 )
135 | {
136 | laneStatus = 3;
137 | __android_log_print(ANDROID_LOG_ERROR, "HoughP line point 2", "Lane Type: %s, Value: %d", "Left Lane", Houghpt2x);
138 | stream << "Lane Status : " << "Left lane";
139 |
140 | }
141 | else if(Houghpt2x >= 180 && Houghpt2x <= 220 )
142 | {
143 | laneStatus = 2;
144 | __android_log_print(ANDROID_LOG_ERROR, "HoughP line point 2", "Lane Type: %s, Value: %d", "Switching ..", Houghpt2x);
145 | stream << "Lane Status : " << "Switching ..";
146 |
147 | }
148 | else if(Houghpt2x > 220 && Houghpt2x <= 450 )
149 | {
150 | laneStatus = 1;
151 | __android_log_print(ANDROID_LOG_ERROR, "HoughP line point 2", "Lane Type: %s, Value : %d", "Right Lane", Houghpt2x);
152 | stream << "Lane Status : " << "Right lane";
153 |
154 | }
155 |
156 | //int LateralPosition = Houghpt2x - 300 - 75;
157 | //average width of car is 1.8 m
158 | //average width of double lane road is 3.3 * 2 = 6.6 m
159 |
160 | //e.g 450 x value = 1.65 lateral position value
161 | //e.g 350 x value = 1.89
162 | //scaling has 0 at left most that is the 0 for x coordinate as well
163 |
164 | //average vehicle width considered is 152 cm or 1.52 m and fixed lane width is used as 365 cm or 3.65 m
165 |
166 | double singleLaneWidth = 3.65; double avgCarWidth = 1.52;
167 | int lowerBound = 100; int upperBound = 450; //range of x coordinate of Hought Point
168 | double bestLateralPosition = avgCarWidth/2 + (((singleLaneWidth/2) - avgCarWidth)/2); // 0.915 - single lane //1.65 - when 2 lanes were considered
169 |
170 |
171 | //x coordinate of Hough point is inverseley proportional to lateral position
172 | double k = upperBound * bestLateralPosition;
173 | double lateralPosition = 0;
174 | if(Houghpt2x > 450)
175 | lateralPosition = bestLateralPosition;
176 | else if(Houghpt2x < 100)
177 | lateralPosition = singleLaneWidth;
178 | else
179 | lateralPosition = k / Houghpt2x;
180 |
181 |
182 | //preparing for SDLP
183 | if(lateralPosition > 0)
184 | {
185 | //calculating lateral position value for each instance
186 | lateralPosition = floor(lateralPosition*100 + 0.5)/100; //rounding off to 2 d.p
187 |
188 | //rounding off to 2 d.p
189 |
190 |
191 |
192 | //sumLateralPosition += lateralPosition;
193 | //arrayLateralPosition[countLateralPosition] = lateralPosition;
194 | //++countLateralPosition;
195 |
196 | LaneCalculations::Instance()->sumLateralPosition += lateralPosition;
197 | LaneCalculations::Instance()->arrayLateralPosition[LaneCalculations::Instance()->countLateralPosition] = lateralPosition;
198 | ++LaneCalculations::Instance()->countLateralPosition;
199 |
200 | __android_log_print(ANDROID_LOG_ERROR, "Line Finder", "count: %d", LaneCalculations::Instance()->countLateralPosition);
201 |
202 |
203 | //displaying output
204 | stringstream stream1;
205 | stream1 << "Lateral position : " << setprecision(3) << lateralPosition;
206 | __android_log_print(ANDROID_LOG_ERROR, "Line Finder", "Lateral Position: %f", lateralPosition);
207 |
208 | //displaying values on screen
209 | putText(image, stream1.str(), Point(50,image.rows-70), 1, 1, Scalar(0,255,255),0); //lateral position
210 | putText(image, stream.str(), Point(50,image.rows-30), 1, 1, Scalar(0,255,255),0); //lane status
211 |
212 |
213 | //displaying sdlp value which is in m. ideal is somewhere around 0.30 m for one lane. This SDLP shows value
214 | //after considerign 2 lanes -> 6.6 m
215 | if(LaneCalculations::Instance()->countLateralPosition >= 1000)
216 | {
217 | __android_log_print(ANDROID_LOG_ERROR, "Line Finder", "SDLP: %f", LaneCalculations::Instance()->calculateSDLP());
218 | stringstream stream2;
219 | stream2 << setprecision(3) << "SDLP : " << LaneCalculations::Instance()->calculateSDLP();
220 | putText(image, stream2.str(), Point(50,image.rows-110), 1, 1, Scalar(0,255,255),0);
221 | }
222 |
223 |
224 |
225 |
226 |
227 |
228 | }
229 |
230 | */
231 |
232 |
233 | ++it2;
234 | }
235 | }
236 |
237 |
238 | // Eliminates lines that do not have an orientation equals to
239 | // the ones specified in the input matrix of orientations
240 | // At least the given percentage of pixels on the line must
241 | // be within plus or minus delta of the corresponding orientation
242 | vector removeLinesOfInconsistentOrientations(
243 | const Mat &orientations, double percentage, double delta) {
244 |
245 | vector::iterator it= lines.begin();
246 |
247 | // check all lines
248 | while (it!=lines.end()) {
249 |
250 | // end points
251 | int x1= (*it)[0];
252 | int y1= (*it)[1];
253 | int x2= (*it)[2];
254 | int y2= (*it)[3];
255 |
256 | // line orientation + 90o to get the parallel line
257 | double ori1= atan2(static_cast(y1-y2),static_cast(x1-x2))+PI/2;
258 | if (ori1>PI) ori1= ori1-2*PI;
259 |
260 | double ori2= atan2(static_cast(y2-y1),static_cast(x2-x1))+PI/2;
261 | if (ori2>PI) ori2= ori2-2*PI;
262 |
263 | // for all points on the line
264 | LineIterator lit(orientations,Point(x1,y1),Point(x2,y2));
265 | int i,count=0;
266 | for(i = 0, count=0; i < lit.count; i++, ++lit) {
267 |
268 | float ori= *(reinterpret_cast(*lit));
269 |
270 | // is line orientation similar to gradient orientation ?
271 | if (min(fabs(ori-ori1),fabs(ori-ori2))(i);
277 |
278 | // set to zero lines of inconsistent orientation
279 | if (consistency < percentage) {
280 |
281 | (*it)[0]=(*it)[1]=(*it)[2]=(*it)[3]=0;
282 |
283 | }
284 |
285 | ++it;
286 | }
287 |
288 | return lines;
289 | }
290 | };
291 |
292 |
293 | #endif
294 |
--------------------------------------------------------------------------------
/jni/tum_andrive_Andrive.h:
--------------------------------------------------------------------------------
1 | /* DO NOT EDIT THIS FILE - it is machine generated */
2 | #include
3 | /* Header for class tum_andrive_Andrive */
4 |
5 | #ifndef _Included_tum_andrive_Andrive
6 | #define _Included_tum_andrive_Andrive
7 | #ifdef __cplusplus
8 | extern "C" {
9 | #endif
10 | /*
11 | * Class: tum_andrive_Andrive
12 | * Method: nativeThreshold
13 | * Signature: (JJ)V
14 | */
15 | JNIEXPORT void JNICALL Java_tum_andrive_Andrive_nativeThreshold
16 | (JNIEnv *, jobject, jlong, jlong);
17 |
18 | JNIEXPORT void JNICALL Java_tum_andrive_Andrive_nativeCannyEdge
19 | (JNIEnv *, jobject, jlong, jlong);
20 |
21 | #ifdef __cplusplus
22 | }
23 | #endif
24 | #endif
25 |
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libLaneDetectionNative.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libLaneDetectionNative.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libnative_camera_r2.2.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libnative_camera_r2.2.0.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libnative_camera_r2.3.3.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libnative_camera_r2.3.3.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libnative_camera_r3.0.1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libnative_camera_r3.0.1.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libnative_camera_r4.0.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libnative_camera_r4.0.0.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libnative_camera_r4.0.3.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libnative_camera_r4.0.3.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libnative_camera_r4.1.1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libnative_camera_r4.1.1.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libnative_camera_r4.2.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libnative_camera_r4.2.0.so
--------------------------------------------------------------------------------
/libs/armeabi-v7a/libopencv_java.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi-v7a/libopencv_java.so
--------------------------------------------------------------------------------
/libs/armeabi/libLaneDetectionNative.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libLaneDetectionNative.so
--------------------------------------------------------------------------------
/libs/armeabi/libnative_camera_r2.2.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libnative_camera_r2.2.0.so
--------------------------------------------------------------------------------
/libs/armeabi/libnative_camera_r2.3.3.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libnative_camera_r2.3.3.so
--------------------------------------------------------------------------------
/libs/armeabi/libnative_camera_r3.0.1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libnative_camera_r3.0.1.so
--------------------------------------------------------------------------------
/libs/armeabi/libnative_camera_r4.0.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libnative_camera_r4.0.0.so
--------------------------------------------------------------------------------
/libs/armeabi/libnative_camera_r4.0.3.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libnative_camera_r4.0.3.so
--------------------------------------------------------------------------------
/libs/armeabi/libnative_camera_r4.1.1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libnative_camera_r4.1.1.so
--------------------------------------------------------------------------------
/libs/armeabi/libnative_camera_r4.2.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libnative_camera_r4.2.0.so
--------------------------------------------------------------------------------
/libs/armeabi/libopencv_java.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/armeabi/libopencv_java.so
--------------------------------------------------------------------------------
/libs/mips/libLaneDetectionNative.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/mips/libLaneDetectionNative.so
--------------------------------------------------------------------------------
/libs/mips/libnative_camera_r4.0.3.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/mips/libnative_camera_r4.0.3.so
--------------------------------------------------------------------------------
/libs/mips/libnative_camera_r4.1.1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/mips/libnative_camera_r4.1.1.so
--------------------------------------------------------------------------------
/libs/mips/libnative_camera_r4.2.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/mips/libnative_camera_r4.2.0.so
--------------------------------------------------------------------------------
/libs/mips/libopencv_java.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/mips/libopencv_java.so
--------------------------------------------------------------------------------
/libs/x86/libLaneDetectionNative.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/x86/libLaneDetectionNative.so
--------------------------------------------------------------------------------
/libs/x86/libnative_camera_r2.3.3.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/x86/libnative_camera_r2.3.3.so
--------------------------------------------------------------------------------
/libs/x86/libnative_camera_r3.0.1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/x86/libnative_camera_r3.0.1.so
--------------------------------------------------------------------------------
/libs/x86/libnative_camera_r4.0.3.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/x86/libnative_camera_r4.0.3.so
--------------------------------------------------------------------------------
/libs/x86/libnative_camera_r4.1.1.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/x86/libnative_camera_r4.1.1.so
--------------------------------------------------------------------------------
/libs/x86/libnative_camera_r4.2.0.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/x86/libnative_camera_r4.2.0.so
--------------------------------------------------------------------------------
/libs/x86/libopencv_java.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/libs/x86/libopencv_java.so
--------------------------------------------------------------------------------
/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/local.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 |
7 | # location of the SDK. This is only used by Ant
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/home/falooka/adt-bundle-linux-x86-20130917/sdk
11 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-18
15 | android.library.reference.1=../OpenCV Library - 2.4.6
16 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wahibhaq/android-opencv-lanedetection/d2625364a802b42173e36f1436b2e3b0668581ad/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_lane_test.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
14 |
15 |
--------------------------------------------------------------------------------
/res/layout/activity_selection.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
41 |
42 |
51 |
52 |
60 |
61 |
71 |
72 |
83 |
84 |
93 |
94 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Andrive
5 | Settings
6 | Hello world!
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/tum/andrive/lanedetection/LaneDetector.java:
--------------------------------------------------------------------------------
1 |
2 | package tum.andrive.lanedetection;
3 |
4 | import org.opencv.android.BaseLoaderCallback;
5 | import org.opencv.android.CameraBridgeViewBase;
6 | import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
7 | import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
8 | import org.opencv.android.LoaderCallbackInterface;
9 | import org.opencv.android.OpenCVLoader;
10 | import org.opencv.core.CvType;
11 | import org.opencv.core.Mat;
12 |
13 | import android.app.Activity;
14 | import android.content.Intent;
15 | import android.os.Bundle;
16 | import android.util.Log;
17 | import android.view.SurfaceView;
18 | import android.view.WindowManager;
19 | import android.widget.Toast;
20 |
21 | /**
22 | *
23 | * This is the main Activity which takes Camera input, captures frame, interact with OpenCV library, process frame and display overlays
24 | * on lanes detection. It uses Hough Value which is provided by the VerticalSliderActivity. This java activity acts as the Controller
25 | * here and core image processing work is done by the C++ files
26 | *
27 | * @author Wahib-Ul-Haq, wahib.tech@gmail.com, 2014
28 | *
29 | * contains code taken from:
30 | *
31 | * "Lane detection using OpenCV"
32 | * https://github.com/jdorweiler/lane-detection
33 | * Acknowledgments: jdorweiler
34 | * Contact: jason@transistor.io
35 | */
36 |
37 | public class LaneDetector extends Activity implements CvCameraViewListener2 {
38 |
39 | private CameraBridgeViewBase mOpenCvCameraView;
40 | private static final String TAG = "OCVSample::Activity";
41 | private Mat img;
42 | private int houghValue;
43 | private Mat mRgba;
44 | private int screen_w, screen_h;
45 |
46 | private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
47 | @Override
48 | public void onManagerConnected(int status) {
49 | switch (status) {
50 | case LoaderCallbackInterface.SUCCESS:
51 | {
52 | Log.i(TAG, "OpenCV loaded successfully");
53 | System.loadLibrary("LaneDetectionNative"); //library module name defined in Android.mk
54 | mOpenCvCameraView.enableView();
55 |
56 | }
57 | break;
58 |
59 | default:
60 | {
61 | super.onManagerConnected(status);
62 | } break;
63 | }
64 |
65 | }
66 | };
67 |
68 | @Override
69 | public void onResume() {
70 |
71 | super.onResume();
72 | OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);
73 | }
74 |
75 | @Override
76 | protected void onCreate(Bundle savedInstanceState) {
77 |
78 | Log.i(TAG, "called onCreate");
79 | super.onCreate(savedInstanceState);
80 | getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
81 |
82 | setContentView(R.layout.activity_lane_test);
83 | mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.AndriveLaneView);
84 | mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
85 | mOpenCvCameraView.setCvCameraViewListener(this);
86 |
87 | Intent intent = getIntent();
88 | houghValue = Integer.valueOf(intent.getStringExtra("houghvalue"));
89 | Toast.makeText(getApplicationContext(), String.valueOf(houghValue), Toast.LENGTH_LONG).show();
90 |
91 | }
92 |
93 | @Override
94 | protected void onPause() {
95 | super.onPause();
96 | if (mOpenCvCameraView != null) {
97 | mOpenCvCameraView.disableView();
98 | }
99 | };
100 |
101 | @Override
102 | protected void onDestroy() {
103 | super.onDestroy();
104 | if (mOpenCvCameraView != null) {
105 | mOpenCvCameraView.disableView();
106 | }
107 | };
108 |
109 |
110 | @Override
111 | public void onCameraViewStarted(int width, int height) {
112 |
113 | Log.v("Screen Resolution","Height: "+height+" Width: "+width);
114 |
115 |
116 | img = new Mat(height, width, CvType.CV_8UC4);
117 |
118 | };
119 |
120 | @Override
121 | public void onCameraViewStopped() {
122 | img.release();
123 | };
124 |
125 | @Override
126 | public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
127 |
128 |
129 | mainDelegate(inputFrame.rgba().getNativeObjAddr(), img.getNativeObjAddr(), houghValue);
130 |
131 | return img;
132 |
133 |
134 | }
135 |
136 |
137 | public native void mainDelegate(long input, long output, int houghValue);
138 |
139 |
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/src/tum/andrive/lanedetection/VerticalSeekBar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Custom implementation of Seekbar Widget
3 | *
4 | */
5 |
6 | package tum.andrive.lanedetection;
7 |
8 | import android.content.Context;
9 | import android.graphics.Canvas;
10 | import android.util.AttributeSet;
11 | import android.view.MotionEvent;
12 | import android.widget.SeekBar;
13 |
14 | public class VerticalSeekBar extends SeekBar {
15 |
16 | public VerticalSeekBar(Context context) {
17 |
18 | super(context);
19 |
20 | }
21 |
22 | public VerticalSeekBar(Context context, AttributeSet attrs, int defStyle) {
23 |
24 | super(context, attrs, defStyle);
25 | }
26 |
27 | public VerticalSeekBar(Context context, AttributeSet attrs) {
28 |
29 | super(context, attrs);
30 | }
31 |
32 |
33 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
34 |
35 | super.onSizeChanged(h, w, oldh, oldw);
36 |
37 | }
38 |
39 | @Override
40 | protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
41 |
42 | super.onMeasure(heightMeasureSpec, widthMeasureSpec);
43 | setMeasuredDimension(getMeasuredHeight(), getMeasuredWidth());
44 | }
45 |
46 |
47 | protected void onDraw(Canvas c) {
48 |
49 | c.rotate(-90);
50 | c.translate(-getHeight(), 0);
51 |
52 | super.onDraw(c);
53 |
54 | }
55 |
56 |
57 | @Override
58 |
59 | public boolean onTouchEvent(MotionEvent event) {
60 |
61 |
62 | if (!isEnabled()) {
63 |
64 | return false;
65 | }
66 |
67 | switch (event.getAction()) {
68 |
69 |
70 | case MotionEvent.ACTION_DOWN:
71 |
72 | case MotionEvent.ACTION_MOVE:
73 |
74 | case MotionEvent.ACTION_UP:
75 |
76 | setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
77 |
78 | onSizeChanged(getWidth(), getHeight(), 0, 0);
79 |
80 | break;
81 |
82 | case MotionEvent.ACTION_CANCEL:
83 |
84 | break;
85 |
86 |
87 | }
88 |
89 | return true;
90 |
91 |
92 | }
93 |
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/tum/andrive/lanedetection/VerticalSliderActivity.java:
--------------------------------------------------------------------------------
1 |
2 | package tum.andrive.lanedetection;
3 |
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.View.OnClickListener;
9 | import android.widget.Button;
10 | import android.widget.SeekBar;
11 | import android.widget.SeekBar.OnSeekBarChangeListener;
12 | import android.widget.TextView;
13 |
14 | /**
15 | * The Activity for Vertical Slider display to take input of Hough Transform value
16 | *
17 | * @author Wahib-Ul-Haq
18 | *
19 | */
20 |
21 | public class VerticalSliderActivity extends Activity {
22 |
23 | private Button forwardButton;
24 | private TextView sliderText;
25 | private VerticalSeekBar verticalSeebar;
26 |
27 | @Override
28 | public void onCreate(Bundle savedInstanceState) {
29 |
30 |
31 | super.onCreate(savedInstanceState);
32 |
33 | setContentView(R.layout.activity_selection);
34 |
35 | sliderText = (TextView) findViewById(R.id.verticalSeekbarText);
36 | forwardButton = (Button)findViewById(R.id.forwardButton);
37 | verticalSeebar = (VerticalSeekBar)findViewById(R.id.verticalSeekbar);
38 |
39 | forwardButton.setOnClickListener(new OnClickListener() {
40 |
41 | @Override
42 | public void onClick(View arg0) {
43 |
44 | // TODO Auto-generated method stub
45 | Intent intent = new Intent(getApplicationContext(), LaneDetector.class);
46 | intent.putExtra("houghvalue", sliderText.getText().toString());
47 | startActivity(intent);
48 | }
49 |
50 | });
51 |
52 |
53 | verticalSeebar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
54 |
55 | @Override
56 | public void onStopTrackingTouch(SeekBar seekBar) {
57 |
58 | }
59 |
60 | @Override
61 | public void onStartTrackingTouch(SeekBar seekBar) {
62 |
63 | }
64 |
65 | @Override
66 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
67 |
68 | sliderText.setText(""+progress);
69 |
70 | }
71 |
72 |
73 | });
74 |
75 |
76 | }
77 |
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/tum/andrive/lanedetection/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | */
4 | /**
5 | * @author falooka
6 | *
7 | */
8 | package tum.andrive.lanedetection;
--------------------------------------------------------------------------------