我正在使用一些关于对象跟踪的教程来创建一个简单的手势检测,但我在新的GetSpatialMoment
API中找不到函数GetCentralMoment
和cv2
或等效函数。< / 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
函数?
答案 0 :(得分: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