SlideShare uma empresa Scribd logo
1 de 10
Baixar para ler offline
Udacity Self Driving Cars Nanodegree- Advanced Lane Finding Project
Objective:
The objective is to write a Python program to identify the lane boundaries in a video from a front-facing
camera on a car. The camera calibration images, test road images, and project videos are provided.
Steps:
1. Removing Distortion
2. Isolate Lanes
3. Warp
4. Curve Fit
5. Final Image
1. Removing distortion:
Cameras use lens which distort image. OpenCV provides function to correct these distortions and to
calibrate the camera.
A set of 20 chess board images were used to calibrate camera.
First, a set of chess board image are passed to findChessboardCorners function to get the corner
points, thru the following code:
Ret, corners=cv2.findChessboardCorners (gray, (9, 6), None)
Then, the corner points discovered are passed to the calibrate Camera function, thru the following
code:
Ret,mtx,dist,rvecs,tvecs=cv2.calibrateCamera(objpoints,imgpoints,gray.shape[::-1],None,None)
This function returns the camera matrix and the distortion coefficients which are then passed to
undistort function to correct the distortion of the images, thru the following code:
undist=cv2.undistort(img,mtx,dist,None,mtx)
The following image shows the Original image and the undistorted image side by side:
2. Isolate Lanes:
Then, color and direction gradients are applied to isolate lanes. Color spaces (RGB, HSV, HLS, LAB, etc.)
are explored for the images to see which channels of these color spaces may be used to distinguish
lane markings based on colors. In our example, S channel of HLS color space and V channel of the HSV
color space was used.
Then, direction gradient (Sobel filter) is used to detect lanes based on change of intensity (edge
detection) where lane markings exists. Both color channels and Sobel filters are applied with the
appropriate thresholds to isolate lane lines.
OpenCV provides cvtColor function to convert the image to different color spaces, like the following
conversion to HLS and HSV color spaces:
hls=cv2.cvtColor (RGB, cv2.COLOR_RGB2HLS) hsv=cv2.cvtColor(img,cv2.COLOR_RGB2HSV)
The following image shows the image after passed to Sobel x operator (with the appropriate
threshold):
The following image shows the image after passed to Sobel y operator (with the appropriate
threshold):
The following image shows the image after passed thru the Color spaces (S channel of HLS and V
channel of HSV):
The following image shows the image after passed thru the combination of Sobel and Color spaces
channels thresholds:
3. Warp:
Source and destination points are passed to the getPerspective function, thru the following code:
M=cv2.getPerspectiveTransform (src, dst)
This results in a Transformation Matrix M, which along with the original image is passed to the
warpPerspective function to get a bird’s eye view (warped perspective) of the image. Following code is
used:
Warped=cv2.warpPerspective(img,M,img_size)
The following image shows Undistorted image with Source points drawn along with the Warped image
with destination points drawn:
4. Curve Fit:
Find the left and the right lines and then apply curve fit to those lines.
We take a histogram of the bottom half of the image and we determine where the lane lines start based
on wherever the histogram peaks are. Y value is sum of the pixels at that x location and the 2 maximums
are where the lines start.
Following code is used:
Histogram=np.sum(img[img.shape[0]//2:,:],axis=0]
Leftx_base=np.argmax(histogram[:midpoint])
Rightx_base=np.argmax(histogram[midpoint:]+midpoint Following
image shows histogram output:
Then, we use a sliding windows technique described as follows: we draw a box around the lane starting
points and any of the white pixels from the binary image that fall into that box; we put them in a list of
x and y values. Then, we add a box on top of that and do the same thing and as we move up the lane
line; we will move the boxes to the left or right based on the average of the previous line. At the end of
this; we will have lists of x and y values of the pixels that are in the line and then we run the 2nd order
numpy polyfit to those pixels to get the curve fit in the pixel space. Following code is used:
Left_fit=np.polyfit(lefty,leftx,2) Right_fit=np.polyfit(righty,rightx,2)
We then do the pixel to meters conversion based on US Highway standards (lanes are 12 feet wide).
After the first window frame; instead of the sliding windows technique; we take the previous fit and
move it to left and right by 100 pixels and any pixels (minimum 50) found in that area are added to the
list of x and y values and then we run the polyfit function to get the lane lines.
The following image shows curve fit with sliding windows technique.
The following image shows curve fit where the program looks for the next lane point within 100 pixels of
the previous fit.
5. Final Image:
Then, we create the final image and put text (using putText function) on the image for the Radius of
curvature and the Distance to lane center; which are calculated using the following formulae:
Radius of curvature=([1+(dy/dx)^2]^3/2)/(d^2y/dx^2)
laneCenter=(rigthPos-leftPos)/2+leftPOs
distancetoCenter=laneCenter-imageCenter
Then, we plot the curve fits and green color the drive area onto the image using fillPoly and polylines
function as shown below:
Cv2.fillPoly(color_warp,np.int_([pts]),(0,255,0))
We want to overlay on the original image and not the warped image. So we need to unwarp the image
(using undistort function reversing the source and destination points) and then add to the original
(using addWeighted function) as below.
Result=cv2.addWeighted(img,1,newwarp,0.5,0)
The following image shows the final drawn image with color filled between the lane lines.
The following image shows the final drawn image with color filled between the lane lines; and text
illustrating radius of curvature and distance from center.
Improvement Points:
There is lot of manual effort in the following areas; so the program will not scale well for all videos and
images:
1. Selection of best channels from the color spaces, which are used for lanes detection
2. Selection of thresholds (minimum and maximum) and parameters (example, kernel size) for
Sobel filter and for color spaces
3. Selection of source and destination points for perspective transform
A deep learning/machine learning approach will be more appropriate for the above points; so the
program can learn those parameters itself; rather than we manually specifying or selecting those
parameters.

Mais conteúdo relacionado

Mais procurados (19)

Computer Graphics Concepts
Computer Graphics ConceptsComputer Graphics Concepts
Computer Graphics Concepts
 
C Graphics Functions
C Graphics FunctionsC Graphics Functions
C Graphics Functions
 
Feature Extraction
Feature ExtractionFeature Extraction
Feature Extraction
 
ECE 565 Project1
ECE 565 Project1ECE 565 Project1
ECE 565 Project1
 
Templateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer VisionTemplateless Marked Element Recognition Using Computer Vision
Templateless Marked Element Recognition Using Computer Vision
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Graphics in C programming
Graphics in C programmingGraphics in C programming
Graphics in C programming
 
Lecture on graphics
Lecture on graphicsLecture on graphics
Lecture on graphics
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Computer Graphics Practical
Computer Graphics PracticalComputer Graphics Practical
Computer Graphics Practical
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
Matlab Visualizing Data
Matlab Visualizing DataMatlab Visualizing Data
Matlab Visualizing Data
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
 
Computer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1bComputer Graphics in Java and Scala - Part 1b
Computer Graphics in Java and Scala - Part 1b
 
Computer graphics
Computer graphicsComputer graphics
Computer graphics
 
Applets
AppletsApplets
Applets
 
Line Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - NotesLine Drawing Algorithms - Computer Graphics - Notes
Line Drawing Algorithms - Computer Graphics - Notes
 

Semelhante a Writeup advanced lane_lines_project

Anish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_ReportAnish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_Reportanish h
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfRajJain516913
 
computer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodecomputer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodeBhavya Chawla
 
Introduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABIntroduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABSriram Emarose
 
OpenCV presentation series- part 3
OpenCV presentation series- part 3OpenCV presentation series- part 3
OpenCV presentation series- part 3Sairam Adithya
 
19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptx
19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptx19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptx
19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptxSamridhGarg
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlabAman Gupta
 
We are restricted from importing cv2 numpy stats and other.pdf
We are restricted from importing cv2 numpy stats and other.pdfWe are restricted from importing cv2 numpy stats and other.pdf
We are restricted from importing cv2 numpy stats and other.pdfDARSHANACHARYA13
 
Computer graphic
Computer graphicComputer graphic
Computer graphicnusratema1
 
05 contours seg_matching
05 contours seg_matching05 contours seg_matching
05 contours seg_matchingankit_ppt
 
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionSimple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionAnish Patel
 
Estrazione automatica delle linee in un'immagine digitale
Estrazione automatica delle linee in un'immagine digitaleEstrazione automatica delle linee in un'immagine digitale
Estrazione automatica delle linee in un'immagine digitalefrancescapadoin
 
Chapter v(drawing)
Chapter v(drawing)Chapter v(drawing)
Chapter v(drawing)Chhom Karath
 

Semelhante a Writeup advanced lane_lines_project (20)

Anish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_ReportAnish_Hemmady_assignmnt1_Report
Anish_Hemmady_assignmnt1_Report
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdfCD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
CD504 CGM_Lab Manual_004e08d3838702ed11fc6d03cc82f7be.pdf
 
computer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcodecomputer graphics-C/C++-dancingdollcode
computer graphics-C/C++-dancingdollcode
 
Introduction to Image Processing with MATLAB
Introduction to Image Processing with MATLABIntroduction to Image Processing with MATLAB
Introduction to Image Processing with MATLAB
 
OpenCV presentation series- part 3
OpenCV presentation series- part 3OpenCV presentation series- part 3
OpenCV presentation series- part 3
 
19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptx
19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptx19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptx
19BCS1815_PresentationAutomatic Number Plate Recognition(ANPR)P.pptx
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
 
Shi.pdf
Shi.pdfShi.pdf
Shi.pdf
 
canvas.pptx
canvas.pptxcanvas.pptx
canvas.pptx
 
We are restricted from importing cv2 numpy stats and other.pdf
We are restricted from importing cv2 numpy stats and other.pdfWe are restricted from importing cv2 numpy stats and other.pdf
We are restricted from importing cv2 numpy stats and other.pdf
 
Computer graphic
Computer graphicComputer graphic
Computer graphic
 
Animation ppt
Animation pptAnimation ppt
Animation ppt
 
Primitives
PrimitivesPrimitives
Primitives
 
05 contours seg_matching
05 contours seg_matching05 contours seg_matching
05 contours seg_matching
 
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer VisionSimple Pendulum Experiment and Automatic Survey Grading using Computer Vision
Simple Pendulum Experiment and Automatic Survey Grading using Computer Vision
 
Estrazione automatica delle linee in un'immagine digitale
Estrazione automatica delle linee in un'immagine digitaleEstrazione automatica delle linee in un'immagine digitale
Estrazione automatica delle linee in un'immagine digitale
 
Report
ReportReport
Report
 
Chapter v(drawing)
Chapter v(drawing)Chapter v(drawing)
Chapter v(drawing)
 

Último

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Último (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Writeup advanced lane_lines_project

  • 1. Udacity Self Driving Cars Nanodegree- Advanced Lane Finding Project Objective: The objective is to write a Python program to identify the lane boundaries in a video from a front-facing camera on a car. The camera calibration images, test road images, and project videos are provided. Steps: 1. Removing Distortion 2. Isolate Lanes 3. Warp 4. Curve Fit 5. Final Image 1. Removing distortion: Cameras use lens which distort image. OpenCV provides function to correct these distortions and to calibrate the camera. A set of 20 chess board images were used to calibrate camera. First, a set of chess board image are passed to findChessboardCorners function to get the corner points, thru the following code: Ret, corners=cv2.findChessboardCorners (gray, (9, 6), None) Then, the corner points discovered are passed to the calibrate Camera function, thru the following code: Ret,mtx,dist,rvecs,tvecs=cv2.calibrateCamera(objpoints,imgpoints,gray.shape[::-1],None,None) This function returns the camera matrix and the distortion coefficients which are then passed to undistort function to correct the distortion of the images, thru the following code: undist=cv2.undistort(img,mtx,dist,None,mtx) The following image shows the Original image and the undistorted image side by side:
  • 2. 2. Isolate Lanes: Then, color and direction gradients are applied to isolate lanes. Color spaces (RGB, HSV, HLS, LAB, etc.) are explored for the images to see which channels of these color spaces may be used to distinguish lane markings based on colors. In our example, S channel of HLS color space and V channel of the HSV color space was used. Then, direction gradient (Sobel filter) is used to detect lanes based on change of intensity (edge detection) where lane markings exists. Both color channels and Sobel filters are applied with the appropriate thresholds to isolate lane lines. OpenCV provides cvtColor function to convert the image to different color spaces, like the following conversion to HLS and HSV color spaces: hls=cv2.cvtColor (RGB, cv2.COLOR_RGB2HLS) hsv=cv2.cvtColor(img,cv2.COLOR_RGB2HSV) The following image shows the image after passed to Sobel x operator (with the appropriate threshold):
  • 3. The following image shows the image after passed to Sobel y operator (with the appropriate threshold): The following image shows the image after passed thru the Color spaces (S channel of HLS and V channel of HSV):
  • 4. The following image shows the image after passed thru the combination of Sobel and Color spaces channels thresholds:
  • 5. 3. Warp: Source and destination points are passed to the getPerspective function, thru the following code: M=cv2.getPerspectiveTransform (src, dst) This results in a Transformation Matrix M, which along with the original image is passed to the warpPerspective function to get a bird’s eye view (warped perspective) of the image. Following code is used: Warped=cv2.warpPerspective(img,M,img_size) The following image shows Undistorted image with Source points drawn along with the Warped image with destination points drawn: 4. Curve Fit: Find the left and the right lines and then apply curve fit to those lines. We take a histogram of the bottom half of the image and we determine where the lane lines start based on wherever the histogram peaks are. Y value is sum of the pixels at that x location and the 2 maximums are where the lines start. Following code is used:
  • 6. Histogram=np.sum(img[img.shape[0]//2:,:],axis=0] Leftx_base=np.argmax(histogram[:midpoint]) Rightx_base=np.argmax(histogram[midpoint:]+midpoint Following image shows histogram output: Then, we use a sliding windows technique described as follows: we draw a box around the lane starting points and any of the white pixels from the binary image that fall into that box; we put them in a list of x and y values. Then, we add a box on top of that and do the same thing and as we move up the lane line; we will move the boxes to the left or right based on the average of the previous line. At the end of this; we will have lists of x and y values of the pixels that are in the line and then we run the 2nd order numpy polyfit to those pixels to get the curve fit in the pixel space. Following code is used: Left_fit=np.polyfit(lefty,leftx,2) Right_fit=np.polyfit(righty,rightx,2)
  • 7. We then do the pixel to meters conversion based on US Highway standards (lanes are 12 feet wide). After the first window frame; instead of the sliding windows technique; we take the previous fit and move it to left and right by 100 pixels and any pixels (minimum 50) found in that area are added to the list of x and y values and then we run the polyfit function to get the lane lines. The following image shows curve fit with sliding windows technique.
  • 8. The following image shows curve fit where the program looks for the next lane point within 100 pixels of the previous fit. 5. Final Image: Then, we create the final image and put text (using putText function) on the image for the Radius of curvature and the Distance to lane center; which are calculated using the following formulae: Radius of curvature=([1+(dy/dx)^2]^3/2)/(d^2y/dx^2) laneCenter=(rigthPos-leftPos)/2+leftPOs distancetoCenter=laneCenter-imageCenter Then, we plot the curve fits and green color the drive area onto the image using fillPoly and polylines function as shown below: Cv2.fillPoly(color_warp,np.int_([pts]),(0,255,0)) We want to overlay on the original image and not the warped image. So we need to unwarp the image (using undistort function reversing the source and destination points) and then add to the original (using addWeighted function) as below. Result=cv2.addWeighted(img,1,newwarp,0.5,0) The following image shows the final drawn image with color filled between the lane lines.
  • 9. The following image shows the final drawn image with color filled between the lane lines; and text illustrating radius of curvature and distance from center.
  • 10. Improvement Points: There is lot of manual effort in the following areas; so the program will not scale well for all videos and images: 1. Selection of best channels from the color spaces, which are used for lanes detection 2. Selection of thresholds (minimum and maximum) and parameters (example, kernel size) for Sobel filter and for color spaces 3. Selection of source and destination points for perspective transform A deep learning/machine learning approach will be more appropriate for the above points; so the program can learn those parameters itself; rather than we manually specifying or selecting those parameters.