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 インターフェイスは、すべての瞬間を直接返します。m00m01または などのインデックスを介して、必要な瞬間にアクセスできます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 に答える