Skip to content

Commit 3b22360

Browse files
author
AleksandrPanov
committed
add drawCustomAxis()
1 parent 63204ac commit 3b22360

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

modules/aruco/include/opencv2/aruco.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ CV_EXPORTS_W void drawDetectedMarkers(InputOutputArray image, InputArrayOfArrays
484484

485485

486486
/**
487-
* @brief Draw coordinate system axis from pose estimation
487+
* @brief Draw custom coordinate system axis from pose estimation
488488
*
489489
* @param image input/output image. It must have 1 or 3 channels. The number of channels is not
490490
* altered.
@@ -495,14 +495,18 @@ CV_EXPORTS_W void drawDetectedMarkers(InputOutputArray image, InputArrayOfArrays
495495
* @param rvec rotation vector of the coordinate system that will be drawn. (@sa Rodrigues).
496496
* @param tvec translation vector of the coordinate system that will be drawn.
497497
* @param length length of the painted axis in the same unit than tvec (usually in meters)
498+
* @param thickness Line thickness of the painted axes.
499+
* @param center center of custom coordinate system axis
500+
* @param axisCoefficient coefficient specifying the direction of the coordinate axes x, y, z. Default is (1.f, 1.f, 1.f)
498501
*
499502
* Given the pose estimation of a marker or board, this function draws the axis of the world
500-
* coordinate system, i.e. the system centered on the marker/board. Useful for debugging purposes.
503+
* coordinate system (with default params), i.e. the system centered on the marker/board. Useful for debugging purposes.
501504
*
502-
* @deprecated use cv::drawFrameAxes
505+
* @sa use default params or cv::drawFrameAxes to get world coordinate system axis for object points
503506
*/
504-
CV_EXPORTS_W void drawAxis(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs,
505-
InputArray rvec, InputArray tvec, float length, int thickness=3);
507+
CV_EXPORTS_W void drawCustomAxis(InputOutputArray image, InputArray cameraMatrix, InputArray distCoeffs, InputArray rvec,
508+
InputArray tvec, float length, int thickness=3, Point3f center = Point3f(0.f, 0.f, 0.f),
509+
Point3f axisCoefficient = Point3f(1.f, 1.f, 1.f));
506510

507511

508512

modules/aruco/samples/detect_board.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ int main(int argc, char *argv[]) {
199199
aruco::drawDetectedMarkers(imageCopy, rejected, noArray(), Scalar(100, 0, 255));
200200

201201
if(markersOfBoardDetected > 0)
202-
aruco::drawAxis(imageCopy, camMatrix, distCoeffs, rvec, tvec, axisLength);
202+
aruco::drawCustomAxis(imageCopy, camMatrix, distCoeffs, rvec, tvec, axisLength);
203203

204204
imshow("out", imageCopy);
205205
char key = (char)waitKey(waitTime);

modules/aruco/samples/detect_board_charuco.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ int main(int argc, char *argv[]) {
213213
}
214214

215215
if(validPose)
216-
aruco::drawAxis(imageCopy, camMatrix, distCoeffs, rvec, tvec, axisLength);
216+
aruco::drawCustomAxis(imageCopy, camMatrix, distCoeffs, rvec, tvec, axisLength);
217217

218218
imshow("out", imageCopy);
219219
char key = (char)waitKey(waitTime);

modules/aruco/samples/detect_diamonds.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ int main(int argc, char *argv[]) {
219219

220220
if(estimatePose) {
221221
for(unsigned int i = 0; i < diamondIds.size(); i++)
222-
aruco::drawAxis(imageCopy, camMatrix, distCoeffs, rvecs[i], tvecs[i],
222+
aruco::drawCustomAxis(imageCopy, camMatrix, distCoeffs, rvecs[i], tvecs[i],
223223
squareLength * 0.5f);
224224
}
225225
}

modules/aruco/samples/detect_markers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ int main(int argc, char *argv[]) {
179179

180180
if(estimatePose) {
181181
for(unsigned int i = 0; i < ids.size(); i++)
182-
aruco::drawAxis(imageCopy, camMatrix, distCoeffs, rvecs[i], tvecs[i],
182+
aruco::drawCustomAxis(imageCopy, camMatrix, distCoeffs, rvecs[i], tvecs[i],
183183
markerLength * 0.5f);
184184
}
185185
}

modules/aruco/samples/tutorial_charuco_create_detect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ static inline void detectCharucoBoardWithCalibrationPose()
7272
//! [pose]
7373
// if charuco pose is valid
7474
if (valid)
75-
cv::aruco::drawAxis(imageCopy, cameraMatrix, distCoeffs, rvec, tvec, 0.1f);
75+
cv::aruco::drawCustomAxis(imageCopy, cameraMatrix, distCoeffs, rvec, tvec, 0.1f);
7676
}
7777
}
7878
cv::imshow("out", imageCopy);

modules/aruco/src/aruco.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,16 +1786,16 @@ void drawDetectedMarkers(InputOutputArray _image, InputArrayOfArrays _corners,
17861786

17871787
/**
17881788
*/
1789-
void drawAxis(InputOutputArray _image, InputArray _cameraMatrix, InputArray _distCoeffs, InputArray _rvec,
1790-
InputArray _tvec, float length, int thickness)
1789+
void drawCustomAxis(InputOutputArray _image, InputArray _cameraMatrix, InputArray _distCoeffs, InputArray _rvec,
1790+
InputArray _tvec, float length, int thickness, Point3f center, Point3f axisCoefficient)
17911791
{
1792-
vector<Point3f> axis;
1793-
axis.push_back(Point3f(0.f, 0.f, 0.f));
1794-
axis.push_back(Point3f(length, 0.f, 0.f));
1795-
axis.push_back(Point3f(0.f, length, 0.f));
1796-
axis.push_back(Point3f(0.f, 0.f, -length));
1792+
vector<Point3f> axis_points;
1793+
axis_points.push_back(center);
1794+
axis_points.push_back(center+Point3f(length*axisCoefficient.x, 0.f, 0.f));
1795+
axis_points.push_back(center+Point3f(0.f, length*axisCoefficient.y, 0.f));
1796+
axis_points.push_back(center+Point3f(0.f, 0.f, length*axisCoefficient.z));
17971797
vector<Point2f> axis_to_img;
1798-
projectPoints(axis, _rvec, _tvec, _cameraMatrix, _distCoeffs, axis_to_img);
1798+
projectPoints(axis_points, _rvec, _tvec, _cameraMatrix, _distCoeffs, axis_to_img);
17991799
line(_image, Point2i(axis_to_img[0]), Point2i(axis_to_img[1]), Scalar(255,0,0), thickness);
18001800
line(_image, Point2i(axis_to_img[0]), Point2i(axis_to_img[2]), Scalar(0,255,0), thickness);
18011801
line(_image, Point2i(axis_to_img[0]), Point2i(axis_to_img[3]), Scalar(0,0,255), thickness);

modules/aruco/test/test_aruco_utils.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
namespace opencv_test {
66
namespace {
77

8-
static inline vector<Point2f> getAxis(InputArray _cameraMatrix, InputArray _distCoeffs,
9-
InputArray _rvec, InputArray _tvec, float length,
10-
const float offset = 0.f)
8+
static inline vector<Point2f> getAxis(InputArray _cameraMatrix, InputArray _distCoeffs, InputArray _rvec,
9+
InputArray _tvec, float length, const float offset = 0.f)
1110
{
1211
vector<Point3f> axis;
1312
axis.push_back(Point3f(offset, offset, 0.f));
1413
axis.push_back(Point3f(length+offset, offset, 0.f));
1514
axis.push_back(Point3f(offset, length+offset, 0.f));
16-
axis.push_back(Point3f(offset, offset, -length));
15+
axis.push_back(Point3f(offset, offset, length));
1716
vector<Point2f> axis_to_img;
1817
projectPoints(axis, _rvec, _tvec, _cameraMatrix, _distCoeffs, axis_to_img);
1918
return axis_to_img;

0 commit comments

Comments
 (0)