Skip to content

Commit

Permalink
add sobelx and s channel thresholding
Browse files Browse the repository at this point in the history
  • Loading branch information
cdemutiis committed Mar 16, 2017
1 parent 1b6ce5a commit 4f62cbe
Show file tree
Hide file tree
Showing 51 changed files with 77 additions and 19 deletions.
49 changes: 39 additions & 10 deletions .ipynb_checkpoints/P4_advanced_lanes_detection-checkpoint.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@
"source": [
"# This function makes sure that each processed image is saved in the \n",
"# appropriate folder \n",
"def save_img(img, folder, fname, stage_name):\n",
"def save_img(img, folder, fname, stage_name, col_map):\n",
" fname = fname.split('/')[1]\n",
" fname = fname.split('.')[0]\n",
" new_filename = fname + \"_\" + stage_name + '.jpg' \n",
" mpimg.imsave(folder + \"/\" + new_filename, img)"
" mpimg.imsave(folder + \"/\" + new_filename, img,cmap=col_map)"
]
},
{
Expand Down Expand Up @@ -121,7 +121,7 @@
" img = mpimg.imread(fname)\n",
" \n",
" # Convert image to grayscale\n",
" gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n",
" gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)\n",
" \n",
" # Find the chessboard corners\n",
" ret, corners = cv2.findChessboardCorners(gray, (9,6),None)\n",
Expand All @@ -137,7 +137,7 @@
" # get the undistorted version of the calibration image\n",
" undistorted = cal_undistort(img, objpoints, imgpoints)\n",
" \n",
" save_img(undistorted, \"camera_cal/undistorted_images\", fname, \"undist\")"
" save_img(undistorted, \"camera_cal/undistorted_images\", fname, \"undist\", col_map = 'jet')"
]
},
{
Expand All @@ -153,21 +153,50 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Create the output_images directory \n",
"# Create the undistorted directory \n",
"if not os.path.exists(\"output_images/undistorted\"):\n",
" os.makedirs(\"output_images/undistorted\")\n",
"# Create the binary directory \n",
"if not os.path.exists(\"output_images/binary\"):\n",
" os.makedirs(\"output_images/binary\")\n",
" \n",
"# This function processes each individual image coming from the video stream \n",
"# and estimates where the lane lines are\n",
"def image_pipeline(img, fname):\n",
" undistorted = cal_undistort(img, objpoints, imgpoints)\n",
" save_img(undistorted, \"output_images/undistorted\", fname, \"_undistorted\")\n",
" return undistorted"
" save_img(undistorted, \"output_images/undistorted\", fname, \"undistorted\", col_map = 'jet')\n",
" \n",
" s_thresh=(170, 255)\n",
" sx_thresh=(20, 100)\n",
" \n",
" # Convert to HSV color space and separate the V channel\n",
" hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HLS).astype(np.float)\n",
" l_channel = hsv[:,:,1]\n",
" s_channel = hsv[:,:,2]\n",
" \n",
" # Sobel x\n",
" sobelx = cv2.Sobel(l_channel, cv2.CV_64F, 1, 0) # Take the derivative in x\n",
" abs_sobelx = np.absolute(sobelx) # Absolute x derivative to accentuate lines away from horizontal\n",
" scaled_sobel = np.uint8(255*abs_sobelx/np.max(abs_sobelx))\n",
"\n",
" # Threshold x gradient\n",
" sxbinary = np.zeros_like(scaled_sobel)\n",
" sxbinary[(scaled_sobel >= sx_thresh[0]) & (scaled_sobel <= sx_thresh[1])] = 1\n",
" \n",
" # Threshold color channel\n",
" s_binary = np.zeros_like(s_channel)\n",
" s_binary[(s_channel >= s_thresh[0]) & (s_channel <= s_thresh[1])] = 1\n",
"\n",
" binary_final = sxbinary + s_binary\n",
" save_img(binary_final, \"output_images/binary\", fname, \"binary\", col_map = 'gray')\n",
" \n",
" return binary_final "
]
},
{
Expand All @@ -181,7 +210,7 @@
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
Expand All @@ -198,7 +227,7 @@
" \n",
" result = image_pipeline(img, fname)\n",
" \n",
" save_img(result, \"output_images\", fname, \"final\")"
" save_img(result, \"output_images\", fname, \"final\", col_map = 'gray')"
]
},
{
Expand Down
47 changes: 38 additions & 9 deletions P4_advanced_lanes_detection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@
"source": [
"# This function makes sure that each processed image is saved in the \n",
"# appropriate folder \n",
"def save_img(img, folder, fname, stage_name):\n",
"def save_img(img, folder, fname, stage_name, col_map):\n",
" fname = fname.split('/')[1]\n",
" fname = fname.split('.')[0]\n",
" new_filename = fname + \"_\" + stage_name + '.jpg' \n",
" mpimg.imsave(folder + \"/\" + new_filename, img)"
" mpimg.imsave(folder + \"/\" + new_filename, img,cmap=col_map)"
]
},
{
Expand Down Expand Up @@ -121,7 +121,7 @@
" img = mpimg.imread(fname)\n",
" \n",
" # Convert image to grayscale\n",
" gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n",
" gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)\n",
" \n",
" # Find the chessboard corners\n",
" ret, corners = cv2.findChessboardCorners(gray, (9,6),None)\n",
Expand All @@ -137,7 +137,7 @@
" # get the undistorted version of the calibration image\n",
" undistorted = cal_undistort(img, objpoints, imgpoints)\n",
" \n",
" save_img(undistorted, \"camera_cal/undistorted_images\", fname, \"undist\")"
" save_img(undistorted, \"camera_cal/undistorted_images\", fname, \"undist\", col_map = 'jet')"
]
},
{
Expand All @@ -159,15 +159,44 @@
},
"outputs": [],
"source": [
"# Create the output_images directory \n",
"# Create the undistorted directory \n",
"if not os.path.exists(\"output_images/undistorted\"):\n",
" os.makedirs(\"output_images/undistorted\")\n",
"# Create the binary directory \n",
"if not os.path.exists(\"output_images/binary\"):\n",
" os.makedirs(\"output_images/binary\")\n",
" \n",
"# This function processes each individual image coming from the video stream \n",
"# and estimates where the lane lines are\n",
"def image_pipeline(img, fname):\n",
" undistorted = cal_undistort(img, objpoints, imgpoints)\n",
" save_img(undistorted, \"output_images/undistorted\", fname, \"_undistorted\")\n",
" return undistorted"
" save_img(undistorted, \"output_images/undistorted\", fname, \"undistorted\", col_map = 'jet')\n",
" \n",
" s_thresh=(170, 255)\n",
" sx_thresh=(20, 100)\n",
" \n",
" # Convert to HSV color space and separate the V channel\n",
" hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HLS).astype(np.float)\n",
" l_channel = hsv[:,:,1]\n",
" s_channel = hsv[:,:,2]\n",
" \n",
" # Sobel x\n",
" sobelx = cv2.Sobel(l_channel, cv2.CV_64F, 1, 0) # Take the derivative in x\n",
" abs_sobelx = np.absolute(sobelx) # Absolute x derivative to accentuate lines away from horizontal\n",
" scaled_sobel = np.uint8(255*abs_sobelx/np.max(abs_sobelx))\n",
"\n",
" # Threshold x gradient\n",
" sxbinary = np.zeros_like(scaled_sobel)\n",
" sxbinary[(scaled_sobel >= sx_thresh[0]) & (scaled_sobel <= sx_thresh[1])] = 1\n",
" \n",
" # Threshold color channel\n",
" s_binary = np.zeros_like(s_channel)\n",
" s_binary[(s_channel >= s_thresh[0]) & (s_channel <= s_thresh[1])] = 1\n",
"\n",
" binary_final = sxbinary + s_binary\n",
" save_img(binary_final, \"output_images/binary\", fname, \"binary\", col_map = 'gray')\n",
" \n",
" return binary_final "
]
},
{
Expand All @@ -181,7 +210,7 @@
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
"collapsed": false
},
"outputs": [],
"source": [
Expand All @@ -198,7 +227,7 @@
" \n",
" result = image_pipeline(img, fname)\n",
" \n",
" save_img(result, \"output_images\", fname, \"final\")"
" save_img(result, \"output_images\", fname, \"final\", col_map = 'gray')"
]
},
{
Expand Down
Binary file modified camera_cal/undistorted_images/calibration10_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration11_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration12_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration13_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration14_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration15_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration16_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration17_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration18_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration19_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration20_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration2_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration3_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration6_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration7_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration8_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified camera_cal/undistorted_images/calibration9_undist.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/straight_lines1_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/straight_lines2_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/test1_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/test2_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/test3_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/test4_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/test5_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output_images/binary/test6_binary.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output_images/straight_lines1_final.jpg
Binary file modified output_images/straight_lines2_final.jpg
Binary file modified output_images/test1_final.jpg
Binary file modified output_images/test2_final.jpg
Binary file modified output_images/test3_final.jpg
Binary file modified output_images/test4_final.jpg
Binary file modified output_images/test5_final.jpg
Binary file modified output_images/test6_final.jpg
Binary file modified output_images/undistorted/straight_lines1__undistorted.jpg
Binary file modified output_images/undistorted/straight_lines2__undistorted.jpg
Binary file modified output_images/undistorted/test1__undistorted.jpg
Binary file added output_images/undistorted/test1_undistorted.jpg
Binary file modified output_images/undistorted/test2__undistorted.jpg
Binary file added output_images/undistorted/test2_undistorted.jpg
Binary file modified output_images/undistorted/test3__undistorted.jpg
Binary file added output_images/undistorted/test3_undistorted.jpg
Binary file modified output_images/undistorted/test4__undistorted.jpg
Binary file added output_images/undistorted/test4_undistorted.jpg
Binary file modified output_images/undistorted/test5__undistorted.jpg
Binary file added output_images/undistorted/test5_undistorted.jpg
Binary file modified output_images/undistorted/test6__undistorted.jpg
Binary file added output_images/undistorted/test6_undistorted.jpg

0 comments on commit 4f62cbe

Please sign in to comment.