-2

I have a video that records car traffic in the road and I want to do a detection and counting of these cars with opencv 3.0.0 and c ++, and here I have the following source code

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
#include<conio.h>           // it may be necessary to change or remove this line if not using Windows

   int main(int argc, char** argv)
    {
        cv::VideoCapture capVideo;
        capVideo.open("CarsDrivingUnderBridge.mp4");
     if (!capVideo.isOpened())
            return -1;
        Mat frame;

        /// Create Window
        namedWindow("Result", 1);
        while (true) {

            //grab and retrieve each frames of the video sequentially 
            cap >> frame;
            //draw a line onto the frame
            line(frame, Point(0, frame.rows / 2), Point(frame.cols, frame.rows / 2), Scalar(0), 3);
            //display the result
            imshow("Result", frame);
            line(frame, Point(0, frame.rows / 8), Point(frame.cols, frame.rows / 8), Scalar(0), 3);
             imshow("Result", frame);

            //wait some time for the frame to render
            waitKey(30);
        }
        return 0;
    }

This code makes it possible to read the video and draw on this video two lines. what can i add for this source code For the lines to detect the cars and count those cars

nabila
  • 11
  • 1
  • 2
  • 2
    *"I have solved the trivial part. Please help me solve the non-trivial part, so non-trivial that books have been written on the topic alone."* No, sorry, that's not why Stack Overflow is there. It's a Q&A site for specific programming questions. Please take the [tour] and see [ask]. – IInspectable May 21 '17 at 11:52
  • 2
    Then again, it looks like you didn't even solve the trivial part, but had [someone else do it for you](http://stackoverflow.com/q/43956568/1889329). This project is likely **way** out of reach given your current skill set. – IInspectable May 21 '17 at 11:57
  • 1
    This [answer](http://stackoverflow.com/a/36274515/3962537) may give you some inspiration on how to approach this. Porting that code to C++ shouldn't be hard -- in fact it should provide some much needed excercise :) – Dan Mašek May 21 '17 at 16:24
  • [This](https://github.com/ahmetozlu/vehicle_counting) open source project may be useful, it uses blob detector to detect, track and count the vehicles. – Ozlu Sep 13 '17 at 09:33

2 Answers2

0

To detect the cars, you can use a blob detector. Define minimum and maximum size and increase counter when the blobs pass a specific (you need to define that) line.

You can also search the internet for "people counter" and you will find additional readings

0

Here is how i solved this problem, but in python https://medium.com/@a.nikishaev/tutorial-making-road-traffic-counting-app-based-on-computer-vision-and-opencv-166937911660

Andrey Nikishaev
  • 3,759
  • 5
  • 40
  • 55