Format raw_timestamp image

Hi there!

I’m getting images and timestamp with this function :

    def getFrame(self):
        image, status = self.stream.wait_for(1000)
        frame = None
        if status == cvb.WaitStatus.Ok:
            frame = cvb.as_array(image, copy=False)
            self.counterFrame += 1
        else:
            logging.error("Error to read frame ({})".format(status))
        return frame, image.raw_timestamp

I’m converting the timestamp with this function :

    def convert_microseconds_timestamp_to_date(self, timestamp_microseconds):
        timestamp_seconds = timestamp_microseconds / 1000000
        timestamp = datetime.datetime.fromtimestamp(timestamp_seconds)
        return timestamp.strftime('%Y-%m-%d_%Hh%Mmin%Ss%fms')

I get raw timestamps:

1204743379657805.0
1204743382157685.0
1204743384657575.0
1204743387157454.0
1204743389657334.0
1204743392157214.0
1204743394657103.0
1204743397156983.0
1204743399656863.0
1204743402156752.0

I get formatted dates in 2008 instead of today:

2008-03-05_19h56min24s657575ms
2008-03-05_19h56min27s157454ms
2008-03-05_19h56min29s657334ms
2008-03-05_19h56min32s157214ms
2008-03-05_19h56min34s657103ms

My unix system date is right:

$ date
mardi 26 avril 2022, 12:59:43 (UTC+0200)

Using online unix timestamp give me the same results.

Where I’m wrong? Need to set camera timestamp?

Thanks for your help!

Hi @DavidC ,

most (if not all) GenICam compliant cameras have a feature in their NodeMap that counts ticks of the cameras quartz that have passed.
Also there is a Node that tells you, what the timestamp tick frequency is.
With this information you can calculate, how much time has passed between n images.

As this feature is often needed to check if devices are still in sync, CVB sends them as metadata on the image thus you dont have to query the Nodes values n times per second as we want to avoid too much stress on the NodeMap.

The fact, that you became values that can be converted to some date is more or less coincidence.

So, I would suggest one of the following ways:

  1. Get the unixtime whenever you waited for a new image and dont care about the timestamp
  2. Get the unixtime once when your routine starts and from then use the RawTimestamp and the timestamp tick frequency to calculate how much time has passed.
    C# sample code here

Hope this helps
Cheers
Chris

1 Like

Or use a PTP timesync server to syncronize the camera’s clock over their network (if they are network cam’s)

1 Like