如何解决根据形状条件涂黑轮廓及其面积
我有一个黑白图像,其中自然会检测到白色像素。现在,所有对象都不感兴趣。我查看每个轮廓,并计算它们的面积和周长,如果它们不满足特定条件,则轮廓及其面积(对象)应变为黑色。例如,我们检测到明显是正方形(或矩形)的周长,但我们想要五边形,因此应在表示图像的原始NumPy数组上将其涂黑。我已经尝试过回答类似的问题,但似乎并不能解决问题
这是代码的一部分:
fig,ax = plt.subplots()
ax.imshow(e_im,cmap=plt.cm.gray) #e_im is the original image holding the eroded image from previous computations
list_int = []
for i in range(len(contours)):
contour = contours[i]
cimg = np.zeros_like(e_im)
cv2.drawContours(cimg,contours,i,color=255,thickness=-1)
pts = np.where(cimg == 255)
list_int.append(e_im[pts[0],pts[1]])
perimeter = cv2.arcLength(contour,True)
area = cv2.contourArea(contour)
approxShape = cv2.approxPolyDP(contour,0.06 * perimeter,True)
approxShape = approxShape.reshape(-1,2)
#if the contour matches the criteria draw it on the main image else make that part of the image black
# ax.plot(approxShape[:,0],approxShape[:,1],linewidth=1)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。