Add eigen tensor conversions#17320
Add eigen tensor conversions#17320alalek merged 14 commits intoopencv:3.4from jgbradley1:add-eigen-tensor-conversions
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.
Type check is required here through CV_CheckTypeEQ(mat.type(), traits::Type<_Tp>::value, "")
There was a problem hiding this comment.
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.
@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.
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.
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.