mirror of
https://github.com/opencv/opencv.git
synced 2025-08-06 14:36:36 +08:00
Merge pull request #27311 from asmorkalov:as/draw_axes_warning
Added warning if projected axes are out of camera frame in drawAxes
This commit is contained in:
commit
2af8d0317e
@ -98,7 +98,8 @@ void drawFrameAxes(InputOutputArray image, InputArray cameraMatrix, InputArray d
|
|||||||
CV_CheckType(type, cn == 1 || cn == 3 || cn == 4,
|
CV_CheckType(type, cn == 1 || cn == 3 || cn == 4,
|
||||||
"Number of channels must be 1, 3 or 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);
|
CV_Assert(length > 0);
|
||||||
|
|
||||||
// project axes points
|
// project axes points
|
||||||
@ -110,6 +111,18 @@ void drawFrameAxes(InputOutputArray image, InputArray cameraMatrix, InputArray d
|
|||||||
std::vector<Point2f> imagePoints;
|
std::vector<Point2f> imagePoints;
|
||||||
projectPoints(axesPoints, rvec, tvec, cameraMatrix, distCoeffs, 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
|
// draw axes lines
|
||||||
line(image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255), thickness);
|
line(image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255), thickness);
|
||||||
line(image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0), thickness);
|
line(image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0), thickness);
|
||||||
|
Loading…
Reference in New Issue
Block a user