parent
8c9a89c909
commit
82f8edc964
@ -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()
|
Loading…
Reference in new issue