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?

 Risposta accettata

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)};

Più risposte (0)

Categorie

Scopri di più su MATLAB Support Package for USB Webcams in Centro assistenza e File Exchange

Prodotti

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by