From 82f8edc964bf535936dc01662aad2e8580b14439 Mon Sep 17 00:00:00 2001 From: pyhqos7bg Date: Thu, 30 May 2024 15:03:33 +0800 Subject: [PATCH] ADD file via upload --- Canny边缘检测.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Canny边缘检测.py 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