10
$\begingroup$

Disclaimer: I posted this question on StackOverFlow but learned that it is better suited here.

I am a bit new to image processing so I'd like to ask you about finding the optimal solution for my problem, not help for code. I couldn't think of a good idea yet so wanted to ask your advice.

I'm working on a project using OpenCV on counting the vehicles from a video file or a live camera. Other people working on such a project generally track the moving objects then count them but instead of that, I wanted to work with a different viewpoint; asking user to set a ROI (Region of interest) on the video window and work only for this region (for some reasons, like to not deal with the whole frame and some performance increase), as seen below. (The user can set more than one ROI and the user is asked to set the height of the ROI about two times of a normal car by sense of proportion.)

picture1

I've done some basic progress so far, like background updating, morphological filters, thresholding and getting the moving object as a binary image something like below.

picture2

After doing them, I tried to count the white pixels of the final thresholded foreground frame and estimate whether it was a car or not by checking the total white pixels number (I set a lower bound by a static calculation by knowing the height of ROI). To illustrate, I drew a sample graphic:

picture3

As you can see, it was easy to calculate the white pixels and check if it draws a curve by the time and determining whether a car or something like noise.

Problem

I was quite successful until two cars passed through my ROI together at the same time. My algorithm incorrectly counted them as one car. I tried different approaches for this problem and similar to this like long vehicles but I haven't found a satisfactory solution.

Question

Is it possible to handle this task by this approach of pixel value counting? If not, what do you suggest?

$\endgroup$
  • $\begingroup$ Your problem is the reason people use tracking. Also, do you want cars that are moving together (say, a car with a trailer) to be counted as one vehicle or two? $\endgroup$ – Emre May 21 '12 at 22:40
  • $\begingroup$ Firstly, thanks for edition. I dont expect %100 accuracy, cars with trailers can be ignored. but if it is two seperate cars going very close to each other, I need to make the program distinguish both of them, but I have no idea . $\endgroup$ – Horizon1710 May 22 '12 at 0:37
5
$\begingroup$

You can keep track of the last 10-15 frames and count the number of white pixel of these frames. You can differentiate if it is a vehicle or not, since the graph will be high for 10-15 frames you will be able to say that it is a vehicle otherwise it is noise.

To count multiple cars in multiple side by side lanes you can check the pixels column wise, I mean vertically. For the time being you must be checking the pixels horizontally for white pixels.

$\endgroup$
  • $\begingroup$ Yes you are right about checking the vertical lines but how ? Can I determine the entry point of vehicles by checking the first line of my ROI ? $\endgroup$ – Horizon1710 May 22 '12 at 0:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.