1.环境的说明
matlab 2021a
qt 5.12.10
qt creator 4.13.1
opencv 4.3.0
eigen-3.4.0/eigen-3.4.0
2.matlab 中导出dill
以aberr_analy1的导出dill举例
-
命令行中输入:deploytool
2. 选择LIbrarycompiler
3type 选择c++
4,选择相应的
5. 点击package 选择保存的路径即可
6.导出后:
只需要 下面这个文件里面的dll .h 和。Lib 文件
3.qt 端 的环境配置
1.opencv +eigen-3.4.0+matlab + 导出的lib 和include 的路径
win32:CONFIG(release, debug|release): LIBS += -LD:/my_software/opencv/opencv/newbuil_with_contrib/x64/vc15/lib/ -lopencv_world453
else:win32:CONFIG(debug, debug|release): LIBS += -LD:/my_software/opencv/opencv/newbuil_with_contrib/x64/vc15/lib/ -lopencv_world453d
INCLUDEPATH +=D:/my_software/opencv/opencv/newbuil_with_contrib/include
DEPENDPATH += D:/my_software/opencv/opencv/newbuil_with_contrib/include/opencv2
INCLUDEPATH += E:/my_software/eigen-3.4.0/eigen-3.4.0
win32: LIBS += -L$$PWD/include/ -lmatAdd
win32: LIBS += -L$$PWD/include/ -lfringe_process
win32: LIBS += -L$$PWD/include/ -lcalculatephase
win32: LIBS += -L$$PWD/include/ -ltest_FWLSI_FUNC4
win32: LIBS += -L$$PWD/include/ -laberr_analy1
win32: LIBS += -L$$PWD/include/ -laberr_analy2
INCLUDEPATH += $$PWD/include
DEPENDPATH += $$PWD/include
# .h文件搜索路径
INCLUDEPATH +=D:/my_software/matlab/extern/include
INCLUDEPATH += D:/my_software/matlab/extern/include/Win64
# 用到的MATLAB 的.lib库文件 及其搜索路径
INCLUDEPATH += D:/my_software/matlab/extern/lib/win64/microsoft
DEPENDPATH += D:/my_software/matlab/extern/lib/win64/microsoft
win32: LIBS += -LD:/my_software/matlab/extern/lib/win64/microsoft/ -llibmex
win32: LIBS += -LD:/my_software/matlab/extern/lib/win64/microsoft/ -llibmx
win32: LIBS += -LD:/my_software/matlab/extern/lib/win64/microsoft/ -llibmat
win32: LIBS += -LD:/my_software/matlab/extern/lib/win64/microsoft/ -llibeng
win32: LIBS += -LD:/my_software/matlab/extern/lib/win64/microsoft/ -lmclmcr
win32: LIBS += -LD:/my_software/matlab/extern/lib/win64/microsoft/ -lmclmcrrt
在项目目录中新建了一个include 文件,放导出的include 和lib 文件
项目的运行文件
release /debug 下面放dill
4qt 中的相关运行代码示例
先写导入.h
mwArray 重点在于 mwArray 的声明
void MainWindow::dill_demo1( )
{
// img_in.convertTo(img_in, CV_32F);
// cv::Mat img_ini=ganshe_matlabe.fringe_process(img_in);
if (!matAddInitialize()) //DLL 初始化
{
return;
}
double vectA[]={1,2,3}; //向量A
double vectB[]={5,6,7}; //向量B
int rowCnt=1; //行数
int colCnt=3; //列数
int elementCnt=3; //元素个数
mwArray matrixA(rowCnt,colCnt,mxDOUBLE_CLASS, mxREAL);//定义数组
matrixA.SetData(vectA,elementCnt); //将C++ 的一维数组存储到 MATLAB的二维数组
mwArray matrixB(rowCnt,colCnt,mxDOUBLE_CLASS, mxREAL);//定义数组
matrixB.SetData(vectB,elementCnt); //
//计算
mwArray matrixC(rowCnt,colCnt,mxDOUBLE_CLASS, mxREAL);//定义数组,double类型
int nargout=1;//输出变量个数
matAdd(nargout,matrixC,matrixA,matrixB);//C=A+B
int dim=2; //按照二维数组读出matrixC
double av=matrixC.Get(dim,1,1); //第1行,第1列
double bv=matrixC.Get(dim,1,2);// 第1行,第2列
double cv=matrixC.Get(dim,1,3); // 第1行,第3列
QString str=QString::asprintf("%.0f, %.0f, %.0f", av,bv,cv);
qDebug()<<"str"<<str;
}
1二维图像 中 mwArray 的声明方式
mwArray I_in2(2, dims2, mxDOUBLE_CLASS, mxREAL);
cv::Mat image_test = cv::imread("E:/my_self_progect/image/expame/512X512.jpg",
cv::IMREAD_GRAYSCALE);
if (!calculatephaseInitialize()) //DLL 初始化
{
std::cerr << "Could not initialize the fringe_process properly" << std::endl;
return;
}
if(!image_test.empty())
{
// Convert cv::Mat to mwArray
mwSize dims2[2] = {static_cast<mwSize>(image_test.rows), static_cast<mwSize>(image_test.cols)};
mwArray I_in2(2, dims2, mxDOUBLE_CLASS, mxREAL);
for (int i = 0; i < image_test.rows; ++i)
{ for (int j = 0; j < image_test.cols; ++j)
{
I_in2(i + 1, j + 1) = static_cast<double>(image_test.at<uchar>(i, j));
}
}
}