This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Map RGB OpenCV Mat to Eigen Tensor

Tags: None
(comma "," separated)
galsight
Registered Member
Posts
2
Karma
0

Map RGB OpenCV Mat to Eigen Tensor

Sun Jun 09, 2019 10:39 am
Hi everyone,

I'm trying to map, convert or even load an OpenCV 3-channel Mat to a 3D Eigen Tensor. So far, I can convert 1-channel grayscale Mat by:

Code: Select all
   
    cv::Mat mat = cv::imread("/image/path.png", cv::IMREAD_GRAYSCALE);
    Eigen::MatrixXd myMatrix;
    cv::cv2eigen(mat, myMatrix);

My attempt to convert a BGR mat to a Tensor have been:

Code: Select all
    cv::Mat mat = cv::imread("/image/path.png", cv::IMREAD_COLOR);
    Eigen::MatrixXd temp;
    cv::cv2eigen(mat, temp);
    Eigen::Tensor<double, 3> myTensor = Eigen::TensorMap<Eigen::Tensor<double, 3>>(temp.data(), 3, mat.rows, mat.cols);

However, I get the error :

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(4.1.0) /tmp/opencv-20190505-12101-14vk1fh/opencv-4.1.0/modules/core/src/matrix_wrap.cpp:1195: error: (-215:Assertion failed) !fixedType() || ((Mat*)obj)->type() == mtype in function 'create'

in the line: cv::cv2eigen(mat, temp);

I guess that the problem with cv2eigen is that this function just works with 1-channel image. I know this is an OpenCV function, not part of the Eigen lib. However, I m hoping to someone who have tried something similar and can put me in the right direction.

All the best,
Gal Sight.
galsight
Registered Member
Posts
2
Karma
0
For someone else interested,
I have posted the question in stackoverflow:

https://stackoverflow.com/questions/56514170/map-bgr-opencv-mat-to-eigen-tensor/56516198#56516198


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot], rblackwell