/*************************************************** Author : Sukul Bagai, Shubheksha Jalan ***************************************************/ #include #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/opencv.hpp" #include using namespace cv; using namespace std; extern "C" { #include "api_scilab.h" #include "Scierror.h" #include "BOOL.h" #include #include "../common.h" int opencv_undistort(char *fname, unsigned long fname_len) { SciErr sciErr; int iRows=0,iCols=0; int *piAddr2 = NULL; int *piAddr3 = NULL; int *piAddr4 = NULL; int *piAddr5 = NULL; int i,j,k; double cameraMatrix [3][3], newCameraMatrix [3][3]; double *temp = NULL; //checking input argument CheckInputArgument(pvApiCtx, 4, 4); CheckOutputArgument(pvApiCtx, 1, 1) ; Mat image; retrieveImage(image, 1); //for camera matrix sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &temp); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } for(i=0;i<3;i++) for(j=0;j<3;j++) cameraMatrix[i][j]=temp[(j*3)+i]; Mat cameraMat(3,3,CV_64F,&cameraMatrix); //for array of coefficients sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3); if (sciErr.iErr) { printError(&sciErr, 0); return 0; } sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols, &temp); if(sciErr.iErr) { printError(&sciErr, 0); return 0; } int n; if(iRows==1) n=iCols; else n=iRows; double distCoeffs[n]; for(i=0;i