function [t1,t2] = estimateUncalibratedRectification(...
  f,matched_points1,matched_points2,imageSize)
% Compute rectification transformations for uncalibrated stereo camera.
%   This function supports code generation. 

% Copyright 2010 The MathWorks, Inc.
% $Revision: 1.1.6.3 $  $Date: 2011/04/02 01:31:13 $
%#codegen

if eml_ambiguous_types
  t1 = zeros(3);
  t2 = zeros(3);
  return;
end

eml_prefer_const(f, matched_points1, matched_points2, imageSize);

%--------------------------------------------------------------------------
% Check the inputs.
%--------------------------------------------------------------------------
coder.extrinsic('cvstGetCoordsChoice');
isXY = eml_const(cvstGetCoordsChoice('fcnEstimateUncalibratedRectification'));

checkInputs(f, matched_points1, matched_points2, imageSize, isXY);

%--------------------------------------------------------------------------
% Compute the projective transformations.
%--------------------------------------------------------------------------
[t1, t2] = cvalgEstimateUncalibratedRectification(...
  f, matched_points1, matched_points2, imageSize, isXY);

%==========================================================================
function checkInputs(f, matched_points1, matched_points2, imageSize, isXY)
%--------------------------------------------------------------------------
% Check the Fundamental matrix
%--------------------------------------------------------------------------
eml_lib_assert(isfloat(f) && isreal(f) && ~issparse(f), ...
  'vision:estimateUncalibratedRectification:invalidFType', ...
  'Expected F to be floating point, real, and nonsparse.');

eml_lib_assert(ndims(f) == 2 && size(f, 1) == 3 && size(f, 2) == 3, ...
  'vision:estimateUncalibratedRectification:invalidFSize', ...
  'Expected F to be a 3-by-3 matrix.');

%--------------------------------------------------------------------------
% Check the image size
%--------------------------------------------------------------------------
eml_lib_assert(isinteger(imageSize) || isfloat(imageSize), ...
  'vision:estimateUncalibratedRectification:invalidImageSizeClass', ...
  'Expected IMAGESIZE to be double, single, or integer.');

eml_lib_assert(isreal(imageSize) && ~issparse(imageSize), ...
  'vision:estimateUncalibratedRectification:invalidImageSizeType', ...
  'Expected IMAGESIZE to be real and nonsparse.');

eml_lib_assert(isvector(imageSize) && numel(imageSize) >= 2, ...
  'vision:estimateUncalibratedRectification:invalidImageSizeSize', ...
  'Expected IMAGESIZE to be a vector of two or more elements.');

eml_lib_assert(all(all(imageSize == floor(imageSize))) ...
  && all(all(imageSize > 0)), ...
  'vision:estimateUncalibratedRectification:invalidImageSizeValue', ...
  'Expected IMAGESIZE to have positive integer values.');

%--------------------------------------------------------------------------
% Check the points
%--------------------------------------------------------------------------
checkPts(matched_points1, isXY);
checkPts(matched_points2, isXY);

if isXY
  eml_lib_assert(size(matched_points1, 1) == size(matched_points2, 1), ...
    'vision:estimateUncalibratedRectification:invalidPtsNumCol', ...
    ['Expected MATCHED_POINTS1 and MATCHED_POINTS2 to have the same '...
    'number of rows.']);
else
  eml_lib_assert(size(matched_points1, 2) == size(matched_points2, 2), ...
    'vision:estimateUncalibratedRectification:invalidPtsNumCol', ...
    ['Expected MATCHED_POINTS1 and MATCHED_POINTS2 to have the same '...
    'number of columns.']);
end
%==========================================================================
function checkPts(value, isXY)
eml_lib_assert(isfloat(value) || isinteger(value), ...
  'vision:estimateUncalibratedRectification:invalidPtsClass', ...
  ['Expected MATCHED_POINTS1 and MATCHED_POINTS2 to be double, single, '...
  'or integer.']);

eml_lib_assert(isreal(value) && ~issparse(value), ...
  'vision:estimateUncalibratedRectification:invalidPtsType', ...
  'Expected MATCHED_POINTS1 and MATCHED_POINTS2 to be real and nonsparse.');

if isXY
  eml_lib_assert(ndims(value)==2 && size(value,1)>0 && size(value,2)==2,...
    'vision:estimateUncalibratedRectification:invalidPtsSize', ...
    'Expected MATCHED_POINTS1 and MATCHED_POINTS2 to be M-by-2 matrices.');
else
  eml_lib_assert(ndims(value)==2 && size(value,1)==2 && size(value,2)>0,...
    'vision:estimateUncalibratedRectification:invalidPtsSize', ...
    'Expected MATCHED_POINTS1 and MATCHED_POINTS2 to be 2-by-N matrices.');
end
