Trainspotting With Junk, For Science

[Douglas] hometown Goshen, Indiana takes the state’s motto ‘The Crossroads of America’ seriously, at least when it comes to trains. The city is the meeting point of three heavily frequented railroad tracks that cross near the center of town, resulting in a car-traffic nightmare. When everybody agrees that a situation is bad, it is time to quantify exactly how bad it is. [Douglas] stepped up for this task and delivered.

High tech train counting equipment

He describes himself as cheap, and the gear he used to analyze the railroad traffic at a crossing visible from his home certainly fits the bill: a decades-old webcam, a scratched telephoto lens and a laptop with a damaged hinge.

With the hardware in place, the next step was to write the software to count and time passing trains. Doing this in stable conditions with reasonable equipment would pose no problem to any modern image processing library, but challenged with variable lighting and poor image quality, [Douglas] needed another solution.

Instead of looking for actual trains, [Douglas] decided to watch the crossing signals. His program crops the webcam image and then compares the average brightness of the left and right halves to detect blinking. This rudimentary solution is robust enough to handle low light conditions as well as morning glare and passing cars.

The rest is verifying the data, making it fit for processing, and then combining it with publicly available data on car traffic at the affected intersections to estimate impact. The next council meeting will find [Douglas] well prepared. Traffic issues are a great field for citizen science as shown in Stuttgart earlier. If the idea of bolting old lenses to webcams intrigues you, we got you covered as well.

33 thoughts on “Trainspotting With Junk, For Science

          1. ‘Never thought I’d see our area in a post on here except for MRRF related stuff though.’

            Surprise!!! :D

            And only, what, a tad less than 5 months until the next MRRF…. (Don’t judge. MRRF is about the most fun I get in a year… Yeah, I know, sad.)

    1. Logitech. Windows says it’s a ‘QuikcamPro 4000’, which I got in 2002 or 2003. 640 x 480, which it will do, and 30fps, which it won’t Locks up every half hour to an hour at that frame rate, no matter what machine I plug it into. I’m running it at 15fps. Got it from my ‘well, it sort-a works so I’ll hang onto it and find something to use it for someday’ pile. Come to think of it, that’s the same pile where the lens and the laptop came from. :P

    1. Thanks! To be honest, nothing else worked in ALL conditions, night, day, bright sunlight, and the worst, partly cloudy days where the suns on it one second and it’s in shadow the next. The darn webcam won’t adjust anymore, when it’s put in ‘auto everything’ mode it jumps to ‘it’s too damn dark and I need to brighten it up a bunch’. Which helps not at all.

    2. The idea is good, but in some areas you have the damn things sometimes suddenly go off without a train actually passing in my experience.
      Hope you don’t have that problem there.

  1. Clever way to count the number of times and length the train gates are down!

    Where I am we have relatively few at-grade crossings, and the ones we do have are almost all commuter trains which take just a minute or two to pass, I take for granted waiting for trains to pass. Doug’s data says that the crossing he observes has a train pass every 15-20 minutes on average, with some pretty significant waits, possibly impacting emergency services as well as being a nuisance.

    Seems like he’s also concerned w/ the noise level increasing in nearby residential areas as a result of a structures in an overpass reflecting the train sounds and horns. I’d be looking at a way to record that now and get some hard numbers before the construction is completed so you can argue for limits that must be adhered to post construction.

    Maybe someone closer to the tracks would be willing to host a recording/listening device on their property and WiFi as a way to record data? Would be a good place to use a few cheap audio parts and an ESP8266–I did something similar to count duration and frequency of hammering noise in our office building awhile back when our company was running some destructive lifecycle tests and I wanted to give the mechanical guys some grief over the noise pollution generated.

  2. Old webcam – check, various alternative lenses – check, old laptop – check, skills to get a working system – doubtful but there are ways around that, so – a project! It won’t be useful like the one in the article but it ought to be fun.
    What I really don’t understand though is the fact that there are plenty of road bridges in satellite pictures of Goshen, but they are only over rivers, not railroad tracks.

    1. We’ve noticed that too. Weird, huh? I place it in the ‘what the hell were they thinking’ category, bu I’m not sure the city officials I’m dealing with would agree.

  3. Thank you, I thought it was a bit clever myself, but my wife tells me I’m wrong a lot about that sort of thing. Lol.
    You’re idea for measuring the noise is a great one. I’m going to have to see about doing that. But I really am cheap. Being on disability’ll do that to a guy. Maybe I have something I could use on that ‘Stuff the wife is wrong about and I need to keep’ pile. I’ll go take a look…

    1. Very valid point. I always say if your dealing with the city you have your work cut out for you. If your dealing with the city AND the state, it’s almost impossible to get anything done. If your dealing with the city, the state AND the railroad, it’s pretty hopeless.
      A couple of days ago we had a train stop dead on the tracks, blocking that line that turns to the south and there is no way around until the new overpass is done, for two hours. The reason? The railroad said it needed a crew change and it took that long to get another crew there. Those guys wont pull it forward an inch to unblock a crossing when stuff like that happens. Not. One. Inch.
      There are state laws about blocking crossings more than a set amount of time, and the sheriff’s department has been giving the railroad tickets for doing so. All it does is piss the railroad off more.

    2. When trains aren’t able to use the tracks because they are covered in debri every day, they will get the idea that an overpass is a great idea. Just have the community drop a old used car off on the tracks every day until the train ceo grows a brain.

  4. I would like to add something to this: This project has caused a bit of a stir here in this town, with everyone coming down into one of two camps. One is the ‘more trains means the economy is booming and that’s great’, which is true, while the other is the ‘all these trains suck’ camp. I’m a member of both camps, and I’m also the only one in town, apparently, who like FACTS, cold hard data, to back up what I’m talking about. The part of the response I like the best is when a student at a local school informed me that some of the students are using my data for their data science class to practice making up some some data visualizations. Love it!
    Oh, better not neglect this: Thanks for the write up, Christian! Heck of a nice job! :D

    1. Perhaps a silly question, but have you thought about monitoring the railroad ATCS signals over the air and logging that data along side your visual data?

      I realize you said you prefer doing things on the cheap, and perhaps a software defined radio setup may not qualify, but seems like it would be a nice wealth of data to add in. The trains themselves broadcast their IDs, location, and speed data. You can likely also pickup the switch track commands from dispatch.

      1. Not a silly question at all! Never even thought about it.
        I do have a SDR dongle. I usually have it running SDRSharp with the scanner addon, listening to police and fire. I will definitely look into your suggestion. Thank You!

      2. This is looking very interesting. Been digging into it and the railroad has one of the transmitter stations 500 feet from my house!
        Drawback is I’d have to run another machine 24/7. There is no way that old laptop will do both at once. So there is that…

          1. Thank you.

            ‘have brass balls or are a bit bonkers’

            The two are not mutually exclusive. :P

            ‘May we respectfully suggest Linux?’

            um, uh, point taken. (he says, shrugging his shoulders and staring at his shoes.)

  5. Well, the laptop finally decided it had enough. May it rest in peace.

    This project, or at least the data collection part of it is done, at least for now. Maybe I’ll try to find another machine to run it on one of these day, and run it for another month later in the winter. The web site will stay up, and all the data is still available there. And I still intend to crunch the numbers and get some more looks at the data from different views.

    Over all, I have to say it was worth the trouble, and I’ve certainly given this city something to think about, and hard numbers to back it up. So it was well worth it.

    1. If the community arranged the delivery of an old abandoned car on to the tracks every day even a ceo as thick as the train corporations one, would eventually wake up to the fact that an overpass is a great idea.

    1. Thanks!

      Yeah, our winter weather sucks sometimes, alright. But it is what it is, right?

      WTG on moving away from our winters. We talk about moving south, but that’s all it is so far. Talk.

      The train program is back up again, and my son is ‘posed to be bringing me his spare laptop, so it should stay up from then on. I’m also working on adding a new page to the website that will display what’s going on in near real time. :)

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

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