getCentralMoment在Pythons新的openCV API中去了哪里?

时间:2013-06-04 17:30:12

标签: python opencv

我正在使用一些关于对象跟踪的教程来创建一个简单的手势检测,但我在新的GetSpatialMoment API中找不到函数GetCentralMomentcv2或等效函数。< / p>

教程代码总是显示为like this,但它们始终位于旧的cv1:

moments = cv.Moments(thresholded_img, 0) 
area = cv.GetCentralMoment(moments, 0, 0) 

#there can be noise in the video so ignore objects with small areas 
if(area > 100000): 
    #determine the x and y coordinates of the center of the object 
    #we are tracking by dividing the 1, 0 and 0, 1 moments by the area 
    x = cv.GetSpatialMoment(moments, 1, 0)/area 
    y = cv.GetSpatialMoment(moments, 0, 1)/area 

我必须使用哪些新的cv2函数?

1 个答案:

答案 0 :(得分:4)

新的Python界面直接返回所有时刻。您可以通过m00m01m10等索引访问所需的时刻。因此cv2中的上述代码为:

moments = cv2.moments(thresholded_img) 
area = moments['m00'] 

#there can be noise in the video so ignore objects with small areas 
if(area > 100000): 
    #determine the x and y coordinates of the center of the object 
    #we are tracking by dividing the 1, 0 and 0, 1 moments by the area 
    x = moments['m10'] / area
    y = moments['m01'] / area