Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. import numpy as np
  2. import argparse
  3. import cv2
  4.  
  5. # construct the argument parser and parse the arguments
  6. ap = argparse.ArgumentParser()
  7. ap.add_argument("-i", "--image", required = True, help = "Path to the image")
  8. args = vars(ap.parse_args())
  9.  
  10. image = cv2.imread(args["image"])
  11. output = image.copy()
  12. image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  13.  
  14. clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
  15. cl1 = clahe.apply(image)
  16.  
  17. cl1 = cv2.medianBlur(cl1,5)
  18. # detect circles in the image
  19. circles = cv2.HoughCircles(cl1, cv2.cv.CV_HOUGH_GRADIENT, 1.8, 75)
  20.  
  21. # ensure at least some circles were found
  22. if circles is not None:
  23.     # convert the (x, y) coordinates and radius of the circles to integers
  24.     circles = np.round(circles[0, :]).astype("int")
  25.  
  26.     # loop over the (x, y) coordinates and radius of the circles
  27.     for (x, y, r) in circles:
  28.         # draw the circle in the output image, then draw a rectangle
  29.         # corresponding to the center of the circle
  30.         cv2.circle(output, (x, y), r, (0, 255, 0), 4)
  31.         cv2.rectangle(output, (x - 5, y - 5), (x + 5, y + 5), (0, 128, 255), -1)
  32.  
  33.     # show the output image
  34.     cv2.imshow("output", output)
  35.  
  36. cv2.imshow("cl1",cl1)
  37. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement