diff options
author | shamikam | 2017-01-16 02:56:17 +0530 |
---|---|---|
committer | shamikam | 2017-01-16 02:56:17 +0530 |
commit | a6df67e8bcd5159cde27556f4f6a315f8dc2215f (patch) | |
tree | e806e966b06a53388fb300d89534354b222c2cad /sci_gateway/cpp/opencv_xyz2double.cpp | |
download | FOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.tar.gz FOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.tar.bz2 FOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.zip |
Diffstat (limited to 'sci_gateway/cpp/opencv_xyz2double.cpp')
-rw-r--r-- | sci_gateway/cpp/opencv_xyz2double.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/sci_gateway/cpp/opencv_xyz2double.cpp b/sci_gateway/cpp/opencv_xyz2double.cpp new file mode 100644 index 0000000..3d82a7d --- /dev/null +++ b/sci_gateway/cpp/opencv_xyz2double.cpp @@ -0,0 +1,159 @@ +/* Function-xyz2double +Author :Tess Zacharias */ +#include <numeric> +#include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" +#include "opencv2/opencv.hpp" +#include <iostream> +#include<stdio.h> +#include <sciprint.h> +#include<string.h> +#include<math.h> +using namespace cv; +using namespace std; + extern "C" + { + #include "api_scilab.h" + #include "Scierror.h" + #include "BOOL.h" + #include <localization.h> + // #include "../common.h" + #define REF_X .95047; // Observer= 2°, Illuminant= D65 +#define REF_Y 1.00000; +#define REF_Z 1.08883; + + +int opencv_xyz2double(char *fname, unsigned long fname_len) +{ + // Error management variable + SciErr sciErr; + //variable info + int iRows = 0; + int iCols = 0; + int piRows = 0; + int piCols = 0; + int* piAddr=NULL; + int* piAddr1=NULL; + int* piAddr3=NULL; + double *value=NULL; + int* piLen = NULL; + char **val; + int i,j; + int error; + + double check; + Mat img,dst; + float X,Y,Z; + int *piAddrNew = NULL; + //checking output argument + CheckOutputArgument(pvApiCtx,1,1); + //checking if number of input arguments are 3 + + int k=0; + // SciErr getMatrixOfDoubleInList(void* _pvCtx, int* _piParent, int _iItemPos, int* _piRows, int* _piCols, double** _pdblReal) + double *pstDataR = NULL; + double *pstDataG = NULL; + double *pstDataB = NULL; + sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + //retrive the matrix of the R values + sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + //retrive address of the list + sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + //retrive the matrix of the G values + sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + //retrive address of the list + sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + //retrive the matrix of the B values + sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + double *r1,*g1,*b1; + r1=(double *)malloc(sizeof(double)*iRows*iCols); + g1=(double *)malloc(sizeof(double)*iRows*iCols); + b1=(double *)malloc(sizeof(double)*iRows*iCols); + for(int i=0;i<iRows;i++) + { + for(int j=0;j<iCols;j++) + { + // Vec3d intensity = img.at<Vec3d>(i,j); + X= (pstDataR[k]); + Y= (pstDataG[k]); + Z= (pstDataB[k++]); + r1[j*iRows+i]=X; + g1[j*iRows+i]=Y; + b1[j*iRows+i]=Z; + } + } + + sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + + //Adding the R value matrix to the list + //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData) + sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1); + free(r1); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + //Adding the G value matrix to the list + sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1); + free(g1); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + //Adding the B value matrix to the list + sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1); + free(b1); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; +} +} + |