为了账号安全,请及时绑定邮箱和手机立即绑定

cv2.approxPolyDP() , cv2.arcLength() 这些是如何工作的

cv2.approxPolyDP() , cv2.arcLength() 这些是如何工作的

qq_笑_17 2023-01-04 11:08:02
这些功能如何工作?我正在使用 Python3.7 和 OpenCv 4.2.0。提前致谢。approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True)
查看完整描述

1 回答

?
慕田峪7331174

TA贡献1828条经验 获得超13个赞

如果您正在寻找一个示例片段,下面是一个:


import cv2

import imutils


# edged is the edge detected image

cnts = cv2.findContours(edged, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

cnts = imutils.grab_contours(cnts)

cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5]

# loop over the contours

for c in cnts:

    # approximate the contour

    peri = cv2.arcLength(c, True)

    approx = cv2.approxPolyDP(c, 0.02 * peri, True)

    # if our approximated contour has four points, then we

    # can assume that we have found our screen

    if len(approx) == 4:

        screenCnt = approx

        break

在上面的代码片段中,首先它从检测到边缘的图像中找到轮廓,然后对轮廓进行排序以找到五个最大的轮廓。最后它遍历轮廓并使用cv2.approxPolyDP函数来平滑和近似四边形。cv2.approxPolyDP适用于文档边界等轮廓中有锐边的情况。


查看完整回答
反对 回复 2023-01-04
  • 1 回答
  • 0 关注
  • 266 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号