fixed points in findHomography
hey guys, im trying to use opencv's cv.findChessboardCorners, cv.findHomography and cv.warpPerspective to find a chessboard in my video feed and display it with the original perspective.
My problem is that the result is sometimes inverted. the chessboard is displayed correctly and the perspective is also correct, but the homography is upside down (you can see this in the 2. image, the color of the drawn keypoints are not correct)
I think this is because the chessboard has no orientation, i.e its the same if i flip it.But i don't know how to fix that since it seems inherent for a chessboard.
Why is this happening? Is it possible to set the orientation of the warpedPerspective, so that its always "one way"? What can i do to make the homography always register in one direction? (i can assume that its never actually going to be upside down in the actual camera feed)
Here is a part of the code i wrote:
# checkerboard is a uint8 array that i created, corner_count is the tuple with patternSize
_, self.cb_corners = cv.findChessboardCorners(checkerboard, corner_count)
found_board, corners = cv.findChessboardCorners(
image=frame,
patternSize=self.corner_count,
flags=cv.CALIB_CB_FAST_CHECK +
cv.CALIB_CB_NORMALIZE_IMAGE +
cv.CALIB_CB_ADAPTIVE_THRESH)
if found_board:
retval, mask = cv.findHomography(self.cb_corners, corners)
dst = cv.warpPerspective(frame, self.homography, (1920, 1080))
cv.imshow("dst", dst)
Add an Aruco marker somewhere, and use that to determine orientation, or use a Charuco claibration target (instead of the plain chessboard) so the orientation is baked in from the beginning.
You have to use an asymmetric chessboard pattern like this one.
@swebb_denver thanks for your answer! how can i combine the aruco marker detection with the cv.findChessboardCorners method to pass them into findHomography together? Or do i do that separately and then detect the arcuro pose and flip my homography accordingly? If there's a good way to combine the two then that is probably the simplest method?
Otherwise the charcuco method looks very promising.
@Eduardo thanks for your reply! That would definitely be the simplest way to fix my problem! I read in the documentation that the border is necessary to segment the black squares properly though. Did you have any issues with this before? Will try this along with the aruco and charuco if there is no border and the background is dark, the outer black squares cannot be segmented properly
White borders is a must. The asymmetric chessboard is the simplest solution.