【发布时间】:2021-07-27 03:44:50
【问题描述】:
我想在这个Image 中分割布料,我正在使用以下代码,但这只会分割表格而不是布料。
img = cv2.imread("/content/task5/20210514_153525.jpg",0)
imgplot = plt.imshow(img,cmap='gray')
plt.show()
blur = cv2.blur(img, (3, 3))
ret, thresh = cv2.threshold(blur, 150, 255, cv2.THRESH_BINARY)
ker2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE,(15,15))
mask = cv2.morphologyEx(np.float32(thresh), cv2.MORPH_CLOSE, ker2)
mask = mask.astype(np.uint8)
contours, hierarchy = cv2.findContours(image =mask , mode = cv2.RETR_TREE,method = cv2.CHAIN_APPROX_SIMPLE)
mask1=mask.copy()*0
for i,cnt in enumerate(contours):
if hierarchy[0][i][2] == -1 :
if cv2.contourArea(cnt) > 100000:
cv2.drawContours(mask1,[cnt], 0, (255), -1)
imgplot = plt.imshow(mask1,cmap='gray')
plt.show()
【问题讨论】:
-
尝试使用 cv2.inRange() 对布料的颜色进行阈值处理。
-
如何应用它可以分享任何python代码来分割它吗?
标签: python opencv image-processing artificial-intelligence cv2