我想从图像提取轮廓到本地文件夹(图像在托盘中包含圆形轮廓)
我已经完成轮廓的阈值绘制和绘制,但是由于尝试中的轮廓非常接近(例如带有多个球的篮子),因此无法将检测到的轮廓提取到文件夹中 示例图片:https://www.shutterstock.com/image-photo/donut-balls-on-metal-tray-white-1307503597?src=xfk0YUuijFGMUXsPIcYEPA-1-49
count = 0
for file in sorted(glob.glob(image_path)):
img = cv2.imread(file)
#img = imutils.resize(img, width=500)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray, 127, 255, 0)
cnts = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
cnts = imutils.grab_contours(cnts)
seg_c = 0
for c in cnts:
seg_c = seg_c + 1
x,y,w,h = cv2.boundingRect(c)
roi=img[y:y+h,x:x+w]
cv2.imwrite(cropped_path + '/frame%d_crop.jpg', roi)
# cv2.rectangle(img,(x,y),(x+w,y+h),(200,0,0),2)
count += 1
我希望将所有检测到的圆形轮廓提取到文件夹中