【发布时间】:2019-11-04 18:58:04
【问题描述】:
我正在尝试在两个重叠的对象上绘制轮廓。在这里,我拍了两支笔的照片。 但它不能完美地绘制轮廓。里面有一些小轮廓。如何删除它?
这是我的原图
结果
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('img/pen001.jpg',1)
img = cv2.cvtColor(img , cv2.COLOR_BGR2RGB)
imgray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
ret, thresh = cv2.threshold(imgray, 102 , 160, 0)
kernel = np.ones((5,5), np.float32)/10
dst = cv2.filter2D(thresh, -1, kernel)
contour1, hierarchy = cv2.findContours(dst, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img , contour1, -1, (0, 255, 0), 3 )
plt.imshow(dst)
plt.show()
plt.imshow(img)
plt.show()
【问题讨论】:
标签: python image opencv image-processing contour