# Revision history [back]

### draw rect around cars

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/MicrocontrollersAndMore/OpenCV_3_Car_Counting_C]

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: link text

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 ?

    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 … m_Mat is cv::Mat m_Mat;

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 !

 2 None StevenPuttemans 19773 ●14 ●82 ●204 http://stevenputtemans...

### draw rect around cars

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/MicrocontrollersAndMore/OpenCV_3_Car_Counting_C]sample: https://github.com/MicrocontrollersAndMore/OpenCV_3_Car_Counting_C

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: link texthere.

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. locations.
• Then use boundingRect to get the rectangle surrounding the blob 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 ?

 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 … m_Mat is cv::Mat m_Mat;

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 !

### draw rect around cars

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/MicrocontrollersAndMore/OpenCV_3_Car_Counting_C

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 … m_Mat is cv::Mat m_Mat;

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 !