Why do I get different results in python and C++ environments using the findChessboardCorners function?
python and c++ have same opencv version4.6.0. And How can I get the same result in C++ when the same image is detected with the same parameters, but all corner points are detected in python and none or some in C++? The original image is attached and the program is as follows.
your answer would be great appreciatly!
python code:
img = cv2.imread("left.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
subpix_criteria = (cv2.TERM_CRITERIA_EPS +
cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)
checkerboard = (3,14)
ret, corners = cv2.findChessboardCorners(
gray, checkerboard, cv2.CALIB_CB_ADAPTIVE_THRESH + cv2.CALIB_CB_FAST_CHECK + cv2.CALIB_CB_NORMALIZE_IMAGE)
if ret == True:
corners2 = cv2.cornerSubPix(gray, corners, (3, 3),
(-1, -1), subpix_criteria)
cv2.drawChessboardCorners(img, checkerboard, corners, ret)
C++ code:
cv::Mat oriImg = cv::imread("left.jpg");
cv::Size patternRowsByCols = cv::Size(14, 3);
std::vector<cv::Point2f> corners;
cv::Mat gray;
if (oriImg.channels() == 3) {
cv::cvtColor(oriImg, gray, cv::COLOR_BGR2GRAY);
} else {
gray = oriImg;
}
bool isFound = cv::findChessboardCorners(gray, patternRowsByCols, corners, cv::CALIB_CB_ADAPTIVE_THRESH + cv::CALIB_CB_FAST_CHECK + cv::CALIB_CB_NORMALIZE_IMAGE);
if (isFound) {
cv::cornerSubPix(gray, corners, cv::Size(3, 3), cv::Size(-1, -1), cv::TermCriteria(cv::TermCriteria::MAX_ITER + cv::TermCriteria::EPS, 30, 0.1));
}
cv::drawChessboardCorners(oriImg, patternRowsByCols, corners, isFound);