Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. def draw_flow(img, flow, step=16):
  2. # shape returns tuple (rows, columns, channels (if colour image)). This just takes number of
  3. # rows and stores in h and number of columns and stores it in w
  4. h, w = img.shape[:2]
  5. # Create an array with two nested array. The first going from 8 to the height of the image
  6. # and going up by 16 each time. The second going from 2 to the width of image in steps of 16
  7. #
  8. # reshape the array to be a nested array with 2 arrays and the same length as before (guess it
  9. # just makes sure both the arrays are the same length. Set one to y and x
  10. y, x = np.mgrid[step / 2:h:step, step / 2:w:step].reshape(2, -1)
  11.  
  12. fx, fy = flow[y, x].T
  13. lines = np.vstack([x, y, x + fx, y + fy]).T.reshape(-1, 2, 2)
  14. lines = np.int32(lines + 0.5)
  15. vis = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
  16.  
  17. cv2.polylines(vis, lines, 0, (0, 255, 0))
  18. for (x1, y1), (x2, y2) in lines:
  19. cv2.circle(vis, (x1, y1), 1, (0, 255, 0), -1)
  20.  
  21.  
  22. return vis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement