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.)
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.
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:
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.
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.
Is it possible to handle this task by this approach of pixel value counting? If not, what do you suggest?