python - Lane Detection tuple error hough_lines OpenCv -


i have been working on lanedetection learning sentdex youtube channel stating python plays gta v series.

ahead want apply own lane detection code encounter tuple error new opencv , failing grasp concepts now

below hough_line function error being generated being called process function.

def hough_lines(img, rho, theta, threshold, min_line_len, max_line_gap):      """      `img` should output of canny transform.        returns image hough lines drawn.      """      lines = cv2.houghlinesp(img, rho, theta, threshold, np.array([]), minlinelength=min_line_len,                              maxlinegap=max_line_gap)      line_img = np.zeros((img.shape, 3), dtype=np.uint8)      draw_lines(line_img, lines)      return line_img      def process_image(img):      img_test = grayscale(img)      img_test = gaussian_blur(img_test, 7)      img_test = canny(img_test, 50, 150)      imshape = img.shape      vertices = np.array([[(100,imshape[0]),(400, 330), (600, 330), (imshape[1],imshape[0])]], dtype=np.int32)      img_test = region_of_interest(img_test, vertices)      rho = 2 # distance resolution in pixels of hough grid      theta = np.pi/180 # angular resolution in radians of hough grid      threshold = 55     # minimum number of votes (intersections in hough grid cell)      min_line_length = 40 #minimum number of pixels making line      max_line_gap = 100    # maximum gap in pixels between connectable line segments      line_image = np.copy(img)*0 # creating blank draw lines on      img_test = hough_lines(img_test, rho, theta, threshold, min_line_length, max_line_gap)      return img_test    img = cv2.imread("img.jpeg")  res=process_image(img)  cv2.imshow("image",res)  cv2.waitkey(0)

error generated:

/users/viditshah/anaconda/envs/py27/bin/python /users/viditshah/downloads/untitled1/detection2.py  traceback (most recent call last):    file "/users/viditshah/downloads/untitled1/detection2.py", line 124, in <module>      res=process_image(img)    file "/users/viditshah/downloads/untitled1/detection2.py", line 120, in process_image      img_test = hough_lines(img_test, rho, theta, threshold, min_line_length, max_line_gap)    file "/users/viditshah/downloads/untitled1/detection2.py", line 102, in hough_lines      line_img = np.zeros((img.shape, 3), dtype=np.uint8)  typeerror: 'tuple' object cannot interpreted index    process finished exit code 1

kindly me. yours sincerely, vidit shah

img.shape returns , height image in tupel. code this:

line_img = np.zeros(( (width,height), 3), dtype=np.uint8) 

lets have @ numpy documentation: https://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.shape.html

now lets make ur bad tupel tripel. how create image 3 8bit channels:

(w,h) = img.shape np.zeros((w,h,3), dtype=np.uint8)  

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -