python - 查找 Contour opencv 时缺少部分轮廓(受白色背景、文档扫描仪影响)
问题描述
我正在尝试对各种背景和光照条件下的文档进行透视变换。目前,我无法在此图像上执行此操作,因为轮廓不接近。
到目前为止,我已经尝试过自适应阈值、高斯模糊、中值模糊、各种形态学操作、霍夫变换和直方图均衡,并使用其中的所有参数,但没有任何效果。
谁能帮我解决这个问题?
解决方案
使用 Canny Edges、Dilation 和 Erosion 获得此输出
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(img,20,40)
kernel = np.ones((5,5),np.uint8)
dilation = cv2.dilate(edges,kernel,iterations = 1)
erosion = cv2.erode(dilation,kernel,iterations = 1)
ret,thresh = cv2.threshold(erosion, 200, 255, 0)
contours, hierarchy = cv2.findContours(thresh,
cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
largest_areas = sorted(contours, key=cv2.contourArea)
cv2.drawContours(img, [largest_areas[-2]], -1, 255, 2)
cv2.imshow("image", img)
cv2.waitKey(0)
推荐阅读
- python - Python PyQt5 webview无法打开没有url创建的标签
- java - 在 JUnit4 中断言两个列表相等
- python - 改变蟒蛇的大小
- php - PHP - 如何将字符串变量的内容用作空()中的变量?
- python - 当键乱序时比较字典列表
- r - 有效地将增长率应用于多年来不同增长率的初始值
- java - 这个 Java 字符串数组声明有什么问题 - 非常奇怪
- html - 使用 exec master..xp_cmdshell 写入 .html 文件
- python - Facebook刮板'NoneType'对象在get_post时没有属性'find'
- c++ - 系统调用是线程安全的吗?