% X_1,X_2 ... 3D points
% omc_1,Tc_1, ... camera positions and orientations
% fc,cc,kc,alpha_c camera intrinsic parameters

[x_reproj] = project_points2(X_1,omc_1,Tc_1,fc,cc,kc,alpha_c);
err_reproj = x_1 - x_reproj;
rms = sum(sum(err_reproj .* err_reproj));

[x_reproj] = project_points2(X_2,omc_2,Tc_2,fc,cc,kc,alpha_c);
err_reproj = x_2 - x_reproj;
rms = rms + sum(sum(err_reproj .* err_reproj));

[x_reproj] = project_points2(X_3,omc_3,Tc_3,fc,cc,kc,alpha_c);
err_reproj = x_3 - x_reproj;
rms = rms + sum(sum(err_reproj .* err_reproj));

[x_reproj] = project_points2(X_4,omc_4,Tc_4,fc,cc,kc,alpha_c);
err_reproj = x_4 - x_reproj;
rms = rms + sum(sum(err_reproj .* err_reproj));

rms = sqrt(rms / (48*4));
fprintf(1, 'Calibration Error: RMS = %3.6f\n', rms);

