Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. # Define a function to pass stored images to
  2. # reading rover position and yaw angle from csv file
  3. # This function will be used by moviepy to create an output video
  4. def process_image(img):
  5. # Example of how to use the Databucket() object defined above
  6. # to print the current x, y and yaw values
  7. # print(data.xpos[data.count], data.ypos[data.count], data.yaw[data.count])
  8.  
  9. # TODO:
  10. # 1) Define source and destination points for perspective transform
  11. source = np.float32([[14, 140], [301 ,140],[200, 96], [118, 96]])
  12. destination = np.float32([[image.shape[1]/2 - dst_size, image.shape[0] - bottom_offset],
  13. [image.shape[1]/2 + dst_size, image.shape[0] - bottom_offset],
  14. [image.shape[1]/2 + dst_size, image.shape[0] - 2*dst_size - bottom_offset],
  15. [image.shape[1]/2 - dst_size, image.shape[0] - 2*dst_size - bottom_offset],
  16. ])
  17. # 2) Apply perspective transform
  18. perspect_transform(img, src, dst)
  19. # 3) Apply color threshold to identify navigable terrain/obstacles/rock samples
  20. color_thresh(img, rgb_thresh=(160, 160, 160))
  21. obstacle_thresh(img, rgb_thresh=(160, 160, 160))
  22. # 4) Convert thresholded image pixel values to rover-centric coords
  23. rover_coords(binary_img)
  24. to_polar_coords(x_pixel, y_pixel)
  25. rotate_pix(xpix, ypix, yaw)
  26. # 5) Convert rover-centric pixel values to world coords
  27. rotate_pix(xpix, ypix, yaw)
  28. translate_pix(xpix_rot, ypix_rot, xpos, ypos, scale)
  29. # 6) Update worldmap (to be displayed on right side of screen)
  30. # Example: data.worldmap[obstacle_y_world, obstacle_x_world, 0] += 1
  31. # data.worldmap[rock_y_world, rock_x_world, 1] += 1
  32. # data.worldmap[navigable_y_world, navigable_x_world, 2] += 1
  33.  
  34. # 7) Make a mosaic image, below is some example code
  35. # First create a blank image (can be whatever shape you like)
  36. output_image = np.zeros((img.shape[0] + data.worldmap.shape[0], img.shape[1]*2, 3))
  37. # Next you can populate regions of the image with various output
  38. # Here I'm putting the original image in the upper left hand corner
  39. output_image[0:img.shape[0], 0:img.shape[1]] = img
  40.  
  41. # Let's create more images to add to the mosaic, first a warped image
  42. warped = perspect_transform(img, source, destination)
  43. # Add the warped image in the upper right hand corner
  44. output_image[0:img.shape[0], img.shape[1]:] = warped
  45.  
  46. # Overlay worldmap with ground truth map
  47. map_add = cv2.addWeighted(data.worldmap, 1, data.ground_truth, 0.5, 0)
  48. # Flip map overlay so y-axis points upward and add to output_image
  49. output_image[img.shape[0]:, 0:data.worldmap.shape[1]] = np.flipud(map_add)
  50.  
  51.  
  52. # Then putting some text over the image
  53. cv2.putText(output_image,"Populate this image with your analyses to make a video!", (20, 20),
  54. cv2.FONT_HERSHEY_COMPLEX, 0.4, (255, 255, 255), 1)
  55. data.count += 1 # Keep track of the index in the Databucket()
  56.  
  57. return output_image
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement