Page 1 of 1

Shutter Glasses

Posted: Tue Mar 05, 2019 4:20 am
by perfo
Hello All, I'm hoping someone out there may have some pointers as to the best approach for this project of mine.

I'm using a pair of shutter glasses and hacked it so the RPI can control the glasses direct which is pretty simple.
I would like to switch between two images then toggle an output pin. So image 1 in frame 1 then image 2 in frame 2 then pin high or low then do it all again.
The thing I'm having difficulty with is how to show the images quick enough. Ideally I would like 120 frames per second but I'd be happy with 60 for now.
Some simple python code just to show what I'm thinking of is below.

Code: Select all

from PIL import Image

im1 = Image.open("An Image for the left eye")
im2 = Image.open("An image for the right eye")

while AllGood:
    im1.show()
    im2.show()
    Toggel_Output    

print("done")
quit
Thanks for reading...

Re: Shutter Glasses

Posted: Wed Mar 06, 2019 2:57 am
by perfo
I've done a bit of reading up on stop motion photography. This kind of application would be perfect for my needs as I simply need to show one image after another but in quick succession. However I can't seem to find a good tut on how to show a series of frames or images with the PI.

Does anyone know if it's even possible to show 60 - 120 fps with the pi using python ? ?
Any suggestions ? anyone ?

Thanks for reading
Perfo...

Re: Shutter Glasses

Posted: Wed Mar 06, 2019 3:10 am
by perfo
There is a great tut on stop motion film making here
https://projects.raspberrypi.org/en/pro ... top-motion

Using the code from there

Code: Select all

 avconv -r 10 -i animation/frame%03d.jpg -qscale 2 animation.h264 
to make a file out of my frames and then

Code: Select all

  omxplayer animation.h264 
to play it
This works great and fast but there doesn't seem to be a way to trigger an output between the frames. I have read about the possibility of each frame raising an interrupt and thus getting a sort of Vsync but the discussion was above me and I couldn't see how I could make it toggle a pin.

If I use the parallel display interface (DPI) set up will the Vsync on the DPI have anything to do with the frame sync on the HDMI port ? I'm guessing not but hoping yes..

Re: Shutter Glasses

Posted: Sun Mar 10, 2019 2:58 am
by perfo
Well thanks for all your comments folk :-)

I've included what I've found incase it helps someone else.

I finally discounted most avenues as they didn't keep in sync or gave other problems .
The DPI and HDMI can be set up to mirror one an another and makes it easy to grab the Vsync off the GPIO but they aren't synchronised and the delay between them can be quite large.
So I settled on trying to get at the video core stuff direct and winkle out the Vsync from there. That way I can simply make a video out of my frames and play it like a standard video. then sniff out the vertical synchronisations the HDMi port uses. That way it is always in sync even if the frame rate wavers.

Unbeknownst to me at the outset, Video Core API's come with raspbian Stretch and after a lot of trying to learn impossible things I came up with a bit of code that uses the API's and works a treat...

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#include <stdint.h>
#include "bcm_host.h"

int Toggle = 0;

void Vsync(DISPMANX_UPDATE_HANDLE_T update, void *arg)
{
  Toggle= !Toggle;
}

int
main(void)
{
    if (wiringPiSetup () == -1)
      return 1 ;

    bcm_host_init();

    DISPMANX_DISPLAY_HANDLE_T display = vc_dispmanx_display_open(0);

    vc_dispmanx_vsync_callback(display, Vsync, NULL);
    while (1)
    {
        digitalWrite (11, Toggle) ; 
    }

    return 0;
}

Re: Shutter Glasses

Posted: Wed Mar 13, 2019 10:08 am
by perfo
Grrr,
It doesn't work.
Looking at the Vsync on my scope I can see a nice train of pulses. With my code above this gets swapped to a nice square wave with the pulse going on with one Vsync pulse and going off with the next sync pulse. At a 60hz refresh rate these pulses are 16 ms so equal to 60 frames per second.
This was (so I thought) perfect for my project where I want to swap the glasses every other frame (as per normal 3d)

I produced a video that had each frame last for 1 second and put a divide by 60 bit in my code to see if the synchronisation between the Vsync pulses and the frames appeared right. It did, the frames changed in line with the glasses swapping... Great so I thought. However when i try a 60fps video and a 60hz refresh rate it is no longer in sync and appears to be all over the place. I'm thinking that this means the frames that I want the glasses to synchronise with are not synchronised with the video refresh and thus the Vsync. I guess this may seem obvious now due to the fact I can have different refresh rates and or FPS and the video still plays ok..
Hmmmm so does this mean using the Vsync idea is a dead end for my project ? Does anyone know if this is the case ?
Any help appreciated....as I haven't much hair left....
Thanks All

Ps an error in my code above , I didn't declare the GPIO as an output port. This worked until I rebooted the RPI then didn't so I found I'd missed the declaration.

Re: Shutter Glasses

Posted: Thu Mar 14, 2019 8:35 am
by perfo
I'm not getting any tearing though so the frame vs refresh can't be that far out of sync...
Is there any way to force the fps and refresh to be in sync ?