5

v4l2_bufferのタイムスタンプ値(タイプtimeval)を使用して、UVCWebカメラからキャプチャされた画像を外部イベントに同期しようとしています

ただし、タイムスタンプはシステム時刻や稼働時間などと同じではありません。

printf("image captured at %ld, %ld\n",
   buffer->timestamp.tv_sec, 
   buffer->timestamp.tv_usec);

struct timeval tv;
gettimeofday(&tv, 0);
printf("current time %ld, %ld\n", tv.tv_sec, tv.tv_usec);

結果は

image captured at 367746, 476270
current time 1335083395, 11225

私の稼働時間は10日です。

4

2 に答える 2

6

http://comments.gmane.org/gmane.linux.drivers.video-input-infrastructure/39892によると、一部のv4l2ドライバー(UVCドライバーを含む)はリアルタイムクロック(実時間)を使用せず、単調なクロックを使用します。指定されていない時点からカウントします。Linuxでは、これは起動時間(つまり、稼働時間)ですが、(これが不一致の原因であると思われます)コンピューターが実際に実行されていた時間のみです(つまり、コンピューターが一時停止されている場合、このクロックは実行されません)。

于 2012-04-22T17:03:47.013 に答える
3

OPに問題があり、各フレームのエポックタイムスタンプを取得しようとしている場合は、以下のコードスニペットを使用してこれを行うことができます。

#include <time.h>
#include <math.h>

//////////////////////
//setup: 

    long getEpochTimeShift(){
        struct timeval epochtime;
        struct timespec  vsTime;

        gettimeofday(&epochtime, NULL);
        clock_gettime(CLOCK_MONOTONIC, &vsTime);

        long uptime_ms = vsTime.tv_sec* 1000 + (long)  round( vsTime.tv_nsec/ 1000000.0);
        long epoch_ms =  epochtime.tv_sec * 1000  + (long) round( epochtime.tv_usec/1000.0);
        return epoch_ms - uptime_ms;
    }

    //stick this somewhere so that it runs once, on the startup of your capture process
    //  noting, if you hibernate a laptop, you might need to recalc this if you don't restart 
    //  the process after dehibernation
    long toEpochOffset_ms = getEpochTimeShift();


//////////////////////
//...somewhere in your capture loop: 

    struct v4l2_buffer buf;

    //make the v4l call to  xioctl(fd, VIDIOC_DQBUF, &buf)

    //then: 
    long temp_ms = 1000 * buf.timestamp.tv_sec + (long) round(  buf.timestamp.tv_usec / 1000.0);
    long epochTimeStamp_ms = temp_ms + toEpochOffset_ms ;

    printf( "the frame's timestamp in epoch ms is: %ld", epochTimeStamp_ms);
于 2015-06-27T10:29:59.130 に答える