简体   繁体   中英

How to convert tif images from an cv::Mat datatype to Eigen::MatrixXf

For some reason whenever I try to convert an image I imported with OpenCV into an eigen matrix I get this error:

libc++abi.dylib: terminating with uncaught exception of type cv::Exception: OpenCV(3.4.3)

/opt/local/var/macports/build/_opt_bblocal_var_buildworker_ports_build_ports_graphics_opencv/opencv/work/opencv-3.4.3/modules/core/src/matrix_wrap.cpp:1186: 

error: (-215:Assertion failed) !fixedType() || ((Mat*)obj)->type() == mtype in function 'create'

I'm assuming it's because I'm incorrectly importing the image as the wrong data type. Could anyone provide some insight on how to properly convert between the two librarires? Please and thank you!

#include <Eigen/Core>
#include <opencv2/opencv.hpp>
#include <opencv2/core/eigen.hpp>

using namespace Eigen;
using namespace cv;

String filename = "phantom.tif";
Mat img = imread(filename);
MatrixXf img_matrix(img.rows, img.cols);
cv2eigen(img, img_matrix);

If anyone is curious, I was able to get it to work by running this:

//Load Dataset.
String filename = "phantom.tif";
Mat img = imread(filename, cv::ImreadModes::IMREAD_GRAYSCALE);
int Nslice = img.rows;
int Nray = img.cols;
Eigen::MatrixXf tiltSeries;
cv::cv2eigen(img, tiltSeries);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM