如何计算Python中2个轮廓之间的区域?

时间:2013-07-02 08:46:08

标签: python opencv scipy contour

我有轮廓列表(已到达),轮廓已关闭,我必须计算它们之间的区域。我试过scipy.integrate,但它给了我错误。我有大约200个轮廓,并且必须计算所有这些的面积,这很容易吗?任何的想法?谢谢!

reached = [ contour for contour in prodcontours[prodwell.name] if contour.latest_time_on_contour()<tau ]
area = trapz(reached, dx=well.radius)

更新

for tau in years :
for contour in reached:
    ctr = np.array(contour)
    area =cv2.contourArea(ctr)

   TypeError: <unknown> data type = 15 is not supported

这是什么意思? 要么 如何为200个轮廓重写这个,而不输入每个

的坐标
 contour = numpy.array([[[0,0]], [[10,0]], [[10,10]], [[5,4]]])
 area = cv2.contourArea(contour)

编辑1:顺便说一下,我的轮廓是复数,可能是问题吗?

编辑2:这是因为我的轮廓是复数

1 个答案:

答案 0 :(得分:1)

您可以使用OpenCV库。

area = cv2.contourArea(contour)

其中,轮廓可以是包含轮廓点的2D numpy数组。

您可以在http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html阅读OpenCV文档 了解更多详情。