diff --git a/Canny边缘检测.py b/Canny边缘检测.py new file mode 100644 index 0000000..d07915f --- /dev/null +++ b/Canny边缘检测.py @@ -0,0 +1,23 @@ +import cv2 +import matplotlib.pyplot as plt + +img = cv2.imread('./images/pill_002.png') +gray_image = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) +img_result = cv2.cvtColor(img,cv2.COLOR_BGR2RGB) +plt.subplot(221),plt.imshow(img_result),plt.title('original') + +contours, hierarchy = cv2.findContours(gray_image, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) + +Circles = [] + +for c in range(len(contours)): + (x,y),radius = cv2.minEnclosingCircle(contours[c]) + x,y,radius = int(x), int(y), int(radius) + if radius < 25 and radius >= 1: + Circles.append([x, y, radius]) + print(x,y,radius) + cv2.circle(img,(x,y),radius,(0,0,255),2) +print(len(Circles)) + + +plt.show() \ No newline at end of file