使用 MATLAB 编码器将代码从注册估算器应用程序导出到C++
Using MATLAB coder to export code from Registration Estimator app to C++
嗨,我正在尝试导出从 MATLAB 中的注册估算器应用程序自动生成的"默认代码",以使用 MATLAB Coder
工具进行C++。
这是我今天生成的示例代码:
function [MOVINGREG] = registerImages(MOVING,FIXED)
%registerImages Register grayscale images using auto-generated code from Registration Estimator app.
% [MOVINGREG] = registerImages(MOVING,FIXED) Register grayscale images
% MOVING and FIXED using auto-generated code from the Registration
% Estimator App. The values for all registration parameters were set
% interactively in the App and result in the registered image stored in the
% structure array MOVINGREG.
% Auto-generated by registrationEstimator app on 21-Jun-2017
%-----------------------------------------------------------
% Convert RGB images to grayscale
FIXED = rgb2gray(FIXED);
MOVING = rgb2gray(MOVING);
% Default spatial referencing objects
fixedRefObj = imref2d(size(FIXED));
movingRefObj = imref2d(size(MOVING));
% Intensity-based registration
[optimizer, metric] = imregconfig('monomodal');
optimizer.GradientMagnitudeTolerance = 1.00000e-04;
optimizer.MinimumStepLength = 1.00000e-05;
optimizer.MaximumStepLength = 6.25000e-02;
optimizer.MaximumIterations = 100;
optimizer.RelaxationFactor = 0.500000;
% Align centers
fixedCenterXWorld = mean(fixedRefObj.XWorldLimits);
fixedCenterYWorld = mean(fixedRefObj.YWorldLimits);
movingCenterXWorld = mean(movingRefObj.XWorldLimits);
movingCenterYWorld = mean(movingRefObj.YWorldLimits);
translationX = fixedCenterXWorld - movingCenterXWorld;
translationY = fixedCenterYWorld - movingCenterYWorld;
% Coarse alignment
initTform = affine2d();
initTform.T(3,1:2) = [translationX, translationY];
% Apply transformation
tform = imregtform(MOVING,movingRefObj,FIXED,fixedRefObj,'similarity',optimizer,metric,'PyramidLevels',3,'InitialTransformation',initTform);
MOVINGREG.Transformation = tform;
MOVINGREG.RegisteredImage = imwarp(MOVING, movingRefObj, tform, 'OutputView', fixedRefObj, 'SmoothEdges', true);
% Store spatial referencing object
MOVINGREG.SpatialRefObj = fixedRefObj;
end
在第 Run-Time Issues
节的编码器工具中,我收到了几个问题,例如,编码人员需要声明外部函数。目前为止,一切都好。例如,我添加了:coder.extrinsic('imregconfig');
和coder.extrinsic('optimizer');
。但我仍然收到以下错误:
尝试从"mxArray"中提取字段"梯度幅度容差"。
尝试从"mxArray"中提取字段"最小步长"。
尝试从"mxArray"中提取字段"最大步长"。
。
指向带有 optimizer.GradientMagnitudeTolerance = 1.00000e-04;
(及下方(的行。
我发现通常缺少变量的初始化。但是我不知道如何提前初始化属性optimizer.GradientMagnitudeTolerance
。谁能帮我解决这个问题?
PS:我正在使用MATLAB R2017a
和Microsoft Visual C++ 2017 (C)
编译器
根据 https://www.mathworks.com/help/coder/ug/functions-supported-for-code-generation--categorical-list.html#bsl0arh-1 中代码生成支持的函数列表,代码生成不支持 imregconfig。这解释了您首先遇到的问题。添加 coder.extrinsic 意味着 MATLAB Coder 生成的文件将调用 MATLAB 来运行该函数。您只能对需要 MATLAB 运行的 mex 目标执行此操作。imregconfig 不会生成任何 C 代码。使用此代码无法生成从外部应用程序使用的独立 C 代码。
当声明为 coder.extrinsic 的函数调用 MATLAB 时,它们会返回一个 mxArray。代码的其余部分只能通过将其传递给 MATLAB(即类似的外部函数(来处理此 mxArray。从Coder的角度来看,这些是不透明的类型,因此尝试从mxArray中提取字段时会出现错误。
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 码头化的C++应用程序是否向后兼容早期的内核版本
- 将应用程序从32位移植到64位时出现问题
- 如何改变c++应用程序的视觉效果
- WM_CTLCOLORSTATIC从未在WIN32应用程序中触发
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 应用程序崩溃并显示"symbol _ZdlPvm, version Qt_5 not defined in file libQt5Core.so.5 with link time reference"
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- phytec phyBOARD iMX-6在从闪存而不是SD卡运行qt5 opengles应用程序时表现不佳(FPS减半
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 如何从Windows应用程序输出到标准?
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- 如何在 64 位 vb.net Windows 应用程序中引用 32 位 dll
- 如果整个应用程序是虚拟映射的,为什么 new 会进行系统调用?