<jupyter_start><jupyter_text>Find lane lines advanced<jupyter_code>%load_ext autoreload
%autoreload 2

root_folder = './'

import sys 
import cv2
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import glob
import importlib

sys.path.append(root_folder + 'src/')

from camera import camera
from gradient import gradient

%matplotlib inline

# Initialize camera
cam = camera(root_folder + 'camera_cal/calibration*.jpg')


from lane_detector import lane_detector

# Initialize gradient
grad = gradient(
    direction=(1, 15, 0.7, 1.3),  
    magnitude=(1, 15, 30, 150), 
    sobelx=(2, 5, 20, 100), 
    sobely=(2, 5, 20, 100))

# Calibrate the camera
cam.calibrate()


detector = lane_detector(camera = cam, gradient = grad, debug = True)

# import test image
# test1 = mpimg.imread(root_folder + 'test_images/test2.jpg')
test1 = mpimg.imread(root_folder + 'test_images/test2.jpg')

detector.reset()
# lanes = detector.find_lanes(test1)
lanes = detector.find_lanes(test1)
lanes = detector.find_lanes(test1)

# Show original and warped image
f, ((ax1, ax2), (ax3, ax4), (ax5, ax6)) = plt.subplots(3, 2, figsize=(16, 9))
f.tight_layout()
ax1.imshow(test1)
ax1.set_title('Original Image', fontsize=12)

ax2.imshow(detector.filtered_image, cmap="gray")
ax2.set_title('After pipeline Image', fontsize=12)

ax3.imshow(detector.birds_eyed_image, cmap="gray")
ax3.set_title('Birds Eye Image', fontsize=12)

ax4.imshow(detector.current_lanes)
ax4.set_title('Lines Image', fontsize=12)

ax5.imshow(lanes)
ax5.set_title('Result image', fontsize=12)

ax6.imshow(lanes)
ax6.set_title('Result image', fontsize=12)

cv2.imwrite(root_folder + 'examples/output.jpg', cv2.cvtColor(cv2.resize(lanes, (640,320)), cv2.COLOR_BGR2RGB))

plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)<jupyter_output>Sliding window
Left =>
Right =>
Around poly
Around poly
Left =>
Right =><jupyter_text>Find lanes on a video First import everything needed to edit/save/watch video clips<jupyter_code>from moviepy.editor import VideoFileClip
from IPython.display import HTML<jupyter_output><empty_output><jupyter_text>Project videoNow I'll apply the detector class to process an entire video<jupyter_code>detector = lane_detector(camera = cam, gradient = grad, debug = False)

detector.reset()

def process_image(image):

    result = detector.find_lanes(image)
    return result

output_video = root_folder + 'test_videos_output/project_video.mp4'

clip = VideoFileClip(root_folder + 'project_video.mp4')

output_clip = clip.fl_image(process_image)
%time output_clip.write_videofile(output_video, audio=False)

print(detector.left_line.all_losted_iterations)
print(detector.right_line.all_losted_iterations)

# plt.subplots_adjust(left=0., right=1, top=0.9, bottom=0.)

# frame = clip.get_frame(0)
# f = frame[:,:,:3]
# print(f.shape)
# plt.imshow(f)
# cv2.imwrite(root_folder + "test_images/project_test2.jpg", cv2.cvtColor(f, cv2.COLOR_RGB2BGR))<jupyter_output>[MoviePy] >>>> Building video ./test_videos_output/project_video.mp4
[MoviePy] Writing video ./test_videos_output/project_video.mp4<jupyter_text>Challenge video<jupyter_code>detector = lane_detector(camera = cam, gradient = grad, debug = False)

detector.reset()

output_video = root_folder + 'test_videos_output/challenge_video.mp4'

clip2 = VideoFileClip(root_folder + 'challenge_video.mp4').subclip(0,5)
output_clip = clip2.fl_image(process_image)
%time output_clip.write_videofile(output_video, audio=False)<jupyter_output>[autoreload of lane_detector failed: Traceback (most recent call last):
  File "/opt/conda/lib/python3.6/site-packages/IPython/extensions/autoreload.py", line 245, in check
    superreload(m, reload, self.old_objects)
  File "/opt/conda/lib/python3.6/site-packages/IPython/extensions/autoreload.py", line 368, in superreload
    module = reload(module)
  File "/opt/conda/lib/python3.6/imp.py", line 315, in reload
    return importlib.reload(module)
  File "/opt/conda/lib/python3.6/importlib/__init__.py", line 166, in reload
    _bootstrap._exec(spec, module)
  File "<frozen importlib._bootstrap>", line 618, in _exec
  File "<frozen importlib._bootstrap_external>", line 674, in exec_module
  File "<frozen importlib._bootstrap_external>", line 781, in get_code
  File "<frozen importlib._bootstrap_external>", line 741, in source_to_code
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "./src/lane_detector.py", line 128
    if self.debug == True
         [...]
{'fraction_non_alphanumeric': 0.12447210491220272, 'fraction_numerical': 0.033340742387197156, 'mean_word_length': 5.859756097560975, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '204713', 'license': 'MIT', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1618, 'n_words': 339, 'path': 'project.ipynb', 'repo_name': 'MatteoGranziera/CarND-Advanced-Lane-Lines', 'size': '4499'}