OnlyTrains: for fans of trains, and only trains

Jonathan M created Trainbot with a Raspberry Pi Camera. It watches a stretch of train track outside his home, detects trains, and stitches together images of them.

You can watch this for hours and hours on Jonathan’s frontend website

Everyone else at Pi Towers said their favourite thing about the project is the Wes Anderson-esque aesthetic of the screen recording above. My favourite thing is that the tab for the train watching website says “Onlytrains”, because I am easily amused.


As well as the full build guide, Jonathan has shared packages for the image patch matching and RANSAC algorithm implementation that Trainbot uses on his GitHub.

A stitched-together image of patches

Image patch matching means that the image you see is made up of small patches, each of which has been processed individually in order to create a single final composite image. RANSAC stands for RANdom SAmple Consensus, and that’s the machine learning method Jonathan uses to make sure no “outlier” images make it into the final cut. It is trained to select only those patches which show separate bits of the train for the final image, dismissing any overlaps.

Simpler than it sounds

If this all seems too complicated, Jonathan insists it is easier to run than it sounds:

“The computer vision used in Trainbot is fairly naïve and simple. There is no camera calibration, image stabilization, undistortion, perspective mapping, or “real” object tracking. This allows us to stay away from complex dependencies like OpenCV, and keeps the computational requirements low.”
jo-m on GitHub

Wall-to-wall Raspberry Pi

As well as having a Raspberry Pi camera for eyes, Trainbot’s software runs on a Raspberry Pi 4B. Images and data are uploaded to a web server via FTP so you can watch the trains passing by Jonathan’s home.


Trainbot in the snow

Trainbot needs a little more training to make sure it works properly in snow and bad weather. That RANSAC algorithm has a tough time discerning which snow-covered part of a train it is looking at. It seems to do perfectly fine during light flurries if the image above is anything to go by.

Thanks for sharing this visual snippet from your daily life with the rest of the world, Jonathan. Also, congratulations on coining the greatest name for a trainspotting website ever.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Server Status

Aradippou Chat Larnaca Nicosia

Chat Links

Official Links.


Alternative Mirror Links.

1. KiwiIRC 1.
2. KiwiIRC 2.

Other Web Clients.

1. IrcCloud.

Recent Posts

Related Posts:


Follow me on Mastodon

Super Club Radio

Mighty Deals


CyIRC Tweets