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 eigen tensor conversions #17320
Add eigen tensor conversions #17320
Conversation
I added a third convenience function (cv2eigen_tensormap) which provides a Tensor interface to cv Mat data without copying any data. |
template <typename _Tp> static inline | ||
Eigen::TensorMap<Eigen::Tensor<_Tp, 3, Eigen::RowMajor>> cv2eigen_tensormap(const cv::InputArray &src) | ||
{ | ||
Mat mat = src.getMat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type check is required here through CV_CheckTypeEQ(mat.type(), traits::Type<_Tp>::value, "")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The suggestion almost worked. I had to modify to account for multiple channels.
CV_CheckTypeEQ(mat.type(), CV_MAKETYPE(traits::Type<_Tp>::value, mat.channels()), "");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jgbradley1 You are right!
Perhaps this one should be clear:
CV_CheckDepthEQ(mat.depth(), traits::Depth<_Tp>::value, "");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, checking the depth would have been clear (and less verbose code). It doesn’t matter to me which approach we use. Since you already approved the merge, I’ll let you decide if it’s worth opening up another PR to update the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Thank you 👍
This PR addresses issue #17237. The primary contributions are two conversion functions (cv2eigen and eigen2cv) for the Eigen::Tensor module along with unit tests.
Pull Request Readiness Checklist
Patch to opencv_extra has the same branch name.