Is there a c/c++ function out there to detect circles in the edge map of an image - c++

I have already tried OpenCV's HoughCircles (which takes grayscale images as input), which is not giving very favorable results. I want to findthe circles in the edge image because I could clean up the unnecessary edges thus reducing the scope for any confusion.
So is there a function that will find circles from the canny edges of the image?
Thanks.

Related

Detect edge from binary image using Canny edge detection from OpenCV

I'm trying to extract the contour of some traffic signs. The images pass through several steps in order to get a good segmented image. In the final step before applying Canny method I get this image:
After applying Canny I get this image:
The algorithm performs as expected except the top left image for which returns an open contour.
So, my question is, is there any way to use Canny in a manner that the top left image returns an closed contour?
If you already have a binary image, Canny does not give much more information. Canny is useful for finding edges in grayscale images (it decides if a gradient is an edge or not), if the image is black and white, Canny will return the edges that you already have,
I think that you need to use findContours(), which depending on the parameters will return only white or black objects, with or without the holes. It also handles the edges of the image.
Image boundary conditions are problematic in most cases. In this particular case, I would try padding the original image with some extra pixels around the image. Depending on how you add those padding pixels, you should get a complete contour around the signs.
You can use Morphological Transformations before and after applying Canny Edge Detection to manipulate the result.

How to process the result of OpenCV:: Canny Edge Detection

I try the Canny edge detection algorithm to find the edge of a simple circle.
cv:: Canny()
The function returns a
cv::Mat edge
But I do not know how to use these "edge".
My goal is the draw the "edge" back to the original image and read the information within that edge (in this case, the edge is a circle)
I look through the cv:: read function and only find the drawContour function which is not an edge.
And I also do not how to find the coordinate of the edge so that I can do something about the inner part of the circle edge.
I am new to openCV, any suggestion is appreciated.
edges is array (Mat) of the same size as source picture, and it contains zero pixels and max value (255) pixels at edges that Canny function found
You can emphasize edges at source image (by white color), making bitwise_or operation with edges (in my). Or transform edges to color image to draw color edges. Here is example of using edges as mask.
Edges is raster result. To get set of segments, use findContours function on edges, then you can use drawContours
Note that this information is well-googlable.
You need learn how to traverse a cv::Mat object.
http://docs.opencv.org/2.4/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html#the-efficient-way
Besides, I suggest u read first few chapters of the book learning opencv to master the basic usage of this library, now there is a third edition. You can also find many examples in "InstallPath\opencv\sources\samples" and the official tutorial: http://docs.opencv.org/2.4/doc/tutorials/tutorials.html

Detecting Rectangular Shapes in edge image with OpenCV

I want to detect multiple (similar) rectangular objects in an image that have a lot of substructure within them. So, my current plan is to use gaussian blur, morphology and edge detection (Canny). After using edge detection I get this (with very low threshold parameters):
What I want in the end is the outline of the greater rectangles. See:
Currently I try to get this by using HoughLines and findContours afterwards. For this to work, I need to fiddle a lot with the threshold parameters for Canny and HoughLines.
When I get it right for one image the parameters most likely will not work for the next one (e.g. the edges in the previous image were less dominant leading to too many lines detected by the hough transformation). Another problem is that sometimes inner structures are equally or less dominant than one side of the outer edges.
I tried to use a stronger blur or morphology but at some point this blurred away the small gap between the rectangles.
Can I extract the bigger rectangles somehow else given the edge image (preferably with opencv)?
Getting the 4 corner points would be enough.

How to stablize the circle from video stream using opencv?

I've started using OpenCV few days back, My aim is to detect a circle and its centre, I've used hough transform, I'm using a webcam of resolution 640x480, It is working but the circle keeps on changing its position, to better explain it I posted a screen grab on youtube https://www.youtube.com/watch?v=6EGePHkGrok
Here is the code http://pastebin.com/zRG4Yfzy ,yes I know its a bit messy.
First the full video is shown, when the camera stabilizes I press ESC, then the processing begins on the ROI 250x250.
I've added few trackbars to change to parameters of hough transform and amount of blur, changing the blur amount doesn't solve the problem
How to stabilize the circle? Also the camera will not move so no tracking is needed.
Or should I adopt a completely new method of doing this?
According to my understanding I need to apply some sort of filter.
The object has many circular contours, but all have the same centre, so any of the circular contour is detected its fine.
PS:I'm no Image Processing expert, I patched up the code from various sites and books
Hough transforms are known to be error prone.
For your case, you may find contours in your image and filter them by their circularity.
1- grayscale
2- low pass filter (gaussian blur)
3- canny edge detection
4- find contours and list their areas.
5- draw min enclosing circles to your contours.
6- select the contour which has min enclosing circle area closest to contour area.
7- find center of mass of the contour using moments F3 type "mass centers"

How to find contours in an image in OpenCV?

I need to find all contours in an image. I know the whole findcontours () and drawContours () thing, but its using the Canny edge detector that I am having trouble with. To use find contours, you either need to use canny edge detection or threshold the image. I cannot threshold the image because this would result in several edges getting blurred out ("merging" of the edges). So I decided to use Canny Edge detection. However, when I do use it instead of getting perfect edges, I get a variety of lines with gaps in them. This prevents me from getting good contours For example instead of getting the edges of a square, I would get 4 separate lines separated by small gaps resulting in me getting 4 contours instead of one. I tried dilating, opening, closing, Gaussian blurring and basically every morphological operator, but none of these are doing the job. Some do not merge the lines, while some merge the lines with non-relevant lines too. So I was wondering does anyone have a solution on how I can get actual contours from Canny Edge detection, or if not does someone have any alternatives to get all the contours from an image?
make blob, then contours come with it. :)
http://code.google.com/p/cvblob/