draw rect around cars

asked 2018-05-08 08:50:00 -0500

flaviu2 gravatar image

updated 2018-05-09 01:49:37 -0500

Hi all of you. For the first beginning, please have patience with my question, I am a beginner in OpenCV and I am struggle to made a project that count cars.

I had taken from here an sample: https://github.com/MicrocontrollersAn...

this project is created in VS2013 (or above), and I have put the code in VS2010. I adapted the code, and launched. Go fine … except doesn't count the cars :D

Can be tested easily from here.

So, I have to go step by step, and create my own code, to control it myself.

I have seen here that there is some steps:

  • Use findContours on the binary image. It will return blob locations.
  • Then use boundingRect to get the rectangle surrounding the blob
  • Now loop over all the rectangles AND use the rectangle function to draw them

But for me is too vague … how can I use findContours ? (m_Mat is cv::Mat m_Mat;)

std::vector<std::vector<cv::Point>> vecPtContours;
cv::Mat MatCopy = m_Mat;
cv::findContours(MatCopy, vecPtContours, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);

result: crash …

Can you guide into achieve this steps ? I need to draw rectangles around cars, and when these rectangles pass by an horizontal or vertical lines, then count the cars …

Thank you for any hint !

edit retag flag offensive close merge delete

Comments

MatCopy must be a binary image see findcontours tutorials

LBerger gravatar imageLBerger ( 2018-05-09 01:54:10 -0500 )edit