TheEngineer
Posts: 3
Joined: Tue Feb 17, 2015 11:24 pm

Trying to Get Raspberry Pi to Recognize Automobiles

Tue Feb 17, 2015 11:31 pm

Greetings!

I'm trying to figure out where I need to begin to get Raspberry Pi to Identify Automobiles by Camera (sort of as in facial recognition, but just to identify the object as a car), as well as to figure out how far away they are). I haven't a clue where I should begin. Does anyone have any advice of where to start? Thanks!

Ian

Reasonable
Posts: 49
Joined: Sun Apr 20, 2014 8:12 pm

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Wed Feb 18, 2015 7:56 am

You'll need a camera+opencv, and lidar

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Wed Feb 18, 2015 9:13 am

Did you start here?

Your question is a bit like "how long is a piece of string?" because you don't say what scenes you will work with. If you are looking at only moving cars in areas where cars are the only significant moving objects then basic motion detection might do.
If you only want to know if a car crosses a particular location that's different to recognising cars anywhere in a large area view.

Here's a video if a technique using Haar cascades.

https://www.youtube.com/watch?v=c4LobbqeKZc

This is a difficult area. If you need very reliable detection in complex scenes it could get very involved.
The Ras Pi is may not be powerful enough for some imaging techniques.

User avatar
PangolinPaws
Posts: 89
Joined: Wed Mar 05, 2014 9:04 pm
Location: Wiltshire, UK
Contact: Website

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Wed Feb 18, 2015 2:38 pm

As Reasonable said, OpenCV (or SimpleCV) is one option, but the speed at which it can do any image processing is limited by the Pi. However, if you just wanted to see how many stationary cars were in a fixed area (like a car park/parking lot) then that shouldn't be a problem.

I did a bit of experimenting with SimpleCV's blob detection a little while ago. You can quite easily find the co-ordinates of the centre of each detected blob and as cars tend to be a solid colour they should give you good blobs.

If you have a good view of the area & you know how far the top of the camera's field of view is from the bottom then you could use the blob coordinates to estimate the distance of the cars (I hope that makes sense).

It'll be fun to try, anyway!
https://github.com/PangolinPaw

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Wed Feb 18, 2015 2:57 pm

PangolinPaws wrote:I did a bit of experimenting with SimpleCV's blob detection a little while ago. You can quite easily find the co-ordinates of the centre of each detected blob and as cars tend to be a solid colour they should give you good blobs.
The problem is you don't know what colours are one whole car and what are neighbouring cars, side of car in shadow, shadows on the surface,or tarmac or line markings etc. The segmentation problem is not trivial. If TheEngineer can tell us more about the task the scale of the problem will become clearer.

Slow moving cars would be easier since the background can be seen and thus eliminated.

User avatar
PangolinPaws
Posts: 89
Joined: Wed Mar 05, 2014 9:04 pm
Location: Wiltshire, UK
Contact: Website

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Wed Feb 18, 2015 3:43 pm

PiGraham wrote:
PangolinPaws wrote:I did a bit of experimenting with SimpleCV's blob detection a little while ago. You can quite easily find the co-ordinates of the centre of each detected blob and as cars tend to be a solid colour they should give you good blobs.
The problem is you don't know what colours are one whole car and what are neighbouring cars, side of car in shadow, shadows on the surface, or tarmac or line markings etc. The segmentation problem is not trivial. If TheEngineer can tell us more about the task the scale of the problem will become clearer.

Slow moving cars would be easier since the background can be seen and thus eliminated.
Good point. My car park example would only work from a very specific direction and with nicely arranged & no two adjacent similar-coloured cars...

What about automatic number plate recognition. They're all (mostly) the same size for distance-estimates and will allow you to distinguish between vehicles. I expect they'd have to be very slow moving cars to give the pi time to do it's stuff though.

We'll wait and see what TheEngineer has in mind!
https://github.com/PangolinPaw

TheEngineer
Posts: 3
Joined: Tue Feb 17, 2015 11:24 pm

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Mon Feb 23, 2015 5:57 pm

Hey guys! Thanks for the tips! To be more specific with what I'm trying to do, I'm basically just trying to create a blind spot warning system like on my Volvo, but I'm afraid I don't know which method to start with to do this. Thanks!

Ian

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Mon Feb 23, 2015 7:54 pm

Ah, now that's a challenge!

You have both camera and object moving, in a cluttered scene, with changing illumination in a fast moving scene and it's a safety critical system.

What do you know about computer vision?

Consider disregarding what the object is. If it's in a particular place, moving in a particular way, it's an alarm condition.

Think about range and relative velocity.
Anything further away that D1 is no concern.
Anything closer than D1 and moving away is no concern.
Anything closer than D1 and moving toward is an alarm.
Anything closer than D2 is an alarm.

You might want more than one velocity sensitive range.

You could measure range and velocity with a stereo camera arrangement.
You could use 'optical flow' data to estimate range and velocity. The Pi can output motion vectors from the H264 encoder, so you could use that.

You could consider using a dopler radar module rather than vision (velocity).
There are also cheap LIDAR detectors available (distance) that might be worth a look. Search on sparkfun.com.

This might be helpful:
Volvo: Wouldn't you know it? Volvo, a company that feels about driving safety the way that Ferrari feels about auto racing, was the first to introduce an automated blind spot detection system into one of their cars back in 2005. It's called the Blind Spot Information System (BLIS), and it blissfully watches for approaching cars on both left and right that the driver can't see. Initially, it used cameras placed in the car's side rear view mirrors, and a computer processed the image from those cameras to see if anything looked like a car and seemed to be approaching dangerously into the area where you might hit it while changing lanes. Newer Volvo BLIS systems, however, use radar (electromagnetic waves that bounce off solid objects and return an echo indicating if they're there) and are mounted in the rear of the car, in the vicinity of the back bumpers. The presence of a hidden vehicle will cause an LED to glow on the A-pillar, the column at the edge of the windshield just to the left of the driver. If you switch on your turn signal to indicate that you plan to enter that lane, the light will start flashing, letting you know that your car is very nervous about your intended maneuver.

http://auto.howstuffworks.com/car-drivi ... erous1.htm

User avatar
PangolinPaws
Posts: 89
Joined: Wed Mar 05, 2014 9:04 pm
Location: Wiltshire, UK
Contact: Website

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Mon Feb 23, 2015 7:58 pm

Interesting idea, I've never thought of that before.

I suppose that probably simplifies certain elements becasuse the cars will always be face-on & in the same place (relative to the car & camera) when they're worth noticing. You'll probably need to angle the camera carefully to minimise background noise.

You may be able to find a Haar cascade for the front of cars as suggested in one if the posts above. Alternatively, have you considered a non-visual option like ultrasonic distance sensors?

You'll have to be pretty confident in your solution before relying on it though!
https://github.com/PangolinPaw

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Mon Feb 23, 2015 8:25 pm

PangolinPaws wrote:You may be able to find a Haar cascade for the front of cars as suggested in one if the posts above.
Possibly so, but do you care what the object on collision course is?

I'd still want the warning if it was this in my blind spot!
Image
Or this:
Image

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Mon Feb 23, 2015 8:37 pm

Image

Maybe all you really need to do is detect that the blind spot zone is empty.

Maybe you could incline the image sensor and focus the lens such that nearer objects are in focus to one side of the sensor and futher objects are in focus to the other side. Using a focus estimation algorithm you could find out how near or far any objects in the zone may be. If they are far away then no alarm. If they are near then alarm.

Possible directions here: http://en.wikipedia.org/wiki/Autofocus

Scan horizontally so that fast moving road surface doesn't register as an object, but vehicles moving at low relative speeds are detected. Faster moving vehicles are possibly less important since they are will not remain in the blind sport for long. They will either be seen in rear view or side mirror.

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Mon Feb 23, 2015 8:40 pm

Another approach is to ignore automatic detection and simply provide a camera view of the blind spot on a display when indicators are activated.

mknoblock
Posts: 16
Joined: Tue Jan 07, 2014 10:20 pm

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Tue May 03, 2016 12:16 pm

I may be a bit late to the party, but I have a related question: how difficult would it be to teach a pi to recognize a particular car from a snapshot, using a fixed camera with the identical background for every pic. I would mount a pi to a post along my driveway to snap the pic and announce who is arriving (Fedex, UPS, son, daughter, mother-in-law, unknown, etc). It doesn't have to be perfect, but this would be kind of a 'friend-or-foe' thing, or at least 'friend-or-not-sure'. We have a long driveway and live in a rural area.

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Tue May 03, 2016 1:05 pm

mknoblock wrote:I may be a bit late to the party, but I have a related question: how difficult would it be to teach a pi to recognize a particular car from a snapshot, using a fixed camera with the identical background for every pic. I would mount a pi to a post along my driveway to snap the pic and announce who is arriving (Fedex, UPS, son, daughter, mother-in-law, unknown, etc). It doesn't have to be perfect, but this would be kind of a 'friend-or-foe' thing, or at least 'friend-or-not-sure'. We have a long driveway and live in a rural area.
Your best option may be to read the licence plate.

Search

Ideally position the camera to see the plate where the car will stop (e.g. at a gate) so that there is no motion blur / distortion, consistent focus and the size of the plate in the image will be fairly constant.
Last edited by PiGraham on Tue May 03, 2016 4:54 pm, edited 1 time in total.

Pithagoros
Posts: 580
Joined: Wed Nov 12, 2014 8:16 pm

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Tue May 03, 2016 1:16 pm

This will be a good exercise, though it will be simpler to use a camera and show the car on a screen so you can recognise the vehicle with your own eyes, unless you can get some advantage from doing image recognition in darkness using stealthy IR illumination. Having a camera that can adjust for having headlights directly into the lens and work just as well in daylight will be a challenge.

PiGraham
Posts: 3404
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Trying to Get Raspberry Pi to Recognize Automobiles

Tue May 03, 2016 5:10 pm

If you feel even more ambitious you could try deep learning neural networks. Take a look at
https://github.com/jetpacapp/DeepBeliefSDK

Return to “General discussion”