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_gateway1/cpp/opencv_FFT.cpp | |
download | FOSSEE_Image_Processing_Toolbox-master.tar.gz FOSSEE_Image_Processing_Toolbox-master.tar.bz2 FOSSEE_Image_Processing_Toolbox-master.zip |
Diffstat (limited to 'sci_gateway1/cpp/opencv_FFT.cpp')
-rw-r--r-- | sci_gateway1/cpp/opencv_FFT.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/sci_gateway1/cpp/opencv_FFT.cpp b/sci_gateway1/cpp/opencv_FFT.cpp new file mode 100644 index 0000000..1ac386e --- /dev/null +++ b/sci_gateway1/cpp/opencv_FFT.cpp @@ -0,0 +1,89 @@ +/**************************************** +Author: Sridhar Reddy +*****************************************/ +#include <numeric> +#include "opencv2/core/core.hpp" +#include "opencv2/highgui/highgui.hpp" +#include "opencv2/opencv.hpp" +#include <iostream> +using namespace cv; +using namespace std; +extern "C" +{ + #include "api_scilab.h" + #include "Scierror.h" + #include "BOOL.h" + #include <localization.h> + #include "sciprint.h" + #include "../common.h" + + int opencv_fftnew(char *fname, unsigned long fname_len) + { + SciErr sciErr; + int intErr=0; + int iRows=0,iCols=0,i,j; + int *piAddr1=NULL; + double *ipReal=NULL; + double *ipImg=NULL; + double *rsltReal=NULL; + double *rsltImg=NULL; + vector<complex<double> > vec_out; + vector<double> vec_in; + + CheckInputArgument(pvApiCtx, 1, 1); + CheckOutputArgument(pvApiCtx, 1, 1) ; + + sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols, &ipReal); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + ipImg = (double*)malloc(sizeof(double) * iRows * iCols); + if(iRows==1){ + for(i = 0 ; i <iCols ; i++) + vec_in.push_back(ipReal[i]); + dft(vec_in,vec_out, DFT_COMPLEX_OUTPUT); + for(i = 0 ; i < iCols ; i++){ + ipReal[i]=real(vec_out[i]); + ipImg[i]=imag(vec_out[i]); + } + vec_in.clear(); + vec_out.clear(); + + } + else{ + for(i = 0 ; i < iCols ; i++){ + for(j = 0 ; j < iRows ; j++) + vec_in.push_back(ipReal[j+iCols*i]); + dft(vec_in,vec_out,DFT_COMPLEX_OUTPUT); + for(j = 0 ; j < iRows ; j++){ + ipReal[j+iCols*i]=real(vec_out[j]); + ipImg[j+iCols*i]=imag(vec_out[j]); + } + vec_in.clear(); + vec_out.clear(); + } + } + sciErr = allocComplexMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, &rsltReal, &rsltImg); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + for(i = 0 ; i < iRows * iCols; i++) + { + rsltReal[i]=ipReal[i]; + rsltImg[i]=ipImg[i]; + } + AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1; + ReturnArguments(pvApiCtx); + return 0; + } +} |