41 #include <opencv2/core.hpp> 42 #include <opencv2/imgproc.hpp> 57 CV_Assert(outSize.height > 0 && outSize.width > 0);
58 CV_Assert(marginSize >= 0);
60 _img.create(outSize, CV_8UC1);
62 Mat out = _img.getMat();
64 out.colRange(marginSize, out.cols - marginSize).rowRange(marginSize, out.rows - marginSize);
66 double totalLengthX, totalLengthY;
67 totalLengthX = _squareLength * _squaresX;
68 totalLengthY = _squareLength * _squaresY;
71 double xReduction = totalLengthX / double(noMarginsImg.cols);
72 double yReduction = totalLengthY / double(noMarginsImg.rows);
75 Mat chessboardZoneImg;
76 if(xReduction > yReduction) {
77 int nRows = int(totalLengthY / xReduction);
78 int rowsMargins = (noMarginsImg.rows - nRows) / 2;
79 chessboardZoneImg = noMarginsImg.rowRange(rowsMargins, noMarginsImg.rows - rowsMargins);
81 int nCols = int(totalLengthX / yReduction);
82 int colsMargins = (noMarginsImg.cols - nCols) / 2;
83 chessboardZoneImg = noMarginsImg.colRange(colsMargins, noMarginsImg.cols - colsMargins);
88 double squareSizePixels =
min(
double(chessboardZoneImg.cols) /
double(_squaresX),
89 double(chessboardZoneImg.rows) /
double(_squaresY));
91 double diffSquareMarkerLength = (_squareLength - _markerLength) / 2;
92 int diffSquareMarkerLengthPixels =
93 int(diffSquareMarkerLength * squareSizePixels / _squareLength);
98 diffSquareMarkerLengthPixels, borderBits);
100 markersImg.copyTo(chessboardZoneImg);
103 for(
int y = 0; y < _squaresY; y++) {
104 for(
int x = 0; x < _squaresX; x++) {
106 if(y % 2 != x % 2)
continue;
108 double startX, startY;
109 startX = squareSizePixels * double(x);
110 startY = double(chessboardZoneImg.rows) - squareSizePixels * double(y + 1);
112 Mat squareZone = chessboardZoneImg.rowRange(
int(startY),
int(startY + squareSizePixels))
113 .colRange(
int(startX),
int(startX + squareSizePixels));
125 float markerLength,
const Ptr<Dictionary> &dictionary) {
127 CV_Assert(squaresX > 1 && squaresY > 1 && markerLength > 0 && squareLength > markerLength);
128 Ptr<CharucoBoard> res = makePtr<CharucoBoard>();
130 res->_squaresX = squaresX;
131 res->_squaresY = squaresY;
132 res->_squareLength = squareLength;
133 res->_markerLength = markerLength;
134 res->dictionary = dictionary;
136 float diffSquareMarkerLength = (squareLength - markerLength) / 2;
139 for(
int y = squaresY - 1; y >= 0; y--) {
140 for(
int x = 0; x < squaresX; x++) {
142 if(y % 2 == x % 2)
continue;
144 vector< Point3f > corners;
146 corners[0] = Point3f(x * squareLength + diffSquareMarkerLength,
147 y * squareLength + diffSquareMarkerLength + markerLength, 0);
148 corners[1] = corners[0] + Point3f(markerLength, 0, 0);
149 corners[2] = corners[0] + Point3f(markerLength, -markerLength, 0);
150 corners[3] = corners[0] + Point3f(0, -markerLength, 0);
151 res->objPoints.push_back(corners);
153 int nextId = (int)res->ids.size();
154 res->ids.push_back(nextId);
159 for(
int y = 0; y < squaresY - 1; y++) {
160 for(
int x = 0; x < squaresX - 1; x++) {
162 corner.x = (x + 1) * squareLength;
163 corner.y = (y + 1) * squareLength;
165 res->chessboardCorners.push_back(corner);
169 res->_getNearestMarkerCorners();
181 nearestMarkerIdx.resize(chessboardCorners.size());
182 nearestMarkerCorners.resize(chessboardCorners.size());
184 unsigned int nMarkers = (
unsigned int)
ids.size();
185 unsigned int nCharucoCorners = (
unsigned int)chessboardCorners.size();
186 for(
unsigned int i = 0; i < nCharucoCorners; i++) {
188 Point3f charucoCorner = chessboardCorners[i];
189 for(
unsigned int j = 0; j < nMarkers; j++) {
191 Point3f center = Point3f(0, 0, 0);
192 for(
unsigned int k = 0; k < 4; k++)
193 center += objPoints[j][k];
196 Point3f distVector = charucoCorner - center;
197 sqDistance = distVector.x * distVector.x + distVector.y * distVector.y;
198 if(j == 0 || fabs(sqDistance - minDist) < cv::pow(0.01 * _squareLength, 2)) {
200 nearestMarkerIdx[i].push_back(j);
201 minDist = sqDistance;
202 }
else if(sqDistance < minDist) {
204 nearestMarkerIdx[i].clear();
205 nearestMarkerIdx[i].push_back(j);
206 minDist = sqDistance;
212 for(
unsigned int j = 0; j < nearestMarkerIdx[i].size(); j++) {
213 nearestMarkerCorners[i].resize(nearestMarkerIdx[i].size());
214 double minDistCorner = -1;
215 for(
unsigned int k = 0; k < 4; k++) {
217 Point3f distVector = charucoCorner - objPoints[nearestMarkerIdx[i][j]][k];
218 sqDistance = distVector.x * distVector.x + distVector.y * distVector.y;
219 if(k == 0 || sqDistance < minDistCorner) {
222 minDistCorner = sqDistance;
223 nearestMarkerCorners[i][j] = k;
235 InputArray _allCharucoCorners,
236 InputArray _allCharucoIds,
237 InputArray _allArucoIds,
int minMarkers,
238 OutputArray _filteredCharucoCorners,
239 OutputArray _filteredCharucoIds) {
241 CV_Assert(minMarkers >= 0 && minMarkers <= 2);
243 vector< Point2f > filteredCharucoCorners;
244 vector< int > filteredCharucoIds;
246 for(
unsigned int i = 0; i < _allCharucoIds.getMat().total(); i++) {
247 int currentCharucoId = _allCharucoIds.getMat().at<
int >(i);
248 int totalMarkers = 0;
250 for(
unsigned int m = 0; m < _board->nearestMarkerIdx[currentCharucoId].size(); m++) {
251 int markerId = _board->ids[_board->nearestMarkerIdx[currentCharucoId][m]];
253 for(
unsigned int k = 0; k < _allArucoIds.getMat().total(); k++) {
254 if(_allArucoIds.getMat().at<
int >(k) == markerId) {
259 if(found) totalMarkers++;
262 if(totalMarkers >= minMarkers) {
263 filteredCharucoIds.push_back(currentCharucoId);
264 filteredCharucoCorners.push_back(_allCharucoCorners.getMat().at< Point2f >(i));
269 Mat(filteredCharucoCorners).copyTo(_filteredCharucoCorners);
270 Mat(filteredCharucoIds).copyTo(_filteredCharucoIds);
271 return (
int)_filteredCharucoIds.total();
282 vector< Size > *_filteredWinSizes,
const Ptr<DetectorParameters> &_params)
283 : grey(_grey), filteredChessboardImgPoints(_filteredChessboardImgPoints),
284 filteredWinSizes(_filteredWinSizes), params(_params) {}
287 const int begin = range.start;
288 const int end = range.end;
290 for(
int i = begin; i < end; i++) {
291 vector< Point2f > in;
292 in.push_back((*filteredChessboardImgPoints)[i]);
293 Size winSize = (*filteredWinSizes)[i];
294 if(winSize.height == -1 || winSize.width == -1)
295 winSize = Size(params->cornerRefinementWinSize, params->cornerRefinementWinSize);
297 cornerSubPix(*grey, in, winSize, Size(),
298 TermCriteria(TermCriteria::MAX_ITER | TermCriteria::EPS,
299 params->cornerRefinementMaxIterations,
300 params->cornerRefinementMinAccuracy));
302 (*filteredChessboardImgPoints)[i] = in[0];
323 OutputArray _selectedCorners,
324 OutputArray _selectedIds,
325 const vector< Size > &winSizes) {
327 const int minDistToBorder = 2;
329 vector< Point2f > filteredChessboardImgPoints;
330 vector< Size > filteredWinSizes;
331 vector< int > filteredIds;
334 Rect innerRect(minDistToBorder, minDistToBorder, _image.getMat().cols - 2 * minDistToBorder,
335 _image.getMat().rows - 2 * minDistToBorder);
336 for(
unsigned int i = 0; i < _allCorners.getMat().total(); i++) {
337 if(innerRect.contains(_allCorners.getMat().at< Point2f >(i))) {
338 filteredChessboardImgPoints.push_back(_allCorners.getMat().at< Point2f >(i));
339 filteredIds.push_back(i);
340 filteredWinSizes.push_back(winSizes[i]);
345 if(filteredChessboardImgPoints.size() == 0)
return 0;
349 if(_image.type() == CV_8UC3)
350 cvtColor(_image, grey, COLOR_BGR2GRAY);
372 Range(0, (
int)filteredChessboardImgPoints.size()),
376 Mat(filteredChessboardImgPoints).copyTo(_selectedCorners);
377 Mat(filteredIds).copyTo(_selectedIds);
378 return (
int)filteredChessboardImgPoints.size();
387 InputArray charucoCorners,
const Ptr<CharucoBoard> &
board,
388 vector< Size > &sizes) {
390 unsigned int nCharucoCorners = (
unsigned int)charucoCorners.getMat().total();
391 sizes.resize(nCharucoCorners, Size(-1, -1));
393 for(
unsigned int i = 0; i < nCharucoCorners; i++) {
394 if(charucoCorners.getMat().at< Point2f >(i) == Point2f(-1, -1))
continue;
395 if(board->nearestMarkerIdx[i].size() == 0)
continue;
401 for(
unsigned int j = 0; j < board->nearestMarkerIdx[i].size(); j++) {
403 int markerId = board->ids[board->nearestMarkerIdx[i][j]];
405 for(
unsigned int k = 0; k < markerIds.getMat().total(); k++) {
406 if(markerIds.getMat().at<
int >(k) == markerId) {
411 if(markerIdx == -1)
continue;
412 Point2f markerCorner =
413 markerCorners.getMat(markerIdx).at< Point2f >(board->nearestMarkerCorners[i][j]);
414 Point2f charucoCorner = charucoCorners.getMat().at< Point2f >(i);
415 double dist = norm(markerCorner - charucoCorner);
416 if(minDist == -1) minDist = dist;
417 minDist =
min(dist, minDist);
426 int winSizeInt = int(minDist - 2);
427 if(winSizeInt < 1) winSizeInt = 1;
428 if(winSizeInt > 10) winSizeInt = 10;
429 sizes[i] = Size(winSizeInt, winSizeInt);
440 InputArray _markerIds, InputArray _image,
441 const Ptr<CharucoBoard> &_board,
442 InputArray _cameraMatrix, InputArray _distCoeffs,
443 OutputArray _charucoCorners,
444 OutputArray _charucoIds) {
446 CV_Assert(_image.getMat().channels() == 1 || _image.getMat().channels() == 3);
447 CV_Assert(_markerCorners.total() == _markerIds.getMat().total() &&
448 _markerIds.getMat().total() > 0);
451 Mat approximatedRvec, approximatedTvec;
452 int detectedBoardMarkers;
453 Ptr<Board> _b = _board.staticCast<
Board>();
454 detectedBoardMarkers =
456 _cameraMatrix, _distCoeffs, approximatedRvec, approximatedTvec);
458 if(detectedBoardMarkers == 0)
return 0;
461 vector< Point2f > allChessboardImgPoints;
463 projectPoints(_board->chessboardCorners, approximatedRvec, approximatedTvec, _cameraMatrix,
464 _distCoeffs, allChessboardImgPoints);
469 vector< Size > subPixWinSizes;
475 _charucoIds, subPixWinSizes);
484 InputArray _markerIds, InputArray _image,
485 const Ptr<CharucoBoard> &_board,
486 OutputArray _charucoCorners,
487 OutputArray _charucoIds) {
489 CV_Assert(_image.getMat().channels() == 1 || _image.getMat().channels() == 3);
490 CV_Assert(_markerCorners.total() == _markerIds.getMat().total() &&
491 _markerIds.getMat().total() > 0);
493 unsigned int nMarkers = (
unsigned int)_markerIds.getMat().total();
496 vector< Mat > transformations;
497 transformations.resize(nMarkers);
498 for(
unsigned int i = 0; i < nMarkers; i++) {
499 vector< Point2f > markerObjPoints2D;
500 int markerId = _markerIds.getMat().at<
int >(i);
501 vector< int >::const_iterator it = find(_board->ids.begin(), _board->ids.end(), markerId);
502 if(it == _board->ids.end())
continue;
503 int boardIdx = (int)std::distance<std::vector<int>::const_iterator>(_board->ids.begin(), it);
504 markerObjPoints2D.resize(4);
505 for(
unsigned int j = 0; j < 4; j++)
506 markerObjPoints2D[j] =
507 Point2f(_board->objPoints[boardIdx][j].x, _board->objPoints[boardIdx][j].y);
509 transformations[i] = getPerspectiveTransform(markerObjPoints2D, _markerCorners.getMat(i));
512 unsigned int nCharucoCorners = (
unsigned int)_board->chessboardCorners.size();
513 vector< Point2f > allChessboardImgPoints(nCharucoCorners, Point2f(-1, -1));
517 for(
unsigned int i = 0; i < nCharucoCorners; i++) {
518 Point2f objPoint2D = Point2f(_board->chessboardCorners[i].x, _board->chessboardCorners[i].y);
520 vector< Point2f > interpolatedPositions;
521 for(
unsigned int j = 0; j < _board->nearestMarkerIdx[i].size(); j++) {
522 int markerId = _board->ids[_board->nearestMarkerIdx[i][j]];
524 for(
unsigned int k = 0; k < _markerIds.getMat().total(); k++) {
525 if(_markerIds.getMat().at<
int >(k) == markerId) {
530 if(markerIdx != -1) {
531 vector< Point2f > in, out;
532 in.push_back(objPoint2D);
533 perspectiveTransform(in, out, transformations[markerIdx]);
534 interpolatedPositions.push_back(out[0]);
539 if(interpolatedPositions.size() == 0)
continue;
542 if(interpolatedPositions.size() > 1) {
543 allChessboardImgPoints[i] = (interpolatedPositions[0] + interpolatedPositions[1]) / 2.;
546 else allChessboardImgPoints[i] = interpolatedPositions[0];
551 vector< Size > subPixWinSizes;
558 _charucoIds, subPixWinSizes);
566 InputArray _image,
const Ptr<CharucoBoard> &_board,
567 OutputArray _charucoCorners, OutputArray _charucoIds,
568 InputArray _cameraMatrix, InputArray _distCoeffs,
int minMarkers) {
571 if(_cameraMatrix.total() != 0) {
573 _cameraMatrix, _distCoeffs, _charucoCorners,
579 _charucoCorners, _charucoIds);
584 minMarkers, _charucoCorners, _charucoIds);
592 InputArray _charucoIds, Scalar cornerColor) {
594 CV_Assert(_image.getMat().total() != 0 &&
595 (_image.getMat().channels() == 1 || _image.getMat().channels() == 3));
596 CV_Assert((_charucoCorners.getMat().total() == _charucoIds.getMat().total()) ||
597 _charucoIds.getMat().total() == 0);
599 unsigned int nCorners = (
unsigned int)_charucoCorners.getMat().total();
600 for(
unsigned int i = 0; i < nCorners; i++) {
601 Point2f corner = _charucoCorners.getMat().at< Point2f >(i);
604 rectangle(_image, corner - Point2f(3, 3), corner + Point2f(3, 3), cornerColor, 1, LINE_AA);
607 if(_charucoIds.total() != 0) {
608 int id = _charucoIds.getMat().at<
int >(i);
611 putText(_image, s.str(), corner + Point2f(5, -5), FONT_HERSHEY_SIMPLEX, 0.5,
624 if(points.size() < 4)
return false;
626 vector< double > sameXValue;
627 vector< int > sameXCounter;
628 for(
unsigned int i = 0; i < points.size(); i++) {
630 for(
unsigned int j = 0; j < sameXValue.size(); j++) {
631 if(sameXValue[j] == points[i].x) {
637 sameXValue.push_back(points[i].x);
638 sameXCounter.push_back(1);
644 for(
unsigned int i = 0; i < sameXCounter.size(); i++) {
645 if(sameXCounter[i] >= 2) moreThan2++;
659 const Ptr<CharucoBoard> &_board, InputArray _cameraMatrix, InputArray _distCoeffs,
660 OutputArray _rvec, OutputArray _tvec,
bool useExtrinsicGuess) {
662 CV_Assert((_charucoCorners.getMat().total() == _charucoIds.getMat().total()));
665 if(_charucoIds.getMat().total() < 4)
return false;
667 vector< Point3f > objPoints;
668 objPoints.reserve(_charucoIds.getMat().total());
669 for(
unsigned int i = 0; i < _charucoIds.getMat().total(); i++) {
670 int currId = _charucoIds.getMat().at<
int >(i);
671 CV_Assert(currId >= 0 && currId < (
int)_board->chessboardCorners.size());
672 objPoints.push_back(_board->chessboardCorners[currId]);
678 solvePnP(objPoints, _charucoCorners, _cameraMatrix, _distCoeffs, _rvec, _tvec, useExtrinsicGuess);
689 const Ptr<CharucoBoard> &_board, Size
imageSize,
690 InputOutputArray _cameraMatrix, InputOutputArray _distCoeffs,
691 OutputArrayOfArrays _rvecs, OutputArrayOfArrays _tvecs,
692 OutputArray _stdDeviationsIntrinsics,
693 OutputArray _stdDeviationsExtrinsics,
694 OutputArray _perViewErrors,
697 CV_Assert(_charucoIds.total() > 0 && (_charucoIds.total() == _charucoCorners.total()));
700 vector< vector< Point3f > > allObjPoints;
701 allObjPoints.resize(_charucoIds.total());
702 for(
unsigned int i = 0; i < _charucoIds.total(); i++) {
703 unsigned int nCorners = (
unsigned int)_charucoIds.getMat(i).total();
704 CV_Assert(nCorners > 0 && nCorners == _charucoCorners.getMat(i).total());
705 allObjPoints[i].reserve(nCorners);
707 for(
unsigned int j = 0; j < nCorners; j++) {
708 int pointId = _charucoIds.getMat(i).at<
int >(j);
709 CV_Assert(pointId >= 0 && pointId < (
int)_board->chessboardCorners.size());
710 allObjPoints[i].push_back(_board->chessboardCorners[pointId]);
714 return calibrateCamera(allObjPoints, _charucoCorners, imageSize, _cameraMatrix, _distCoeffs,
715 _rvecs, _tvecs, _stdDeviationsIntrinsics, _stdDeviationsExtrinsics,
716 _perViewErrors, flags, criteria);
724 const Ptr<CharucoBoard> &_board, Size
imageSize,
725 InputOutputArray _cameraMatrix, InputOutputArray _distCoeffs,
726 OutputArrayOfArrays _rvecs, OutputArrayOfArrays _tvecs,
int flags,
728 return calibrateCameraCharuco(_charucoCorners, _charucoIds, _board, imageSize, _cameraMatrix, _distCoeffs, _rvecs,
729 _tvecs, noArray(), noArray(), noArray(), flags, criteria);
736 InputArray _markerIds,
float squareMarkerLengthRate,
737 OutputArrayOfArrays _diamondCorners, OutputArray _diamondIds,
738 InputArray _cameraMatrix, InputArray _distCoeffs) {
740 CV_Assert(_markerIds.total() > 0 && _markerIds.total() == _markerCorners.total());
742 const float minRepDistanceRate = 1.302455f;
746 Ptr<CharucoBoard> _charucoDiamondLayout =
CharucoBoard::create(3, 3, squareMarkerLengthRate, 1., dict);
749 vector< vector< Point2f > > diamondCorners;
750 vector< Vec4i > diamondIds;
753 vector< bool > assigned(_markerIds.total(),
false);
754 if(_markerIds.total() < 4)
return;
758 if(_image.type() == CV_8UC3)
759 cvtColor(_image, grey, COLOR_BGR2GRAY);
764 for(
unsigned int i = 0; i < _markerIds.total(); i++) {
765 if(assigned[i])
continue;
768 float perimeterSq = 0;
769 Mat corners = _markerCorners.getMat(i);
770 for(
int c = 0; c < 4; c++) {
771 Point2f edge = corners.at< Point2f >(c) - corners.at< Point2f >((c + 1) % 4);
772 perimeterSq += edge.x*edge.x + edge.y*edge.y;
775 float minRepDistance =
sqrt(perimeterSq) * minRepDistanceRate;
777 int currentId = _markerIds.getMat().at<
int >(i);
781 vector< Mat > currentMarker;
782 vector< int > currentMarkerId;
783 currentMarker.push_back(_markerCorners.getMat(i));
784 currentMarkerId.push_back(currentId);
787 vector< Mat > candidates;
788 vector< int > candidatesIdxs;
789 for(
unsigned int k = 0; k < assigned.size(); k++) {
792 candidates.push_back(_markerCorners.getMat(k));
793 candidatesIdxs.push_back(k);
796 if(candidates.size() < 3)
break;
799 for(
int k = 1; k < 4; k++)
800 _charucoDiamondLayout->ids[k] = currentId + 1 + k;
802 _charucoDiamondLayout->ids[0] = currentId;
805 vector< int > acceptedIdxs;
806 Ptr<Board> _b = _charucoDiamondLayout.staticCast<
Board>();
808 currentMarker, currentMarkerId,
809 candidates, noArray(), noArray(), minRepDistance, -1,
false,
813 if(currentMarker.size() == 4) {
820 markerId[0] = currentId;
821 for(
int k = 1; k < 4; k++) {
822 int currentMarkerIdx = candidatesIdxs[acceptedIdxs[k - 1]];
823 markerId[k] = _markerIds.getMat().at<
int >(currentMarkerIdx);
824 assigned[currentMarkerIdx] =
true;
828 vector< Point2f > currentMarkerCorners;
831 currentMarkerCorners, aux, _cameraMatrix, _distCoeffs);
834 if(currentMarkerCorners.size() > 0) {
836 vector< Point2f > currentMarkerCornersReorder;
837 currentMarkerCornersReorder.resize(4);
838 currentMarkerCornersReorder[0] = currentMarkerCorners[2];
839 currentMarkerCornersReorder[1] = currentMarkerCorners[3];
840 currentMarkerCornersReorder[2] = currentMarkerCorners[1];
841 currentMarkerCornersReorder[3] = currentMarkerCorners[0];
843 diamondCorners.push_back(currentMarkerCornersReorder);
844 diamondIds.push_back(markerId);
850 if(diamondIds.size() > 0) {
852 Mat(diamondIds).copyTo(_diamondIds);
854 _diamondCorners.create((
int)diamondCorners.size(), 1, CV_32FC2);
855 for(
unsigned int i = 0; i < diamondCorners.size(); i++) {
856 _diamondCorners.create(4, 1, CV_32FC2, i,
true);
857 for(
int j = 0; j < 4; j++) {
858 _diamondCorners.getMat(i).at< Point2f >(j) = diamondCorners[i][j];
870 OutputArray _img,
int marginSize,
int borderBits) {
872 CV_Assert(squareLength > 0 && markerLength > 0 && squareLength > markerLength);
873 CV_Assert(marginSize >= 0 && borderBits > 0);
876 Ptr<CharucoBoard>
board =
880 for(
int i = 0; i < 4; i++)
881 board->ids[i] = ids[i];
883 Size outSize(3 * squareLength + 2 * marginSize, 3 * squareLength + 2 * marginSize);
884 board->draw(outSize, _img, marginSize, borderBits);
891 InputArray _ids, Scalar borderColor) {
894 CV_Assert(_image.getMat().total() != 0 &&
895 (_image.getMat().channels() == 1 || _image.getMat().channels() == 3));
896 CV_Assert((_corners.total() == _ids.total()) || _ids.total() == 0);
899 Scalar textColor, cornerColor;
900 textColor = cornerColor = borderColor;
901 swap(textColor.val[0], textColor.val[1]);
902 swap(cornerColor.val[1], cornerColor.val[2]);
904 int nMarkers = (int)_corners.total();
905 for(
int i = 0; i < nMarkers; i++) {
906 Mat currentMarker = _corners.getMat(i);
907 CV_Assert(currentMarker.total() == 4 && currentMarker.type() == CV_32FC2);
910 for(
int j = 0; j < 4; j++) {
912 p0 = currentMarker.at< Point2f >(j);
913 p1 = currentMarker.at< Point2f >((j + 1) % 4);
914 line(_image, p0, p1, borderColor, 1);
918 rectangle(_image, currentMarker.at< Point2f >(0) - Point2f(3, 3),
919 currentMarker.at< Point2f >(0) + Point2f(3, 3), cornerColor, 1, LINE_AA);
922 if(_ids.total() != 0) {
924 for(
int p = 0; p < 4; p++)
925 cent += currentMarker.at< Point2f >(p);
928 s <<
"id=" << _ids.getMat().at< Vec4i >(i);
929 putText(_image, s.str(), cent, FONT_HERSHEY_SIMPLEX, 0.5, textColor, 2);
void operator()(const Range &range) const CV_OVERRIDE
CV_EXPORTS_W void drawDetectedCornersCharuco(InputOutputArray image, InputArray charucoCorners, InputArray charucoIds=noArray(), Scalar cornerColor=Scalar(255, 0, 0))
Draws a set of Charuco corners.
InputArray InputArray counter
CV_EXPORTS_W void detectCharucoDiamond(InputArray image, InputArrayOfArrays markerCorners, InputArray markerIds, float squareMarkerLengthRate, OutputArrayOfArrays diamondCorners, OutputArray diamondIds, InputArray cameraMatrix=noArray(), InputArray distCoeffs=noArray())
Detect ChArUco Diamond markers.
CV_EXPORTS void drawCharucoDiamond(const Ptr< Dictionary > &dictionary, Vec4i ids, int squareLength, int markerLength, OutputArray img, int marginSize=0, int borderBits=1)
Draw a ChArUco Diamond marker.
CV_EXPORTS_W void drawDetectedDiamonds(InputOutputArray image, InputArrayOfArrays diamondCorners, InputArray diamondIds=noArray(), Scalar borderColor=Scalar(0, 0, 255))
Draw a set of detected ChArUco Diamond markers.
InputArrayOfArrays const Ptr< CharucoBoard > Size imageSize
static int _interpolateCornersCharucoLocalHom(InputArrayOfArrays _markerCorners, InputArray _markerIds, InputArray _image, const Ptr< CharucoBoard > &_board, OutputArray _charucoCorners, OutputArray _charucoIds)
const Ptr< DetectorParameters > & params
vector< Size > * filteredWinSizes
CV_EXPORTS Ptr< Dictionary > getPredefinedDictionary(PREDEFINED_DICTIONARY_NAME name)
Returns one of the predefined dictionaries defined in PREDEFINED_DICTIONARY_NAME. ...
InputArrayOfArrays const Ptr< CharucoBoard > Size InputOutputArray InputOutputArray OutputArrayOfArrays OutputArrayOfArrays OutputArray OutputArray OutputArray int TermCriteria criteria
PREDEFINED_DICTIONARY_NAME
Predefined markers dictionaries/sets Each dictionary indicates the number of bits and the number of m...
CvImagePtr cvtColor(const CvImageConstPtr &source, const std::string &encoding)
CharucoSubpixelParallel(const Mat *_grey, vector< Point2f > *_filteredChessboardImgPoints, vector< Size > *_filteredWinSizes, const Ptr< DetectorParameters > &_params)
static CV_WRAP Ptr< CharucoBoard > create(int squaresX, int squaresY, float squareLength, float markerLength, const Ptr< Dictionary > &dictionary)
Create a CharucoBoard object.
static bool _arePointsEnoughForPoseEstimation(const vector< Point3f > &points)
static int _selectAndRefineChessboardCorners(InputArray _allCorners, InputArray _image, OutputArray _selectedCorners, OutputArray _selectedIds, const vector< Size > &winSizes)
From all projected chessboard corners, select those inside the image and apply subpixel refinement...
InputArrayOfArrays const Ptr< CharucoBoard > Size InputOutputArray InputOutputArray OutputArrayOfArrays OutputArrayOfArrays OutputArray OutputArray OutputArray int flags
double min(double a, double b)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
CV_EXPORTS_W double calibrateCameraCharuco(InputArrayOfArrays charucoCorners, InputArrayOfArrays charucoIds, const Ptr< CharucoBoard > &board, Size imageSize, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays rvecs=noArray(), OutputArrayOfArrays tvecs=noArray(), int flags=0, TermCriteria criteria=TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON))
It's the same function as calibrateCameraCharuco but without calibration error estimation.
void _drawPlanarBoardImpl(Board *board, Size outSize, OutputArray img, int marginSize=0, int borderBits=1)
Implementation of drawPlanarBoard that accepts a raw Board pointer.
CV_WRAP void draw(Size outSize, OutputArray img, int marginSize=0, int borderBits=1)
Draw a ChArUco board.
CV_EXPORTS_W void refineDetectedMarkers(InputArray image, const Ptr< Board > &board, InputOutputArrayOfArrays detectedCorners, InputOutputArray detectedIds, InputOutputArrayOfArrays rejectedCorners, InputArray cameraMatrix=noArray(), InputArray distCoeffs=noArray(), float minRepDistance=10.f, float errorCorrectionRate=3.f, bool checkAllOrders=true, OutputArray recoveredIdxs=noArray(), const Ptr< DetectorParameters > ¶meters=DetectorParameters::create())
Refind not detected markers based on the already detected and the board layout.
vector< Point2f > * filteredChessboardImgPoints
static int _filterCornersWithoutMinMarkers(const Ptr< CharucoBoard > &_board, InputArray _allCharucoCorners, InputArray _allCharucoIds, InputArray _allArucoIds, int minMarkers, OutputArray _filteredCharucoCorners, OutputArray _filteredCharucoIds)
static CV_WRAP Ptr< DetectorParameters > create()
Create a new set of DetectorParameters with default values.
CV_EXPORTS_W bool estimatePoseCharucoBoard(InputArray charucoCorners, InputArray charucoIds, const Ptr< CharucoBoard > &board, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false)
Pose estimation for a ChArUco board given some of their corners.
CV_EXPORTS_W int estimatePoseBoard(InputArrayOfArrays corners, InputArray ids, const Ptr< Board > &board, InputArray cameraMatrix, InputArray distCoeffs, OutputArray rvec, OutputArray tvec, bool useExtrinsicGuess=false)
Pose estimation for a board of markers.
static int _interpolateCornersCharucoApproxCalib(InputArrayOfArrays _markerCorners, InputArray _markerIds, InputArray _image, const Ptr< CharucoBoard > &_board, InputArray _cameraMatrix, InputArray _distCoeffs, OutputArray _charucoCorners, OutputArray _charucoIds)
void _getNearestMarkerCorners()
void swap(scoped_ptr< T > &, scoped_ptr< T > &)
static void _getMaximumSubPixWindowSizes(InputArrayOfArrays markerCorners, InputArray markerIds, InputArray charucoCorners, const Ptr< CharucoBoard > &board, vector< Size > &sizes)
CV_EXPORTS_W int interpolateCornersCharuco(InputArrayOfArrays markerCorners, InputArray markerIds, InputArray image, const Ptr< CharucoBoard > &board, OutputArray charucoCorners, OutputArray charucoIds, InputArray cameraMatrix=noArray(), InputArray distCoeffs=noArray(), int minMarkers=2)
Interpolate position of ChArUco board corners.
InputArrayOfArrays const Ptr< CharucoBoard > & board