clahe = cv2.createCLAHE(clipLimit=3., tileGridSize=(8,8))
lab = cv2.cvtColor(image, cv2.COLOR_BGR2LAB) #convert from BGR to LAB color space
l, a, b = cv2.split(lab) # split on 3 different channels
l2 = clahe.apply(l) #apply CLAHE to the L-channel
lab = cv2.merge((l2,a,b)) #merge channels
img2 = cv2.cvtColor(lab, cv2.COLOR_LAB2BGR) #convert from LAB to BGR
blur = cv2.GaussianBlur(img2, (7,7), 0)
hsv = cv2.cvtColor(blur, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, (0,0,0), (179,255,70))
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (7,7))
opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel, iterations=1)
close = cv2.morphologyEx(opening, cv2.MORPH_CLOSE, kernel, iterations=2)
cnts,_ = cv2.findContours(close, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
circles = cv2.HoughtCircles = (image, cv2.HOUGH_GRADIENT, 1, 300, np.array([]), 10, 30, 60, 300)
if circles is not None:
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
cv2.circle(image, (i[0], i[1]), i[2], (0, 255, 0), 1)
cv2.circle(image, (i[0], i[1]), 2, (0, 0, 255), 3)
cv2.imshow("thing", image)
for c in cnts:
approx = cv2.approxPolyDP(c, 0.04 * cv2.arcLength(c, True), True)
area = cv2.contourArea(c)
if len(approx) > 3 and area > 50:
cv2.drawContours(image, [c], -1, (0, 255, 0), -1)
Заранее спасибо!