Reputation: 107
I am trying to draw a minimum bounding rectangle around an object in an image using openCV,
the cv2.minAreaRect is returning the rectangle of correct size but its orientation is off
Following is my codeSnippet
The following screentshot shows the image i am working
In the next screenshot it shows the image with the detected border
According to the opencv documentation linked here: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html this should work
Upvotes: 1
Views: 196
Reputation: 23032
np.where()
returns things in the normal array index (row, column) order, but OpenCV expects points in (x, y) order, which is opposite to (row, column). This has the effect that you are flipping the points about the diagonal of the image.
Simply reverse the points by swapping the two columns. Better yet would just be to be more explicit with variables and not do everything on one line:
y, x = np.where(binary == 0)
coords = np.column_stack((x, y))
Upvotes: 2