ros::opencv识别棋盘格角点

#include <ros/ros.h>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;

int main(int argc, char** argv)
{
    ros::init(argc, argv, "depth_point_filter_node");
    ros::NodeHandle nh;
    ros::NodeHandle pnh("~");

    // Read the image
    Mat image = imread("/home/lhh/Chessboard_image/4.jpg", IMREAD_GRAYSCALE);
    if (image.empty())
    {
        std::cerr << "Error: Unable to load image!" << std::endl;
        ros::shutdown();
    }

    imshow("Chessboard", image);
    waitKey(0);

    // 定义棋盘图案大小
    // 一般的M×N棋盘:
    // 每行的内角数量:每行上有 N-1 个内角
    // 每列的内角数量:每列上有 M-1 个内角
    Size patternSize(12, 14); // 棋盘每行和每列的内角数量

    // Detect chessboard corners
    std::vector<Point2f> corners;
    std::cout << "findChessboardCorners start" << std::endl;
    bool found = findChessboardCorners(image, patternSize, corners,
                 CALIB_CB_ADAPTIVE_THRESH + CALIB_CB_NORMALIZE_IMAGE);
    std::cout << "findChessboardCorners done" << std::endl;

    if (found)
    {
        // 提高角点精度
        cornerSubPix(image, corners, Size(11, 11), Size(-1, -1),
                     TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, 0.001));

        // 绘制并显示角
        drawChessboardCorners(image, patternSize, corners, found);
        imshow("Chessboard", image);
        waitKey(0);
    }
    else
    {
        std::cerr << "Error: Chessboard corners not found!" << std::endl;
    }

    ros::spin();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值