Reputation: 40909
I'm using the OpenCV function findChessboardCorners()
successfully, but I'm confused by the shape of the corners
return value.
Here is my code below. I already know that my chessboard image has 8 x 6 internal corners.
import cv2
nx = 8
ny = 6
img = cv2.imread('test_image2.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, corners = cv2.findChessboardCorners(img, (nx, ny), None)
print(corners.shape)
The last line prints: (48, 1, 2)
.
Where does the 1
come from? I know there are 8 * 6 = 48
corners, and each corner has 2
coordinates. But what about the 1
?
The documentation for findChessboardCorners() doesn't say anything about the corners
result:
corners – Output array of detected corners.
Upvotes: 2
Views: 662
Reputation: 4367
It is an unwanted and unnecessary dimension, you can eliminate the dimension by using the squeeze function of numpy
:
corners = np.squeeze(corners)
In this documentation, they have also mentioned in comment line as "extraneous singleton dimension" :
corners = np.squeeze(corners) # Get rid of extraneous singleton dimension
I simply switched the code to C++ side to dig into. Lastly, here is the code and console output of it:
std::ccorners<<corners.rows<<" "<<corners.cols<<" "<<corners.dims<<std::endl;
Output:
48 1 2
So the output you are getting gives respectively:
Upvotes: 2