← Back to context

Comment by jo-m

3 years ago

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.

It has a frontend at https://trains.jo-m.ch/.

Edit: it's currently raining and the rain drops are disturbing the images a bit.

Have you considered getting a line scan camera for sharper and higher resolution images? I took some train scans with one: https://daniel.lawrence.lu/photos/

Incidentally I also built some tech for it: https://github.com/dllu/nectar but I need to update the readme...

  • Thanks for sharing, those photographs are very clear and sharp (especially this one: https://pics.dllu.net/file/dllu-pics/boston-pcc.jpg) it seems to tickle my brain.

    • I have three of those actually:

      https://daniel.lawrence.lu/photos/pcc

      Technically, the photo could be twice the resolution, since the length of the line scan sensor is 4096. It consists of two lines, RGRGRG and GBGBGB. By interpolating the red and blue channels, it would be possible to get images 4096 pixels tall. The challenge is that the two green channels apparently have quite different sensitivity and also each pixel has some variation in sensitivity, which also seems to drift with temperature and settings, so it's quite annoying to calibrate everything properly haha.

  • Wow, the pictures look amazing! Yes, the look of line scan images were an inspiration for this project. But of course, I also tried to keep BOM costs down and so ended up with a RP4 + RPi Camera.

  • Have you tried the opposite direction? Sitting on the train with the line feed and taking a picture of outside? Like say, a panorama view of the entire run-length of the line, distorted in proportion to the trains turns and accelerations.

  • I love how the line scan camera’s horizontal background makes it look like the trains are moving impossibly fast. Not only are the images sharp & high res, it has a great aesthetic and implies you were tracking an action shot.

  • I remember seeing your photographs on Wikimedia Commons and wondering how you did them - now I know! I always assumed that you just used a very quick shutter with an f-stop of zero :)

    • I have a huge backlog of photos that I need to contribute to Wikimedia Commons! I'll get around to doing it eventually, hopefully before 2045.

      1 reply →

    • I know he told us how already, but that would have left the background sharp, rather than always the same.

  • How do you get the x scaling right? You have to measure the speed of the train somehow?

    • When the train is moving at a constant speed, you can just scale the image manually to make it just right. If it's moving at a non-constant speed, you can apply a spline or similar to remove the distortion.

This is such a cool project! I live right next to a busy road and for a long time have wanted to do something like this that would count the vehicles passing. I've always been curious how many cars pass on a given day and I feel like the hardest part now adays would be getting the right camera angle so if cars are occupying all 3 lanes they aren't counted incorrectly. From there I just need to detect cars as they pass and count them.

It's really cool to see it used like this! The resulting images are really neat as well!

Given the type of trains that are passing (it seems no IC/IR), along with their precise timing and direction, I'm sure it is easy to figure out where exactly you are living.

I wonder if there's open data or an open API for the schedule or location information. That way, you could include information on which train is which.

  • Yes, the APIs are there, with minute accurate real time data. Would just have to do it ;)

This is close to what I've always wanted to build; a camera watching the road next to me that records the speed of the vehicle traveling by. I should have everything needed from a simple camera setup, but I've not bothered actually doing it.

Since you have speed, I should dig into this.

Awesome. Congratulations from a fellow Swiss (and panorama photo dabbler).

  • And yet again I forgot it’s not the Chinese TLD.

    By the way I have a quick expansion for most TLDs and for the Swiss .ch “cheese” sounds rather more apt and easier than the real one in my head :)

This is cool. How do you calculate the speed of the train?

I'm assuming you are measuring how far a certain feature of the train takes to get from one point of the frame to the other. Similar to how police catch people speeding by measuring how long road markings take to pass in a given frame.

Sounds interesting id love to know how you do it. Is the speed calculated based on the noise of the wheels going over a track join? Then you can work out the length/speed based on the time it takes etc. Are the train types/images random or calculated some how?

  • 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.

Really cool. They look like model trains! :-)

  • Yeah! I've never seen trains so clean and modern looking in my life. They look like they came out of a futuristic toy set.

    • They're swiss trains, I guess we have enough wealth to make sure that our trains are clean. The interior is also almost always clean, except early morning on weekends (drunk people).

      From time to time I see a train with graffiti on it, but usually they remove such things very fast.

Wow that's very cool. The resulting super flat images of the trains is really interesting -- like taking a photo from immense distance

When you say "right under my apartment", where exactly do you mean? Because I also have a train line going underground very near my apartment but it's not directly under. Could I capture such images? And I'm on the 4th floor.

  • I got confused at first too. What he means is "somewhere outside on the ground level while my apt is not on the ground level, there are trains passing by which I can see from my apt". You need line of sight.

    This is not mysterious tech deriving images from sound traveling through the floor. You will be out of luck with your underground subway.

    • If you have the schedule and the sound I'm sure you could make a cam with translucent ground. You should be able to figure out where it is, which model and how long it is. Who knows, maybe the orchestra of break sounds (it has many) is unique enough to spot which it is exactly.

Nice job! I would be really happy if I ever finished my own hobby projects this well.

Sharing this with SBB

I hope they notice (also makes me want to guess the location). I am in Zurich and I hope I don't find this spot

Curious to know how you manage to concentrate during waking hours on work and how you sleep peacefully?

  • There's a lot of trains in Switzerland so there's a lot of apartments by tracks. For the most part, the apartments are just built well.

    Plus, the trains and tracks are very well maintained, so they create a lot less noise than you may be used to.

What’s up with the duplicated cars at the top?

  • The camera is pointing at the car. The train is moving past the car. The images of the whole train are made by stitching together lots of photos, all containing the bit of the train in front of the car as it moves past it.

  • From what I can see, they're not actually duplicated, I would suggest taking a closer look at the windows. But I do agree that it's quite hard to see the difference.

    The trains look very clean from the outside. I do wonder how loud is it, to live so near the tracks.

    • They are also very clean from the inside :).

      I also live right next to a train line in CH (that has exactly the same kind of rolling stock passing by as the ones captured by jo-m). These are modern commuter trains (no cargo and long distance trains), and are a lot less loud than you'd expect. A somewhat busy street nearby would be an order of magnitude more annoying.