python和c++有相同的opencv version4.6.0。当使用相同的参数检测到相同的图像,但在 python 中检测到所有角点而在 C++ 中没有或部分检测到角点时,如何在 C++ 中获得相同的结果?附上原图,程序如下。
您的回答将非常感激!
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++
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);
```