2

私はウェブカメラを使用し、openCV を使用して各フレームを取得し、オブジェクトの位置を追跡します。

つまり、基本的に、各フレームで 1 つのポイントを取得しています。しかし、リアルタイムで動きのある絵を描くにはどうすればよいでしょうか?

特定の時間内に複数のポイントを記録して線を引くにはタイマーが必要ですか?

while ループの場合と同様に、フレームを 1 つ取得するだけです。この現在のフレームに線を描画しても、次のフレームで線を保持することはできないと思います。では、どのように動きを表示すればよいでしょうか。

while( true )
    {
        //Read the video stream
        capture = cvCaptureFromCAM(1);
        frame = cvQueryFrame( capture );

        //Apply the classifier to the frame
        detectAndDisplay(frame); // I got a point from this function

        // waitkey enter
        int c = waitKey(10);
        if( (char)c == 27 ) { exit(0); } 

    }
4

1 に答える 1

1

ベクトルを使用して位置を保持し、すべてのフレームに描画します。関数は検出されたポイントを返す必要があることに注意してください。その時点で描画されないため、名前を変更しました。後で修正できます。

vector<CvPoint> trajectory;
Vec3b mycolor(100,0,0);

while( true )
{
    //Read the video stream
    capture = cvCaptureFromCAM(1);
    frame = cvQueryFrame( capture );

    //Apply the classifier to the frame
    CvPoint cur_pnt=detect(frame); // I got a point from this function
    trajectory.push_back(cur_point);

    //Draw points.
    for (int i=0;i<trajectory.size();i++)
        frame.at<Vec3b>(trajectory[i].x,trajectory[i].y)=mycolor;

    // waitkey enter
    int c = waitKey(10);
    if( (char)c == 27 ) { exit(0); } 

}
于 2013-04-17T09:53:37.610 に答える