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

标签 opencv

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/

相关文章:

opencv - 使用 opencv 校准相机,它是如何工作的以及我如何移动我的棋盘

python - OpenCV无法从视频读取图像帧

python - opencv/ python : mask in module cv2 while streaming webcam video

c++ - 无法在 Linux 中使用 OpenCV 打开相机

opencv - mat.at <short>(x,y)的访问冲突

c++ - 错误的 cv::putText 结果

ios - 使用 OpenCV iOS Objective C 将图像转换为黑白(非灰度)

c++ - Visual Studio 2015 错误 C4996 'std::_Copy_impl' : Function call with parameters that may be unsafe

Python OpenCV PCA计算特征值

python - 获取显示屏4个角在图像上的坐标