1

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

教程代码总是这样,但它们总是在旧的 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我必须为此使用哪些新功能?

4

1 回答 1

4

新的 Python 接口直接返回所有时刻。m00您可以通过,m01或等索引访问所需的时刻m10。所以上面的代码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
于 2013-06-04T17:44:00.060 回答