This Raspberry Pi project stitches together images of passing trains

May 12, 2023

John Aldred

John Aldred is a photographer with over 20 years of experience in the portrait and commercial worlds. He is based in Scotland and has been an early adopter – and occasional beta tester – of almost every digital imaging technology in that time. As well as his creative visual work, John uses 3D printing, electronics and programming to create his own photography and filmmaking tools and consults for a number of brands across the industry.

This Raspberry Pi project stitches together images of passing trains

May 12, 2023

John Aldred

John Aldred is a photographer with over 20 years of experience in the portrait and commercial worlds. He is based in Scotland and has been an early adopter – and occasional beta tester – of almost every digital imaging technology in that time. As well as his creative visual work, John uses 3D printing, electronics and programming to create his own photography and filmmaking tools and consults for a number of brands across the industry.

Join the Discussion

Share on:

This is quite a fascinating concept. Based around a Raspberry Pi, it takes photographs – lots of photographs – of trains passing through a station and then stitches them together to create a single long composite of the entire locomotive. It works on a similar principle to slit-scan photography, which is often used for capturing fast-moving subjects passing a fixed point – like horses finishing a race.

Slit-scan photography in the digital age typically shoots a stream of 1-pixel wide vertical slices. This is required if you’re trying to the capture speed between multiple moving objects, such as in a horse race. But in this project by “jo-m“, the “slits” are a little wider, which means fewer images are required in order to composite the final result together. But for applications such as this, it’s all that’s needed.

The project is called Trainbot, and it lives looking at a single piece of track from jo-m’s apartment, he writes. Running on a Raspberry Pi, a computer vision app spots when there’s a train in the view and records images of it as it moves past the fixed view of the track. It then stitches the photo segments together in order to try and create a super long panoramic image of the entire train. It even uploads them to the web on a website he’s nicknamed Onlytrains.

I have a rail line right under my apartment, so I built a small computer vision app running on a Rasperry Pi which records each train passing, and tries to stitch an image of it.

There is a parameter which tells the program how many pixels there are per meter. From this you can compute the length after stitching. Using framerate, you can compute the speed in the same way.

The images from jo-m’s creation are quite intriguing with the repeated background pattern from each “slit” of the images. The width of the slits is variable based on the speed of the train. Slower-moving trains have a narrower slit while faster trains have a wider one. This allows jo-m to not only calculate the length of the train but also its speed.

It’s a pretty niche project, although I’m sure there are many other applications that this concept could be applied to. If you want to have a go at making your own, head over to GitHub where jo-m has posted all of the code for you to check out under an MIT license. The author has a fairly lengthy to-do list on the project page, so perhaps there’s something there you might be able to help with.

To see jo-m’s complete archive of train photos so far, which seems to get new trains added every 5-10 minutes or so, be sure to head over to his “Onlytrains” website.

[via Hackster.io]

Filed Under:

Tagged With:

Find this interesting? Share it with your friends!

John Aldred

John Aldred

John Aldred is a photographer with over 20 years of experience in the portrait and commercial worlds. He is based in Scotland and has been an early adopter – and occasional beta tester – of almost every digital imaging technology in that time. As well as his creative visual work, John uses 3D printing, electronics and programming to create his own photography and filmmaking tools and consults for a number of brands across the industry.

Join the Discussion

DIYP Comment Policy
Be nice, be on-topic, no personal information or flames.

Leave a Reply

Your email address will not be published. Required fields are marked *

3 responses to “This Raspberry Pi project stitches together images of passing trains”

  1. Trainbot Avatar
    Trainbot

    The prject’s name is Trainbot. With an “r”.

    1. Kaouthia Avatar
      Kaouthia

      The typo in the project’s (with an “o”) name has been fixed :)

      1. TameBot Avatar
        TameBot

        Oh, u gt te jk. Grt. ;-)