findredlinedpolygonfromgooglemaps.py 828 B

1234567891011121314151617181920212223242526272829
  1. # USAGE - How to run this code ?
  2. # python find_shapes.py --image shapes.png
  3. #python findredlinedpolygonfromgooglemaps.py --image stanford.png
  4. import numpy as np
  5. import argparse
  6. import cv2 as cv
  7. # construct the argument parse and parse the arguments
  8. ap = argparse.ArgumentParser()
  9. ap.add_argument("-i", "--image", help = "path to the image file")
  10. args = vars(ap.parse_args())
  11. # load the image
  12. image = cv.imread(args["image"])
  13. lower = np.array([20,0,155])
  14. upper = np.array([255,120,250])
  15. shapeMask = cv.inRange(image, lower, upper)
  16. # find the contours in the mask
  17. (cnts, _) = cv.findContours(shapeMask.copy(), cv.RETR_EXTERNAL,
  18. cv.CHAIN_APPROX_SIMPLE)
  19. cv.imshow("Mask", shapeMask)
  20. # loop over the contours
  21. for c in cnts:
  22. cv.drawContours(image, [c], -1, (0, 255, 0), 2)
  23. cv.imshow("Image", image)
  24. cv.waitKey(0)