OpenCV 相机标定 findChessboardCorners() 与 cornerSubPix() 函数

 

OpenCV 官方文档

 
  

findChessboardCorners():Finds the positions of internal corners of the chessboard.

bool cv::findChessboardCorners( InputArray     image,
                     Size        patternSize,
                   OutputArray    corners,
                     int         flags = CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE 
                   )        
Python:
retval, corners  =  cv.findChessboardCorners(image, patternSize[, corners[, flags]])

Parameters
imageSource chessboard view. It must be an 8-bit grayscale or color image.
patternSize   Number of inner corners per a chessboard row and column ( patternSize = cvSize(points_per_row,points_per_colum) = cvSize(columns,rows)).
cornersOutput array of detected corners.
flagsVarious operation flags that can be zero or a combination of the following values:
  • CALIB_CB_ADAPTIVE_THRESH Use adaptive thresholding to convert the image to black and white, rather than a fixed threshold level (computed from the average image brightness).
  • CALIB_CB_NORMALIZE_IMAGE Normalize the image gamma with equalizeHist before applying fixed or adaptive thresholding.
  • CALIB_CB_FILTER_QUADS Use additional criteria (like contour area, perimeter, square-like shape) to filter out false quads extracted at the contour retrieval stage.
  • CALIB_CB_FAST_CHECK Run a fast check on the image that looks for chessboard corners, and shortcut the call if none is found. This can drastically speed up the call in the degenerate condition when no chessboard is observed.

 

The function attempts to determine whether the input image is a view of the chessboard pattern and locate the internal chessboard corners. The function returns a non-zero value if all of the corners are found and they are placed in a certain order (row by row, left to right in every row). Otherwise, if the function fails to find all the corners or reorder them, it returns 0. For example, a regular chessboard has 8 x 8 squares and 7 x 7 internal corners, that is, points where the black squares touch each other. The detected coordinates are approximate, and to determine their positions more accurately, the function calls cornerSubPix. You also may use the function cornerSubPix with different parameters if returned coordinates are not accurate enough.

 

cornerSubPix():Refines the corner locations.

Python: cv2.cornerSubPix(image, corners, winSize, zeroZone, criteria)

Parameter:
image Input image
corners       Initial coordinates of the input corners and refined coordinates provided for output
winSize Half of the side length of the search window. For example, if winSize=Size(5,5) , then a 5*2+1 x 5*2+1 = 11 x 11 search window is used.
zeroZoneHalf of the size of the dead region in the middle of the search zone over which the summation in the formula below is not done. It is used sometimes to avoid possible singularities of the autocorrelation matrix. The value of (-1,-1) indicates that there is no such a size.
criteria Criteria for termination of the iterative process of corner refinement. That is, the process of corner position refinement stops either after criteria.maxCount iterations or when the corner position moves by less than criteria.epsilon on some iteration.

 

转载于:https://www.cnblogs.com/dinghongkai/p/11211840.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
相机标定是计算机视觉中的重要问题,它可以用于恢复相机的内部参数和外部参数。OpenCV提供了一组函数,可以在C++中进行相机标定,其中包括对于相机位姿的求解、立体标定以及多相机标定等。 下面是一个简单的相机标定示例: ```c++ #include <opencv2/opencv.hpp> #include <iostream> int main() { // 读取图像 cv::Mat img = cv::imread("calib.jpg"); // 棋盘格参数 int board_width = 7; int board_height = 7; float square_size = 0.0245; // 棋盘格方块大小(米) // 棋盘格角点 std::vector<cv::Point3f> obj_pts; for (int i = 0; i < board_height; i++) { for (int j = 0; j < board_width; j++) { obj_pts.push_back(cv::Point3f(j * square_size, i * square_size, 0)); } } // 标定图像 std::vector<std::vector<cv::Point2f>> img_pts; std::vector<cv::Point2f> corner_pts; cv::Mat gray_img; cv::cvtColor(img, gray_img, cv::COLOR_BGR2GRAY); bool found = cv::findChessboardCorners(gray_img, cv::Size(board_width, board_height), corner_pts); if (found) { cv::cornerSubPix(gray_img, corner_pts, cv::Size(11, 11), cv::Size(-1, -1), cv::TermCriteria(cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 30, 0.1)); img_pts.push_back(corner_pts); cv::drawChessboardCorners(img, cv::Size(board_width, board_height), corner_pts, found); } // 相机标定 cv::Mat camera_matrix, dist_coeffs; std::vector<cv::Mat> rvecs, tvecs; cv::calibrateCamera(std::vector<std::vector<cv::Point3f>>{obj_pts}, std::vector<std::vector<cv::Point2f>>{img_pts}, gray_img.size(), camera_matrix, dist_coeffs, rvecs, tvecs); // 输出结果 std::cout << "相机内部参数矩阵:\n" << camera_matrix << std::endl; std::cout << "畸变系数:\n" << dist_coeffs << std::endl; // 显示结果 cv::imshow("result", img); cv::waitKey(0); return 0; } ``` 在这个示例中,我们首先读取了一幅图像,然后定义了棋盘格的参数以及每个方块的大小。接着,我们生成了理论上的棋盘格角点,并使用OpenCV的 `findChessboardCorners` 函数在图像中寻找角点。如果找到了角点,我们再使用 `cornerSubPix` 函数对它们进行亚像素级别的精确化。最后,我们使用 `calibrateCamera` 函数对相机进行标定,并输出了相机内部参数矩阵以及畸变系数。 需要注意的是,这个示例只是相机标定中的一小部分,实际应用中可能还需要进行更多的处理,比如多张图像的标定、立体标定等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值