如何转换a'mat。将cv :: mat; s" s&quote;在“ OpenCvmex.hpp”中使用API。由Matlab提供
我尝试读取由Matlaband创建的“ .mat”文件中的数据,将保存在“ .mat”中的矩阵转换为OpenCV的“ cv :: mat”格式。也就是说,首先打开“ .mat”文件,然后使用mxarrar
使用mat.h
键入数据,然后使用MATLAB提供的API转换,该API在<<<<<代码> opencvmex.h 文件。
我已经清楚地完成了该过程,现在我成功地获得了mxarray
。但是,当我尝试将mxarray
转换为cv :: mat
时,问题就会发生,并指出该函数是无可避免的。代码如下:
//#include <torch/script.h> // One-stop header.
//
//#include <iostream>
//#include <memory>
#include<stdlib.h>
#define MATLAB_MEX_FILE
#include <mat.h>
#include <opencvmex.hpp>
//#include <opencv2/highgui.hpp>
int main(int argc, const char* argv[]){
// Load mat file as model's input
MATFile* pmatFile = NULL;
mxArray* pMxArray = NULL;
// Open mat file with given API
pmatFile = matOpen("image.mat", "r");
// Read mat from .mat file with Name(Here "I" in mat file)
pMxArray = matGetVariable(pmatFile, "I");
// Varible to save mat read from mat file
cv::Mat image_from_mat;
// Convert from mxArray to cv::Mat
ocvMxArrayToMat_double(pMxArray, &image_from_mat);
// Varible to save mat read from mat file
//cv::Ptr<cv::Mat> image_from_mat = ocvMxArrayToMat_double(pMxArray);
// Convert from mxArray to cv::Mat
//auto img_tensor = torch::CPU(torch::kFloat32).tensorFromBlob(pMxArray, { 1, 224, 224, 3 });
return 0;
}
此错误是
LNK2019 unresolved external symbol "struct cv::Ptr<class cv::Mat> __cdecl ocvMxArrayToMat_double(struct mxArray_tag const *,bool)" (?ocvMxArrayToMat_double@@YA?AU?$Ptr@VMat@cv@@@cv@@PEBUmxArray_tag@@_N@Z),The symbol is referenced in the function `main` Load_Mat_Cpp C:\Users\Dalek\Documents\Private\UCAS_SIA\CPP_Reconstruction\Load_Mat_Cpp\main.obj
在VS2019中配置的,并且Prop文件的内容如下:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>C:\tools\opencv\build\include\opencv2;C:\tools\opencv\build\include;C:\Program Files\Polyspace\R2021a\extern\include;C:\tools\libtorch\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\tools\opencv\build\x64\vc15\lib;C:\Program Files\Polyspace\R2021a\extern\lib\win64\microsoft;C:\tools\libtorch\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>asmjit.lib;c10.lib;caffe2_module_test_dynamic.lib;clog.lib;cpuinfo.lib;fbgemm.lib;libprotobufd.lib;libprotobuf-lited.lib;libprotocd.lib;mkldnn.lib;torch_cpu.lib;torch.lib;libmat.lib;libmx.lib;libmex.lib;libeng.lib;opencv_world3413.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
所有路径和依赖关系已仔细检查并应还算不错,也可以在path 已经很好地添加了。
为什么会发生此错误,如何将.mat文件转换为cv :: mat格式?
I tried to read data from ".mat" file created by MATLABand convert a matrix saved in ".mat" to opencv's "cv::Mat" format. That is, firstly open the ".mat" file and get the mxArrar
type data using mat.h
and then convert with the API provided by MATLAB, which is defined in opencvmex.h
file.
I've made the process above clearly, and now I've obtained the mxArray
successfully. However, when I tried to convert the mxArray
to cv::Mat
, the problem occurred and it stated that the function is unparsable. The code is as below:
//#include <torch/script.h> // One-stop header.
//
//#include <iostream>
//#include <memory>
#include<stdlib.h>
#define MATLAB_MEX_FILE
#include <mat.h>
#include <opencvmex.hpp>
//#include <opencv2/highgui.hpp>
int main(int argc, const char* argv[]){
// Load mat file as model's input
MATFile* pmatFile = NULL;
mxArray* pMxArray = NULL;
// Open mat file with given API
pmatFile = matOpen("image.mat", "r");
// Read mat from .mat file with Name(Here "I" in mat file)
pMxArray = matGetVariable(pmatFile, "I");
// Varible to save mat read from mat file
cv::Mat image_from_mat;
// Convert from mxArray to cv::Mat
ocvMxArrayToMat_double(pMxArray, &image_from_mat);
// Varible to save mat read from mat file
//cv::Ptr<cv::Mat> image_from_mat = ocvMxArrayToMat_double(pMxArray);
// Convert from mxArray to cv::Mat
//auto img_tensor = torch::CPU(torch::kFloat32).tensorFromBlob(pMxArray, { 1, 224, 224, 3 });
return 0;
}
This error is thrown
LNK2019 unresolved external symbol "struct cv::Ptr<class cv::Mat> __cdecl ocvMxArrayToMat_double(struct mxArray_tag const *,bool)" (?ocvMxArrayToMat_double@@YA?AU?$Ptr@VMat@cv@@@cv@@PEBUmxArray_tag@@_N@Z),The symbol is referenced in the function `main` Load_Mat_Cpp C:\Users\Dalek\Documents\Private\UCAS_SIA\CPP_Reconstruction\Load_Mat_Cpp\main.obj
The project is configured in VS2019 and the prop file has content below:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>C:\tools\opencv\build\include\opencv2;C:\tools\opencv\build\include;C:\Program Files\Polyspace\R2021a\extern\include;C:\tools\libtorch\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<AdditionalLibraryDirectories>C:\tools\opencv\build\x64\vc15\lib;C:\Program Files\Polyspace\R2021a\extern\lib\win64\microsoft;C:\tools\libtorch\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>asmjit.lib;c10.lib;caffe2_module_test_dynamic.lib;clog.lib;cpuinfo.lib;fbgemm.lib;libprotobufd.lib;libprotobuf-lited.lib;libprotocd.lib;mkldnn.lib;torch_cpu.lib;torch.lib;libmat.lib;libmx.lib;libmex.lib;libeng.lib;opencv_world3413.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
All the path and dependencies has been checked carefully and should be alright, also the environment variable in Path
has been well added.
Why does this error occur and how can I convert a .mat file to cv::Mat format?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论