Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility functions to set/get rotation matrix #1194

Draft
wants to merge 1 commit into
base: v3_develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bindings/python/src/pipeline/datatype/ImgFrameBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ void bind_imgframe(pybind11::module& m, void* pCallstack) {
DOC(dai, ImgTransformation, addPadding))
.def("addFlipVertical", &ImgTransformation::addFlipVertical, DOC(dai, ImgTransformation, addFlipVertical))
.def("addFlipHorizontal", &ImgTransformation::addFlipHorizontal, DOC(dai, ImgTransformation, addFlipHorizontal))
.def("addRotation", &ImgTransformation::addRotation, py::arg("angle"), py::arg("rotationPoint"), DOC(dai, ImgTransformation, addRotation))
.def("addRotation", py::overload_cast<float, dai::Point2f>(&ImgTransformation::addRotation), py::arg("angle"), py::arg("rotationPoint"), DOC(dai, ImgTransformation, addRotation))
.def("addRotation", py::overload_cast<std::array<std::array<float, 3>, 3> >(&ImgTransformation::addRotation), py::arg("rotationMatrix"), DOC(dai, ImgTransformation, addRotation, 2))
.def("getRotation", &ImgTransformation::getRotation, DOC(dai, ImgTransformation, getRotation))
.def("addScale", &ImgTransformation::addScale, py::arg("scaleX"), py::arg("scaleY"), DOC(dai, ImgTransformation, addScale))
.def("remapPointTo", &ImgTransformation::remapPointTo, py::arg("to"), py::arg("point"), DOC(dai, ImgTransformation, remapPointTo))
.def("remapPointFrom", &ImgTransformation::remapPointFrom, py::arg("to"), py::arg("point"), DOC(dai, ImgTransformation, remapPointFrom))
Expand Down
13 changes: 13 additions & 0 deletions include/depthai/common/ImgTransformations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ struct ImgTransformation {
* @param rotationPoint Point around which to rotate
*/
ImgTransformation& addRotation(float angle, dai::Point2f rotationPoint);

/**
* Add a rotation transformation around optical center.
* @param rotationMatrix Rotation matrix
*/
ImgTransformation& addRotation(std::array<std::array<float, 3>, 3> rotationMatrix);

/**
* Get the rotation matrix around optical center from the transformation matrix.
* @return Rotation matrix
*/
std::array<std::array<float, 3>, 3> getRotation();

/**
* Add a scale transformation.
* @param scaleX Scale factor in the horizontal direction
Expand Down
15 changes: 15 additions & 0 deletions src/pipeline/datatype/ImgTransformations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,21 @@ ImgTransformation& ImgTransformation::addRotation(float angle, dai::Point2f rota
addTransformation(translateMatrixInv);
return *this;
}

ImgTransformation& ImgTransformation::addRotation(std::array<std::array<float, 3>, 3> rotationMatrix) {
auto intrinsicMatrix = getIntrinsicMatrix();
auto homography = matmul(intrinsicMatrix, matmul(rotationMatrix, getMatrixInverse(intrinsicMatrix)));
addTransformation(homography);
return *this;
}

std::array<std::array<float, 3>, 3> ImgTransformation::getRotation() {
auto intrinsicMatrix = getIntrinsicMatrix();
auto homography = getMatrix();
auto rotation = matmul(getMatrixInverse(intrinsicMatrix), matmul(homography, intrinsicMatrix));
return rotation;
}

ImgTransformation& ImgTransformation::addScale(float scaleX, float scaleY) {
width *= scaleX;
height *= scaleY;
Expand Down
Loading