如何解决在 openCV findcontours()
我正在从这个二值图像中提取轮廓:
我使用 OpenCV
并且我可以正确地找到和绘制轮廓
import cv2 as cv
import matplotlib.pyplot as plt
sample_img = cv.imread('img_test.png',cv.IMREAD_GRAYSCALE)
contours,hierarchy = cv.findContours(sample_img,cv.RETR_TREE,cv.CHAIN_APPROX_SIMPLE)
plt.imshow(cv.drawContours(cv.cvtColor(sample_img,cv.COLOR_GRAY2BGR),contours,-1,(0,255,0),3))
但是,如果我提取从 OpenCV
找到的列表轮廓并用 matplotlib
绘制它,我会得到:
x,y = contours[0][...,0].flatten(),contours[0][...,1].flatten()
plt.plot(x,y)
plt.xlim(0,512)
plt.ylim(0,512)
plt.gca().invert_yaxis()
plt.show()
从中轮廓似乎没有闭合和拉伸,即使两个轴上的比例相同。但是,如果我在起始图像上绘制此轮廓,则会获得未拉伸的轮廓但仍处于打开状态:
plt.imshow(sample_img)
plt.plot(x,y,linewidth = 4)
plt.xlim(0,512)
plt.gca().invert_yaxis()
plt.show()
那么这里发生了什么?为什么轮廓在用 {{1}} 绘制时没有闭合,而在未绘制在图像上时似乎被拉伸了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。