Ich habe an LaneDetection gearbeitet, als ich von sentdex von seinem YouTube-Kanal mit der PYTHON PLAYS GTA V-Serie lernte.Lane Detection Tupelfehler hough_lines OpenCv
Ahead will ich meinen eigenen Lane Erkennungscode anwenden, aber ich begegne Tupel Fehler Ich bin neu in OpenCV und damit nun die Konzepte erfassen Versäumnis
Im Folgenden wird die hough_line Funktionsfehler erzeugt werden, die sein wird, von Prozessfunktion aufgerufen.
def hough_lines(img, rho, theta, threshold, min_line_len, max_line_gap):
"""
`img` should be the output of a Canny transform.
Returns an image with 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 the Hough grid
theta = np.pi/180 # angular resolution in radians of the Hough grid
threshold = 55 # minimum number of votes (intersections in Hough grid cell)
min_line_length = 40 #minimum number of pixels making up a line
max_line_gap = 100 # maximum gap in pixels between connectable line segments
line_image = np.copy(img)*0 # creating a blank to 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)
Fehler generiert:
/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 be interpreted as an index
Process finished with exit code 1
bitte mir helfen. Mit freundlichen Grüßen, Vidit Shah
ich denke 'img.shape' ein Tupels ist, versuchen np.zeros (img.shape, dtype = np.uint8) –
@ al-EAX [ Korrekte Schätzung] (https://docs.scipy.org/doc/numpy/reference/generated/numpy.darray.shape.html). Da 'img' aussieht, als wäre es 3-Kanal, ist Ihr Vorschlag ebenfalls korrekt. Mach es eine richtige Antwort;) –