问题描述
我有一张拼图成品的照片,我想获得“干净”的轮廓以匹配单个拼图。 Source Image
对于当前结果,我使用以下步骤: current result
img = cv2.imread("img.jpg",cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
blur = cv2.medianBlur(gray,5)
threshold = cv2.adaptiveThreshold(blur,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,7,2)
contours,hierarchy = cv2.findContours(threshold,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
blank = np.zeros((img.shape[0],img.shape[1],4),dtype=np.uint8)
for i in range(len(contours)):
if cv2.contourArea(contours[i]) > 600:
cv2.drawContours(blank,contours,i,(255,255),2)
cv2.imshow("gray",gray)
cv2.imshow("blur",blur)
cv2.imshow("threshold",threshold)
cv2.imshow("contours",blank)
cv2.waitKey(0)
我需要使用自适应阈值,因为完整的源图像的光照条件很差: Full source image 为了清除大部分噪音,我过滤了小区域的轮廓。
为了获得没有噪音的干净轮廓,我错过了什么步骤?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)