'TypeError: 'NoneType' object is not subscriptable while I'm running lane detection code
I'm very new to python. I'm using google colab because I'm using laptop. I imported https://github.com/Dt-Pham/Advanced-Lane-Lines.git and followed instructions the youtube. Here's the site, https://www.youtube.com/watch?v=iRTuCYx6quQ&ab_channel=MisbahMohammed. The code worked fine for existing video clip. But when I used my own video clip to check the lane detection, it showed this error
<decorator-gen-171> in set_make_frame(self, mf)
<decorator-gen-124> in get_frame(self, t)
/content/Advanced-Lane-Lines/LaneLines.py in fit_poly(self, img)
176 ploty = np.linspace(miny, maxy, img.shape[0])
177
--> 178 left_fitx = self.left_fit[0]*ploty**2 + self.left_fit[1]*ploty + self.left_fit[2]
179 right_fitx = self.right_fit[0]*ploty**2 + self.right_fit[1]*ploty + self.right_fit[2]
180
TypeError: 'NoneType' object is not subscriptable
I'm not sure why this happened... the video width and height are both same(1280*720). For more detatils, here's my code
import numpy as np
import matplotlib.image as mpimg
import cv2
from docopt import docopt
from IPython.display import HTML
from IPython.core.display import Video
from moviepy.editor import VideoFileClip
from CameraCalibration import CameraCalibration
from Thresholding import *
from PerspectiveTransformation import *
from LaneLines import *
class FindLaneLines:
def __init__(self):
""" Init Application"""
self.calibration = CameraCalibration('camera_cal', 9, 6)
self.thresholding = Thresholding()
self.transform = PerspectiveTransformation()
self.lanelines = LaneLines()
def forward(self, img):
out_img = np.copy(img)
img = self.calibration.undistort(img)
img = self.transform.forward(img)
img = self.thresholding.forward(img)
img = self.lanelines.forward(img)
img = self.transform.backward(img)
out_img = cv2.addWeighted(out_img, 1, img, 0.6, 0)
out_img = self.lanelines.plot(out_img)
return out_img
def process_image(self, input_path, output_path):
img = mpimg.imread(input_path)
out_img = self.forward(img)
mpimg.imsave(output_path, out_img)
def process_video(self, input_path, output_path):
clip = VideoFileClip(input_path)
out_clip = clip.fl_image(self.forward)
out_clip.write_videofile(output_path, audio=False)
def main():
findLaneLines = FindLaneLines()
findLaneLines.process_video("test_sample.mp4","output.mp4")
if __name__ == "__main__":
main()
google colab said
img = self.lanelines.forward(img)
there's the problem(red line).
Very thank you!!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
