Das ganze Programm ist, die extrahierten optischen Flüsse von jedem Bild von einem Ordner zu visualisieren. Das Problem tritt auf, wenn ich die Funktion draw_flow anwendete. Ich habe das Bild-Array in ein Tupel umgewandelt, aber es ist kein numerisches Tupel, wie der Fehler erwähnt. Ich weiß nicht, wie ich das beheben soll. Als ich versuchte, den Code auszuführen, wie die folgenden:img ist kein numerisches Tupel
def draw_flow(im, greyim, flow, step = 16):
h, w = im.shape[:2]
y, x = np.mgrid[step/2:h:step,step/2:w:step].reshape(2, -1)
fx, fy = flow[y,x].T
lines = np.vstack([x, y, x+fx, y+fy]).T.reshape(-1,2,2)
lines = np.int32(lines)
for(x1,y1),(x2,y2) in lines:
cv2.line(greyim, (x1,y1), 1, (0,255,0), -1)
return greyim
def main():
mypath = 'jpl_thomas'
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath,f)) ]
color_images = np.empty(len(onlyfiles), dtype=object)
gray_images = np.empty(len(onlyfiles), dtype=object)
for n in range(1, len(onlyfiles)):
color_images[n] = cv2.imread(join(mypath,onlyfiles[n]))
gray_images[n] = cv2.imread(join(mypath,onlyfiles[n]),0)
for i in range(2, len(gray_images)):
flow =cv2.calcOpticalFlowFarneback(gray_images[i],gray_images[i-1], None, 0.5, 3, 15, 3, 5, 1.2, 0)
draw_flow(color_images[i],tuple(gray_images[i]),flow, step = 16)
Ich habe die Fehlermeldung wie folgt aus:
Traceback (most recent call last):
File "main.python", line 51, in <module>
main()
File "main.python", line 45, in main
draw_flow(color_images[i],tuple(gray_images[i]),flow, step = 16)
File "main.python", line 19, in draw_flow
cv2.line(greyim, (x1,y1), 1, (0,255,0), -1)
TypeError: img is not a numerical tuple