嗨我試圖導出使用MATLAB Coder
工具從MATLAB中的註冊估算器應用程序自動生成的「默認代碼」爲C++。使用MATLAB編碼器將代碼從註冊估算器應用程序導出到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
在編碼器工具,我收到了幾個問題,例如該編碼器需要declare the extrinsic。到現在爲止還挺好。我加了例如:coder.extrinsic('imregconfig');
和coder.extrinsic('optimizer');
。但我仍然收到如下錯誤:
嘗試從'mxArray'中提取字段'GradientMagnitudeTolerance'。
嘗試從'mxArray'中提取字段'MinimumStepLength'。
嘗試從'mxArray'中提取字段'MaximumStepLength'。
...
指着符合optimizer.GradientMagnitudeTolerance = 1.00000e-04;
(和下文)。
我發現通常變量的初始化是缺失的。但我不知道如何在高級中初始化屬性optimizer.GradientMagnitudeTolerance
。誰能幫我這個?
PS:我使用MATLAB R2017a
和Microsoft Visual C++ 2017 (C)
編譯
嗯這是不好的:/你建議任何其他方式來使用這個代碼「outsite」的matlab IDE? – user1234
你可以試試MATLAB編譯器來編譯這段代碼並創建一個獨立的可執行文件。那會在MATLAB之外運行。 – Navan