Search code examples
geometrycomputer-visiondelphi-7pascalfeature-detection

Finding a rectangle and its corners in an image


I am building a machine for placing SMD elements. I'm almost finished, but I've got one problem.

The elements that I'm placing must be placed in a specific orientation. I want to show the picked element to a camera from its bottom, so that my program can find its corners, and determine how many degrees it has been rotated. Based on this, my program should correct the rotation, so that the element will be placed correctly.

All my attemps to detect the angle have failed. Do you have any ideas ?

Examples:

Here are two simplified illustrations of incorrectly oriented elements, as the camera might see them:

Incorrectly rotated element Another incorrectly rotated element

I want to get the angle by which I need to rotate the element to get it to the correct orientation, as shown below:

Correctly oriented element


Solution

  • If your rectangles are well defined as pictures show, then you can use Hough transform to determine parameters of lines (rectangle edges) and identify rectangle position and orientation.