i am trying to determine the bounding rectangle (position and rotation) for a mainly rectangular shaped contour using OpenCV and python. There is one problem: Parts of the background interfere with the rectangle.
Does anyone have an idea, what else, i could try?
I have tried the following:
-
A closing with different kernel sizes and number of interations -> The rectangular shape was destroyed before all the noise was gone
-
Iterating over the image and all possible 180 degrees of rotation and trying to find the rectangle position and rotation that contains the most white pixels. (This is possible since i know the size of the rectangle. But it was extremely slow and not that precise)
-
Feature Matching (wasnt expecting much, and didnt work at all)
-
Edge detection
-
Contour Approximation with a Polygon with 4 Points
Testimages Images are the following:
- Testimage1
- Testimage2
- Testimage3
- Testimage4
- Testimage5
Many thanks for your help in advance!