Pi camera performance (frame sync control)

A project log for Optical motion capture system

Tracking human motion for digital animation.

Robert GowansRobert Gowans 12/17/2017 at 10:390 Comments


Due to this technique requiring multiple (at least two) cameras to see the same marker before triangulation can occur, the more in sync the cameras are the more accurate the triangulation can be. If the system runs at 100fps then the worst case frames can be out from each other is by 5ms. After doing a few tests by waving the active markers around, I think frame discrepancies of 1ms or less will provide acceptable results.

Commercial motion capture systems have various methods for syncing cameras, such as over Ethernet or by using dedicated cables. Many camera sensor chips have a sync line which is used to indicate the exact moment a frame should be taken. The Pi camera v2 uses the Sony IMX219 and there is indeed a sync pin on the module. Unfortunately it isn't exposed to the Pi in any way. 

There is another option, and its a very interesting feature exposed to the Pi camera drivers - minor frame rate adjustment. You can modify the current frame rate by tiny amounts causing a slow down or speed up of the overall camera timing. This means that you can adjust the frame rate until you are taking frames in sync with a master clock. If all the cameras adhere to the same master clock, then they will all be taking frames at the same time. The drawback to this method is that it will never be as precise as a direct sync pin, and it requires a small warm up period to achieve initial sync. However this is plenty to get within the goal of 1ms.


My test setup involves filming an LED that is being controlled by a PWM on the Pi. The LED is switching on 80 times a second and each time for 3ms. The camera is filming at 80fps. The PWM is acting as the master clock, so the camera is trying to sync each frame to the PWM cycle.

So what the heck is going on in this video?  First let's cover the flickering in the background, it's due to the lighting of the room I filmed in and has no bearing on the actual test. Second, the Pi camera uses a rolling shutter which means that each row of pixels in the image isn't taken at exactly the same time. Starting from the top, each row is sent down to the Pi one line at a time. It seems to take roughly 6ms to record an entire frame. This is not really desirable behaviour, but I'm willing to work with it. The camera starts capturing the frame while the LED is off. About 3ms later the LED switches on and the camera starts picking up the lit LED. 3ms later the LED switches off again, and this is also about the same time the camera finishes the frame. The whole system is idle for the remaining 6ms of the 80fps cycle. This is what you're seeing in the video. The thing to note is that the LED timing and the frame timing are almost exactly in sync (There is drift if you compare the beginning and end of the video, but that is just due to my poor PID controller ;).


This test proves that by using the frame rate control on the Pi camera you can steadily hold the frame timing in sync with some form of master clock. I'll discuss the methods of syncing a master clock between all the cameras in a future entry.