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

cv2.approxPolyDP() , cv2.arcLength() How these works(cv2.approxPolyDP() , cv2.arcLength() 这些是如何工作的)
本文介绍了cv2.approxPolyDP() , cv2.arcLength() 这些是如何工作的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

这些功能是如何工作的?我正在使用 Python3.7 和 OpenCv 4.2.0.提前致谢.

How do these function works? I am using Python3.7 and OpenCv 4.2.0. Thanks in Advance.

approx = cv2.approxPolyDP(cnt, 0.01*cv2.arcLength(cnt, True), True)

推荐答案

如果您正在寻找示例代码段,以下是一个:

If you are looking for a example snippet, below is one:

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 适用于文档边界等轮廓中有尖锐边缘的情况.

In the above snippet, first it finds the contours from a edge detected image, then it sorts the contours to find the five largest contours. Finally it loop over the contours and used cv2.approxPolyDP function to smooth and approximate the quadrilateral. cv2.approxPolyDP works for the cases where there are sharp edges in the contours like a document boundary.

这篇关于cv2.approxPolyDP() , cv2.arcLength() 这些是如何工作的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How To Detect Red Color In OpenCV Python?(如何在 OpenCV Python 中检测红色?)
Distance between 2 pixels(2个像素之间的距离)
How to get length of each side of a shape in an image?(如何获取图像中形状每一边的长度?)
How to upload dataset in google colaboratory?(如何在谷歌合作实验室上传数据集?)
Fast and Robust Image Stitching Algorithm for many images in Python?(Python中许多图像的快速而强大的图像拼接算法?)
Problems during Skeletonization image for extracting contours(用于提取轮廓的骨架化图像过程中的问题)