16 #include <mrpt/otherlibs/do_opencv_includes.h> 37 unsigned int check_size_x,
unsigned int check_size_y,
bool normalize_image,
38 bool useScaramuzzaMethod)
43 ASSERT_(check_size_y > 0 && check_size_x > 0)
51 bool corners_found =
false;
53 const CvSize check_size = cvSize(check_size_x, check_size_y);
55 const int CORNERS_COUNT = check_size_x * check_size_y;
57 vector<CvPoint2D32f> corners_list;
58 corners_count = CORNERS_COUNT;
59 corners_list.resize(CORNERS_COUNT);
63 int find_chess_flags = cv::CALIB_CB_ADAPTIVE_THRESH;
64 if (normalize_image) find_chess_flags |= cv::CALIB_CB_NORMALIZE_IMAGE;
66 if (!useScaramuzzaMethod)
68 cv::Mat cvImg = cv::cvarrToMat(
img.getAs<IplImage>());
70 vector<cv::Point2f> pointbuf;
74 cvImg, check_size, pointbuf, find_chess_flags);
76 corners_list.resize(pointbuf.size());
77 for (
size_t i = 0; i < pointbuf.size(); i++)
79 corners_list[i].x = pointbuf[i].x;
80 corners_list[i].y = pointbuf[i].y;
91 if (corners_found && corners_count != CORNERS_COUNT) corners_found =
false;
97 img.getAs<IplImage>(), &corners_list[0], corners_count,
100 cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 10, 0.01f));
105 for (
y = 0, k = 0;
y < check_size.height;
y++)
106 for (
int x = 0;
x < check_size.width;
x++, k++)
107 cornerCoords.push_back(
111 return corners_found;
137 std::vector<std::vector<TPixelCoordf>>& cornerCoords,
138 unsigned int check_size_x,
unsigned int check_size_y)
144 std::vector<std::vector<CvPoint2D32f>> corners_list;
148 img, cvSize(check_size_x, check_size_y), corners_list);
150 if (corners_found && !corners_list.empty())
153 cornerCoords.resize(corners_list.size());
156 for (
size_t i = 0; i < corners_list.size(); i++)
158 ASSERT_(corners_list[i].
size() == check_size_x * check_size_y)
161 img.getAs<IplImage>(), &corners_list[i][0],
162 check_size_x * check_size_y, cvSize(5, 5),
164 cvTermCriteria(CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 10, 0.01f));
167 for (
unsigned int y = 0, k = 0;
y < check_size_y;
y++)
168 for (
unsigned int x = 0;
x < check_size_x;
x++, k++)
171 corners_list[i][k].
x, corners_list[i][k].
y));
180 pt_x1 = cornerCoords[i][1],
181 pt_y1 = cornerCoords[i][check_size_x];
185 const Eigen::Matrix<double, 3, 1> Az =
190 for (
unsigned int y = 0;
y < check_size_y;
y++)
192 cornerCoords[i].
begin() +
y * check_size_x,
193 cornerCoords[i].
begin() + (
y + 1) * check_size_x);
199 cornerCoords.clear();
int cvFindChessboardCorners3(const mrpt::utils::CImage &img_, CvSize pattern_size, std::vector< CvPoint2D32f > &out_corners)
A pair (x,y) of pixel coordinates (subpixel resolution).
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
A class for storing images as grayscale or RGB bitmaps.
bool findChessboardCorners(const mrpt::utils::CImage &img, std::vector< mrpt::utils::TPixelCoordf > &cornerCoords, unsigned int check_size_x, unsigned int check_size_y, bool normalize_image=true, bool useScaramuzzaMethod=false)
Look for the corners of a chessboard in the image using one of two different methods.
EIGEN_STRONG_INLINE iterator begin()
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
This base provides a set of functions for maths stuff.
Classes for computer vision, detectors, features, etc.
void findMultipleChessboardsCorners(const mrpt::utils::CImage &img, std::vector< std::vector< mrpt::utils::TPixelCoordf >> &cornerCoords, unsigned int check_size_x, unsigned int check_size_y)
Look for the corners of one or more chessboard/checkerboards in the image.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool find_chessboard_corners_multiple(const mrpt::utils::CImage &img_, CvSize pattern_size, std::vector< std::vector< CvPoint2D32f >> &out_corners)