I do not think that at present there is a simple and reliable method for detecting rectangles in an image. You have to deal with many problems, such as rectangles that are not exactly rectangular, but only approximately, partial occlusions, changes in lighting, etc.
One possible direction is to segment the image, and then check how close each segment is to the rectangle. Since you cannot trust the segmentation algorithm, you can run it several times with different parameters.
Another direction is to try to parametrically fit the rectangle to the image so that the magnitude of the image gradient along the contour is maximized.
If you decide to work with a parametric approach, you will notice that although the trivial way to parameterize a rectangle is to arrange its four corners, which is 8 parameters, there are several other representations that require fewer parameters.
source share