Are there any opencv function like "cvHoughCircles()" that can use for square detection programming for circle detection program that is CvSeq* circles = cvHoughCircles() but i couldn't find for square detection.
You don't need any separate function for that. OpenCV comes with square detection sample( which actually detects rectangles, you can add constraint that all sides should be equal in length to get square).
Check this link : squares.cpp
There is a good explanation on how this code works in this SOF : How to identify square or rectangle with variable lengths and width by using javacv?
Below is the result you get when apply that code.
There is no opencv function to directly find squares.
But you can use houghLines function, which detects lines, and find intersections between lines with 90 degree angles.
To measure angles between lines I can provide you a Java code snippet:
// returns cosine of angle between line segments 0 to 1, and 0 to 2.
// pt0 is the vertex / intersection
// angle of 90 degrees will have a cosine == 0
public static final double angleCosine(Point pt1, Point pt0, Point pt2) {
double dx1 = pt1.x - pt0.x;
double dy1 = pt1.y - pt0.y;
double dx2 = pt2.x - pt0.x;
double dy2 = pt2.y - pt0.y;
return (dx1 * dx2 + dy1 * dy2) / Math.sqrt((dx1 * dx1 + dy1 * dy1) * (dx2 * dx2 + dy2 * dy2) + 1e-10);
}
Docs about houghLines:
http://docs.opencv.org/modules/imgproc/doc/feature_detection.html?highlight=houghlines#houghlines
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With