You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
689 B
23 lines
689 B
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() |