【发布时间】:2020-01-20 19:14:25
【问题描述】:
我在计算薄度比时遇到问题。它给了我 0.9 而不是 1 的值。
薄度以a给出
(4 * pi * area) / (perimeter * perimeter)
对于圆,上述等式的结果应该是 1.0。
import cv2
import math
image = cv2.imread("circle.png")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cnt = cv2.findContours(gray.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[1]
for c in cnt:
# compute the area of the contour along with the bounding box
# to compute the aspect ratio
area = cv2.contourArea(c)
perimeter = cv2.arcLength(c,True)
ti= (4*area*math.pi)/(perimeter**2)
print(ti)
【问题讨论】:
-
欢迎来到 StackOverflow。请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确说明问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您指定的问题。您发布的代码包括图形输入、两个函数调用和一个计算。差异发生在哪里?
-
你试过
cv2.CHAIN_APPROX_NONE吗? -
cv2.CHAIN_APPROX_NONE函数给了我同样的结果
标签: python algorithm opencv optimization geometry