【问题标题】:finding the value of x,y in contour在轮廓中找到 x,y 的值
【发布时间】:2020-10-17 03:45:06
【问题描述】:

我试图理解这段代码,但我就是无法理解。如果有人能解释这段代码中的 x,y int 到底是什么,将会有所帮助。我想修改 x,y 值,但我不知道编码器是如何得到它的值的。我的理解是,要找到一个水平轮廓,Y 需要在 180-300 之间的范围内,如果它在该范围内,那么 x 必须是 x>300 或 x

if len(cnts) > 0:
        for c in cnts:
            (x,y),radius = cv2.minEnclosingCircle(c)
            center = (int(x),int(y))
            radius = int(radius)
            cv2.circle(frame,center,radius,(0,255,0),2)

            x = int(x)
            y = int(y)
            
            if 180 < x < 300:
                if y > 300:
                    vert = vert +1
                elif y < 180:
                    vert = vert +1
                else:
                    vert = vert
            if 180 < y < 300:
                if x > 300:
                    horiz = horiz +1
                elif x < 180:
                    horiz = horiz +1
                else:
                    horiz = horiz

【问题讨论】:

    标签: python opencv raspberry-pi


    【解决方案1】:

    这是某种元组赋值。猜猜下面赋值后的 a、b 和 c 是什么。

    lol = [[1, 2], ['a']]
    (a, b), c = lol
    

    将其与您的代码进行比较

    (x,y),radius = cv2.minEnclosingCircle(c)
    

    还可以看看这个article关于python中的元组赋值

    【讨论】:

      【解决方案2】:

      我知道了,所以 x 和 y 是轮廓的中心,if elif else 循环是要知道轮廓在 480x480 上的位置,谢谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多