5

I am doing a web application where i am pulling in an image from an IP camera, and I need to be able to see if there is a car in the parking spot. I wanted to do this using some sort of shape detection but all I can seem to find is face detection port from c++ and basic shapes such as squares. Can someone point me in the right direction so I can make my own shape detection?snapshot of cam Right now I am drawing the blue box and getting the images data for the x,y,h,w and seeing if I can get any other colors besides the 0xFFFFFF of the parking lot but it doesnt work at night at it will be skewed for humans walking.

Any help would be appreciated..

function drawgrid(){
  context.drawImage(img, 0, 0);
  localStorage.setItem( "savedImageData", canvas.toDataURL("image/png") );
  context.beginPath();
  context.rect(308, 240, 250, 100);
  context.lineWidth = 2;
  context.strokeStyle = 'blue';
  context.stroke();
  var dataURL = canvas.toDataURL();
}

this is grabbing image data saving it to local storage where I then loop through every pixel, however I don't think this is the correct way of going about it.

m59
  • 43,214
  • 14
  • 119
  • 136
Dnaso
  • 1,335
  • 4
  • 22
  • 48
  • tracing shapes is pretty complicated but you can use another cheap method to detect the presence of a car. you cut a square/rectangle out of the image where the parking spot is. you then cut a same-sized square out of the image from the center lane, or anywhere else with clean blacktop. then resize the sub-pics to 1x1 px, and grab the imageData. if the total of the RGBA slots of the subpics adds up to within ~30 levels of each-other, the spot is empty. moving cameras will make this a lot harder... It would be possible to design a stealth car to fool this technique, but nothing's perfect... – dandavis Dec 14 '13 at 17:56
  • as far as brief interruptions like traffic and people walking go, just sample every 5 seconds and make 5 positives in a row be required to trigger the output. – dandavis Dec 14 '13 at 18:02
  • dandavis interesting. Here's the problem (i was thinking the same thing) right now its snowing where I am so that completely offs the test. I also think that same effect will happen at night when the camera uses IR – Dnaso Dec 14 '13 at 18:25
  • Difficult task--As a former Minnesota resident, I know that a car will melt the snow in a parking space that is shaped like a car even if the car leaves. Someone tried photo-car-detection in this link: http://cseweb.ucsd.edu/classes/wi07/cse190-a/reports/ntrue.pdf Perhaps fewer false positives if you just use a wireless motion sensor that's been masked to narrowly point at the parking spot you're interested in. – markE Dec 14 '13 at 20:25
  • markE i thought I had it bad in NJ =( ! – Dnaso Dec 14 '13 at 20:49
  • How about using a Naive Bayes classifier, treat the pixel rbg values as a word, and train it using images from both day and night – levi Dec 14 '13 at 21:14
  • levi, you might be a genius. let me see if that works hold on – Dnaso Dec 14 '13 at 21:41

1 Answers1

4

The question is perhaps a bit broad for SO but you can use something like the following approach to get closer:

  • For each sampled image, convert it to grey-scale and subtract the previous image (or sample a main frame every now and then and use that as a subtractor for the new frame).
  • Apply a threshold filter - all values below convert to black, all above to white
  • Apply erosion filter to deal with pixels as a result of noise in the image
  • Apply statistical measures to determine if number of changed pixels in a region should trigger an "alarm".

It sounds perhaps simple enough but you are in for a variety of challenges such as light conditions and noise, small movements versus large movements. It's (almost) all about finding and tweaking the values, sample rates, threshold values until you have something that matches your situation. The values will vary for day and night light conditions, for example in the night or when poor light (cloudy, heavy dark weather) you will have to deal with a lot of noise in the image. For cloudy and windy days where light changes a lot you will have to deal with thresholds and sample rates, if your camera is set to automatically adjust itself you will have various luminance values depending on white balance (even when converted to grey-scale), f-stop, shutter-time and so on.

They will all affect the result but it's how much will allow this to affect which determines the results in the end and where the statistical part comes in.

There are several other ways but it's a very broad topic. In any case, I hope this can give you some points in the hopefully right direction.