This is an example of how to detect and localize feature points on a calibration board.
#define LIBCALIB_OPENCV_INTEROP
#include "libCalib.h"
#include <opencv2/calib3d.hpp>
#include <opencv2/opencv.hpp>
void drawCross(cv::Mat &im, const cv::Point2d &pos,
const cv::Scalar color = cv::Scalar(255, 0, 0)) {
const int shift = 5;
const int size = 20 * (1 << shift);
cv::Point posI((1 << shift) * pos.x, (1 << shift) * pos.y);
cv::line(im, posI - cv::Point(size, 0), posI + cv::Point(size, 0), color, 2,
cv::LINE_AA, shift);
cv::line(im, posI - cv::Point(0, size), posI + cv::Point(0, size), color, 2,
cv::LINE_AA, shift);
return;
}
int main() {
std::string imagesPath = std::string(SRCDIR) + "/../data/";
{
std::string filePath = imagesPath + "/pensylvania_c1/img_0002.png";
cv::Mat_<uchar> im = cv::imread(filePath, cv::IMREAD_GRAYSCALE);
std::vector<libCalib::Point2> saddlePoints;
bool patternfound =
std::vector<libCalib::Point3> worldPoints;
const double squareSize = 0.10;
for (int r = 0; r < patternSize.rows; ++r) {
for (int c = 0; c < patternSize.columns; ++c) {
worldPoints.emplace_back(r * squareSize, c * squareSize, 0.0);
}
}
libCalib::subpixSaddlePointSymmetry(im, 10, worldPoints, saddlePoints);
cv::Mat imColor;
cv::cvtColor(im, imColor, cv::COLOR_GRAY2BGR);
cv::drawChessboardCorners(
imColor, cv::Size(patternSize.columns, patternSize.rows),
libCalib::toOpenCV<cv::Point2f>(saddlePoints), true);
cv::namedWindow("IMAGE", cv::WINDOW_AUTOSIZE);
cv::imshow("IMAGE", imColor);
cv::waitKey(0);
}
return 0;
}
LIBCALIB_API bool findCheckerBoard(const Image< uint8_t > &image, const PatternSize &size, std::vector< Point2 > &saddlePoints)
Definition: detection.h:15