openCV detect shapes inside contour - opencv

Is there a way to detect shapes inside a contour ? On the image you can see give way and no passage signs(triangle on top of circle). Is there a way to detect the circle from this contour? Triangle is easy because of the inner triangle but I cant figure out how to get the circle.

Take a look at Hough Circle Transform.
It is used to detect circles.
Relevant link: http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html

Related

Difference Between Hough Circle and minEnclosed Circle in OpenCV to detect circles?

I just want to know what will the difference be if instead of using hough circle to detect a circle, I find a contour and using minEnclosed circle find the circle? Which one will be more accurate? As far as I can understand both of them should give me the same thing. Can anyone help clarify
minEnclosed circle will enclose all outlier points in your connected component (blob or edge) while Hough circle searches for the best fit using voting algorithm.
So for searching circles; Hough circle is more accurate.
Edit :

Drawing a outline around card edges by using OpenCV

Currently i am trying to read a square card by using an OCR engine. But before processing image, i want during capturing card image, user should only capture card not other surrounding noise. So for that i looked for overlay & able to create a overlay on camera screen but it is not that useful. So right now i am looking forward some help, how to draw a contour / a outline around a square card when user see it in camera eye as this example.
for ex.
Any body has done this before ?
At first use cvCanny to detect all contours on your image.
Then you can use Standard Hough Line Transform for detection of all lines on the image.
Then you can calculate their intersections and find 4 points: the leftmost and the rightmost of the top and the bottom of the image.
You can ignore small lines which are on the the left and right borders of the image by changing the property of threshold.

How to detect corner with specific angle degree

I have an image with a equilateral triangle and a rectangle:
And I want to detect 3 corner of the triangle only. I follow the OpenCV Harris corner detector tutorial I see that all the corner-point of the triangle have the threshold = 80 (when all the 4 corner-point of the rectangle threshold = 255). But I did not find the link between threshold and degree.
How can I find the corner that in the range of [55,65] degree, for example?
Here is the output Mat http://pastebin.com/raw.php?i=qNidEAG0
P/s: I very new to CV, hope you can give some more detail!
It seems that I found possible solution. I've implemented it on Mathematica and able to explain basic steps.
Use find corners operator and take strongest corners. Use Harris operator.
Find contours (cv::FindContours).
For each corner in each contour draw a circle and find point of intersection between circle and contour. There is no ready function for it in OpenCV and you should implement it yourself.
Now for each corner you have coordinates of three points: corner, and two points on sides of contour. It is enough to evaluate angles using dot product:
Result:

Rectangular approximation of contours

After some color detection, binary thresholding, and using cvFindContours() and drawing the contours and detected blue rectangle on the image I have:
My problem is to some simple collision avoidance (the blue rectangle in the center cannot hit the red "walls"). It would be helpful for my purposes to have the red wall contours be approximated as with rectangles. However, using a simple cvBoundingRect and drawing red rectangles around the white contours I get:
The edges are a little cropped off, but you may get the idea of what we would expect using a bounding rectangle for the contours, as the entire contour is used for the approximation of the bounding rectangle and hence the large overlapping rectangles. What I would like to have is the wall contours be divided into multiple bounding rectangles, such as the the left wall be approximated as one rectangle, the right wall, the forward wall, etc...as in my illustrative rendition below:
Any help in doing so would be greatly appreciated.
Detecting lines (typically Hough, RANSAC) together with some other information you have about the problem should be enough, maybe even overkill. For instance, starting with the below image at left, we get the below image at right.
But if you have the above image at left (which you should have already), the problem is already solved. Just draw both internal and external contours of the walls and you are set.

Using OpenCV to detect clothing buttons on a piece of paper

I have no background in computer vision, but I was curious to know how I could use OpenCV library to achieve the following:
I have a jar of spare buttons, assorted in colour, style and diameter. For the most part they are circular. I evenly scatter them on a piece of white paper, and under good lighting, take a fairly high resolution picture with your average digital camera. How would I got about slicing this image to grab each button individually as a separate object/image?
Thanks in advance.
Two possible ways:
1) Using the circle hough transform
You run some edge detector (canny/sobel) and then the circle hough transform. You'll get the circles.
2) Using contours
Seperate the button and background using thresholding. Detect contours in this thresholded image and you have the buttons!
Articles that might help:
Contours: http://aishack.in/tutorials/an-introduction-to-contours/
Thresholding: http://aishack.in/tutorials/thresholding/
Hough circles: http://aishack.in/tutorials/hough-circles-in-opencv/
Disclaimer: Those are links to my website.
I think the simplest thing you could try is: run the Canny edge detector and apply a Hough transform to detect circles and generate a separate image from each of the circles.
I've been doing some dish recognition and it worked pretty good. do this:
Do some thresholding (buttons should be shiner than background) to leave only the buttons,
then cvFindContours
for each contour:
run cvFitEllipse, it will return you both axis (a,b) of the fitted ellipse.
check that the area of an ellipse PIab is similar to the Area of the contour using cvContourArea and also that both axis are similar a = b. (this will leave only circles)
then you can do whatever you need.
printContour, using cvPrintContour, use cvMinAreaRect2 to get button bounding box, etc
Hough transform is also possible but it is quite more expensive.

Resources