【问题标题】:How to convert tif images from an cv::Mat datatype to Eigen::MatrixXf如何将 tif 图像从 cv::Mat 数据类型转换为 Eigen::MatrixXf
【发布时间】:2019-05-14 15:16:50
【问题描述】:

由于某种原因,每当我尝试将使用 OpenCV 导入的图像转换为特征矩阵时,都会出现以下错误:

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'

我假设这是因为我错误地将图像导入为错误的数据类型。谁能提供一些关于如何在两个图书馆之间正确转换的见解?请,谢谢!

#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);

【问题讨论】:

  • 我认为在调用cv2eigen() 之前,您需要确保img 的类型为CV_32FC1,但我不知道您的图像phantom.tif 是什么类型。

标签: c++ opencv eigen tiff


【解决方案1】:

如果有人好奇,我可以通过运行它来让它工作:

//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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-08
    • 1970-01-01
    • 2017-10-26
    • 1970-01-01
    相关资源
    最近更新 更多