计算轮廓周长(OpenCV,Python)

互联网 行业动态 更新时间:2024-06-13 00:19:06

Emi*_*tti 5

很好的案例,根据OpenCV 文档,一旦你有了轮廓,你应该能够使用方法计算你想要的东西cv.arcLength()

也称为弧长。可以使用 cv.arcLength() 函数找到它。第二个参数指定 shape 是闭合轮廓(如果传递 True),还是只是曲线。

来自官方文档的示例:

    import numpy as np
    import cv2 as cv
    img = cv.imread('star.jpg',0)
    ret, thresh = cv.threshold(img,127,255,0)
    contours, hierarchy = cv.findContours(thresh, 1, 2)
    
    t = contours[0]
    area = cv.contourArea()  # Area of first contour
    perimeter = cv.arcLength(t, True)  # Perimeter of first contour 

因此,在您的情况下,您应该按如下方式更新代码:

    def pute_mean_stddev(contours_of_images):
        for contours_of_image in contours_of_images:
            count = len(contours_of_image)

            sum_list = []
            for tr in contours_of_image:
                area = cv2.contourArea(tr)
                perimeter = cv.arcLength(tr, True)  
            
            average = np.mean(sum_list)
            standard_deviation = np.std(sum_list) 

我希望这行得通!

更多推荐

周长,轮廓,Python,OpenCV

本文发布于:2023-04-20 20:48:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/hyzx/7b4c9f90e38be867d8d90189f99c23be.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:周长   轮廓   Python   OpenCV

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!