最近在学习相机标定,涉及到角点检测,自己写了一个使用C++版本的Opencv棋盘格检测角点的程序。
话不多说,直接上代码。

/// findChessboardCorners
#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;
int main() {
	int w = 9;
	int h = 6;
	Size boardSize(8, 5);  //对于不同的棋盘格,需要更改这个参数,否则将检测不到角点
	cout << "Start of test" << endl;
	//Mat img = imread("left01.jpg", cv::IMREAD_GRAYSCALE);
	Mat img = imread(".jpg", cv::IMREAD_GRAYSCALE);  //将图片名改为你的图片明

	if (img.empty()) {
		return -1;
	}
	cout << "rows" << img.rows << endl;
	vector<Point2f> corners;
	//bool found = findChessboardCorners(img, boardSize, corners);
	bool found = cv::findChessboardCorners(img, boardSize, corners, cv::CALIB_CB_ADAPTIVE_THRESH | cv::CALIB_CB_FAST_CHECK | cv::CALIB_CB_NORMALIZE_IMAGE);
	cout << "End of test" << endl;
	cout << found << endl;
	if (found) {
		drawChessboardCorners(img, boardSize, corners, found);
		namedWindow("chessboard", WINDOW_NORMAL);
		imshow("chessboard", img);
		waitKey(0);
	}
}
GitHub 加速计划 / opencv31 / opencv
238
21
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
6950bedb Use Mat::total() in Darknet IO 3 天前
105a7747 doc: update image codec configuration reference (add AVIF, fix JPEG XL) #28393 This PR updates the build configuration documentation to: - Add AVIF to the supported format list (it was missing). - Clarify that some codecs (AVIF, JPEG XL) do not support BUILD_* options because OpenCV does not bundle their source code. - Update the description to include "write" capabilities for these formats. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake 4 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐