How do I generate code for 'rectifyStereoImages' functionality to rectify stereo camera images?

I have 2 images ('img1' and 'img2'), and have a variable called 'stereoParameters' that contains the Stereo Parameters. that I have generated by calibrating my stereo camera.
I run the following function without a problem:
>> [J1,J2] = rectifyStereoImages(img1,img2,stereoParameters)
I would like to generate C code for the same. When I tried to generate code with the 'codegen' function, I keep getting the following error:
>> codegen rectifyStereoImages -args {coder.typeof(img1), coder.typeof(img2), coder.typeof(stereoParameters)};
??? Not enough input arguments. Error in ==> rectifyStereoImages Line: 112 Column: 5 Code generation failed: View Error Report Error using codegen
Why do I see this error? How do I generate code that can rectify images?

 Accepted Answer

MATLAB coder does not support the passing of the 'stereoParameters' object as an argument into a function. I recommend you pass the information in as a struct, and then create the 'stereoParameters' object inside the function, as suggested in the link below:
The workflow is to:
1) Set up a function that accepts structs as an argument, and generates the 'stereoParams' within.
2) You can then pass this generated 'stereoParams' into the rectifyStereoImages function.
3) I also recommend setting up the 'stereoParams' to be a persistent variable, so it is not generated with each instance of the function being called:
Thus , please create the following function:
% Input Arguments would be image matrices and a struct
function [a,b]= img_rec(img1,img2,stereoParamStruct)
persistent stereoParams
if isempty(stereoParams)
% Create the stereoParams object using the input struct
stereoParams = stereoParameters(stereoParamStruct);
end
% Now that the object is created, you can run 'rectifyStereoImages'
[a,b]=rectifyStereoImages(img1, img2, stereoParams);
end
You can use the commands listed below at the MATLAB command prompt to generate embeddable code.
>> params_str = toStruct(stereoParameters)
>> codegen img_rec -args {coder.typeof(img1), coder.typeof(img2), coder.typeof(params_str)};

More Answers (0)

Categories

Find more on MATLAB Support Package for USB Webcams in Help Center and File Exchange

Products

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!