opencv手眼标定c++源码
时间: 2023-08-16 13:04:20 浏览: 188
以下是一个使用OpenCV进行手眼标定的C++源码示例:
```cpp
#include <iostream>
#include <opencv2/opencv.hpp>
int main() {
// 读取相机内参
cv::Mat cameraMatrix, distCoeffs;
cv::FileStorage fs("intrinsics.xml", cv::FileStorage::READ);
fs["camera_matrix"] >> cameraMatrix;
fs["distortion_coefficients"] >> distCoeffs;
fs.release();
// 设置标定板尺寸和格点尺寸
cv::Size boardSize(9, 6);
float squareSize = 0.025; // 格点尺寸,单位为米
std::vector<cv::Mat> rvecs, tvecs;
std::vector<std::vector<cv::Point2f>> imagePoints;
std::vector<std::vector<cv::Point3f>> objectPoints;
cv::VideoCapture cap(0); // 打开摄像头
if (!cap.isOpened()) {
std::cerr << "Failed to open camera" << std::endl;
return -1;
}
cv::namedWindow("Chessboard", cv::WINDOW_NORMAL);
while (true) {
cv::Mat frame, gray;
cap >> frame;
cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);
std::vector<cv::Point2f> corners;
// 检测棋盘格角点
bool found = cv::findChessboardCorners(gray, boardSize, corners,
cv::CALIB_CB_ADAPTIVE_THRESH | cv::CALIB_CB_NORMALIZE_IMAGE);
if (found) {
// 提取亚像素角点
cv::cornerSubPix(gray, corners, cv::Size(11,
阅读全文