gpt4 book ai didi

opencv - cv.contourArea(contour,True)何时返回负值?

转载 作者:行者123 更新时间:2023-12-02 17:03:46 24 4
gpt4 key购买 nike

documentation for cv.contourArea 表示,如果orientedtrue,则返回值将为正值或负值,具体取决于轮廓的方向:

oriented: Oriented area flag. If it is true, the function returns a signed area value, depending on the contour orientation (clockwise or counter-clockwise). Using this feature you can determine orientation of a contour by taking the sign of an area. By default, the parameter is false, which means that the absolute value is returned.



但是,它没有说负值是什么意思-顺时针还是逆时针为负值?

最佳答案

回答问题的最简单方法是用两个简单的三角形轮廓(一个顺时针,一个逆时针)进行测试。

import numpy as np
import cv2

cw = np.array([[0,0],[4,0],[0,4]])
ccw = np.array([[0,0],[0,4],[4,0]])

print cv2.contourArea(cw, True)
print cv2.contourArea(ccw, True)

打印出来
8.0
-8.0

因此,正数表示顺时针,负数表示逆时针。

关于opencv - cv.contourArea(contour,True)何时返回负值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58157158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com