find contours in an image [closed]
Hi
I want to detect contours in this image below , so that the output is like the second image
shuold I use canny detection , how can I get this output
Thanks
Hi
I want to detect contours in this image below , so that the output is like the second image
shuold I use canny detection , how can I get this output
Thanks
If you already have a binary image, then you need just to do findContours, then for each contour you can do a boundingRect:
std::vector< std::vector< cv::Point > > contours;
std::vector< cv::Vec4i > hierarchy;
cv::findContours(threshold_output, contours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
std::vector< std::vector< cv::Point > > contours_poly(contours.size());
std::vector< cv::Rect > boundRect(contours.size());
for(int i = 0; i < contours.size(); i++)
{
cv::approxPolyDP(cv::Mat(contours[i]), contours_poly[i], 3, true);
cv::boundRect[i] = cv::boundingRect(cv::Mat(contours_poly[i]));
}
like in this tutorial
What you can do is to play a little with the flags of the functions:
cv::threshold(image, threshold_output, thr, 255, cv::THRESH_BINARY_INV);
And when searching for contours, then use
cv::findContours(threshold_output, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE, Point(0, 0));
For better understanding the findContours functions see this
Asked: 2016-01-05 08:57:14 -0600
Seen: 330 times
Last updated: Jan 05 '16
Area of a single pixel object in OpenCV
OpenCV DescriptorMatcher matches
Conversion between IplImage and MxArray
Video On Label OpenCV Qt :: hide cvNamedWindows
Problems using the math.h class with OpenCV (c++, VS2012)
How to reduce false positives for face detection
Which is more efficient, use contourArea() or count number of ROI non-zero pixels?
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
Can't compile .cu file when including opencv.hpp
Using OpenCV's stitching module, strange error when compositing images