diff --git a/modules/calib3d/src/solvepnp.cpp b/modules/calib3d/src/solvepnp.cpp index bb5a932c71..c9428427e8 100644 --- a/modules/calib3d/src/solvepnp.cpp +++ b/modules/calib3d/src/solvepnp.cpp @@ -98,7 +98,8 @@ void drawFrameAxes(InputOutputArray image, InputArray cameraMatrix, InputArray d CV_CheckType(type, cn == 1 || cn == 3 || cn == 4, "Number of channels must be 1, 3 or 4" ); - CV_Assert(image.getMat().total() > 0); + cv::Mat img = image.getMat(); + CV_Assert(img.total() > 0); CV_Assert(length > 0); // project axes points @@ -110,6 +111,18 @@ void drawFrameAxes(InputOutputArray image, InputArray cameraMatrix, InputArray d std::vector imagePoints; projectPoints(axesPoints, rvec, tvec, cameraMatrix, distCoeffs, imagePoints); + cv::Rect imageRect(0, 0, img.cols, img.rows); + bool allIn = true; + for (size_t i = 0; i < imagePoints.size(); i++) + { + allIn &= imageRect.contains(imagePoints[i]); + } + + if (!allIn) + { + CV_LOG_WARNING(NULL, "Some of projected axes endpoints are out of frame. The drawn axes may be not relaible."); + } + // draw axes lines line(image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255), thickness); line(image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0), thickness);