views:

82

answers:

1

Hello,

I am using OpenCV for square detection in an image. The squares.c example is a really great help, but my problem is that it recognizes pretty much everything that has 4 corners that are close to 90 degrees.

My goal is it however to only recognize the real squares in an image from a video feed. This means the objects themselves have 4 edges with the same length and 4, 90 degree angles. This sounds rather easy at first, but since an object might be tilted in the image, the angles can vary between something like 45 and 135 degrees and the edges have a different length. If I check these attributes though I am still recognizing rectangles that are no squares.

I've been thinking for a good solution to only recognize real squares for a few days now, but everything I come up with is still flawed. I wonder if any of you knows what the exact relation between the angles of the corners and the edge length is. With my guessing so far I have come pretty far, but sometimes random squares pop up that I don't want to recognize. I really think there is some mathematical relation, but I can't really find a formula for squares in a perspective view.

Any help would really be appreciated!

A: 

Without any reference coordinate system, how is this even possible? If you are doing the recognition based on a video feed, can your be "taught" what a square looks like by keeping a square in the field of view at all times? Maybe then you can use this to figure out what the rotations are in 3 space, which you'd then have to apply to everything else in the feed.

Dave
Well no that's not an option for me:( I think it is possible. Currently I am able to pretty much narrow it down to recognizing squares. The problem is however that something like a piece of A4 paper looks pretty much like a tilted square. I am however able to recognize a certain difference between the angles of both with my eyes. That of the paper will have close to 90 degree angles while the square will have something like 70 and 110 degree angles. My problem is that I can't see the correct relation between the angles and the edge length.
Pandoro
Well, I don't know how to solve your problem, but I think I understand what you're saying now. Basically, even though you don't have any sort of reference coordinate system, it should still be possible to rule out non-squares because of the angle and side length relationships. If you take a trapezoid as the simplest case, that trapezoid could only be a square if it satisfied very specific relationships between the sides and angles.
Dave
Exactly that is my idea :) But here are my two problems. I am not sure if the "resolution" of possible angles is actually fine enough to determine this. And I haven't been able to find the actual math behind perspective transforms. Currently I went with something like:angles close to 90 degrees-> allow small variation between edge length.big angles -> allow less variation.This "works", but anything more exact would be really appreciated. Maybe anyone with a deeper knowledge can help me out here.
Pandoro
Well, resolution of possible angles is something you should determine before proceeding, and I imagine that's not too bad. If you create a couple of reference images with known angles, you'll know what your limitations are.
Dave