Reputation: 964
I have the following images of a chessboard taken from a camera:
Here is my minimal working example code:
import cv2
print(cv2.__version__)
left_gray = cv2.imread('left_raw.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
print(left_gray.shape)
ret, left_corners = cv2.findChessboardCorners(left_gray, (6,5))
print(left_corners)
And here is the output, indicating that no corners were found:
2.4.13.1
(1080, 1920)
None
I read several other StackOverflow questions:
I'm a little lost at this point about how to find the corners. Does anyone have some advice they would like to share? The image and code are right here in case you wish to test them out. I should also point out that I tried increasing the brightness of the original camera when taking the image but no luck.
Upvotes: 3
Views: 10444
Reputation: 2517
This is the best result I can get with the following environment:
5x5
C++ code:
cv::Mat img = cv::imread("klpVW.jpg", cv::IMREAD_GRAYSCALE);
cv::resize(img, img, cv::Size(), 0.5, 0.5);
cv::Ptr<cv::CLAHE> clahe = cv::createCLAHE();
clahe->apply(img, img);
std::vector<cv::Point2f> corners;
cv::Size boardSize(5, 5);
bool found = cv::findChessboardCorners(img, boardSize, corners);
std::cout << "found=" << found << std::endl;
cv::Mat display(img.size(), CV_8UC3);
cv::cvtColor(img, display, cv::COLOR_GRAY2BGR);
cv::drawChessboardCorners(display, boardSize, cv::Mat(corners), found);
cv::imshow("Chessboard corners", display);
cv::imwrite("test_chessboard_corners.png", display);
cv::waitKey(0);
As your OpenCV version is different, you may not get the same result. Anyway, you should use instead this OpenCV pattern (yours seems slightly different for me) and remember that the calibration pattern must be as flat as possible to get good calibration results.
Upvotes: 3
Reputation: 21203
I was able to obtain a satisfactory result using cv2.goodFeaturesToTrack()
.
CODE:
corners = cv2.goodFeaturesToTrack(gray_img,25,0.01,10)
corners = np.int0(corners)
for i in corners:
x,y = i.ravel()
cv2.circle(img,(x,y),3,(0,0,255),-1)
cv2.imshow('Corners',img)
I know it is not accurate, but with some pre-processing you should be able to obtain a better result.
:D
Upvotes: 8