From a6df67e8bcd5159cde27556f4f6a315f8dc2215f Mon Sep 17 00:00:00 2001 From: shamikam Date: Mon, 16 Jan 2017 02:56:17 +0530 Subject: First Commit --- sci_gateway/cpp/opencv_imwrite.cpp | 85 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 sci_gateway/cpp/opencv_imwrite.cpp (limited to 'sci_gateway/cpp/opencv_imwrite.cpp') diff --git a/sci_gateway/cpp/opencv_imwrite.cpp b/sci_gateway/cpp/opencv_imwrite.cpp new file mode 100644 index 0000000..2815ac9 --- /dev/null +++ b/sci_gateway/cpp/opencv_imwrite.cpp @@ -0,0 +1,85 @@ +/******************************************************** +Author: Sukul Bagai +********************************************************/ + +#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_imwrite(char *fname, unsigned long fname_len) + { + + SciErr sciErr; + int iRows=0,iCols=0; + int *piAddr = NULL; + int *piAddr1 = NULL; + int *piLen = NULL; + char **pstData=NULL; + int i,j,k; + + //checking input argument + CheckInputArgument(pvApiCtx, 2, 2); + //CheckOutputArgument(pvApiCtx, 0, 0) ; + Mat image; + retrieveImage(image, 1); + + //Now, retriving path + sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr1); + if (sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + //first call to retrieve dimensions + sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows, &iCols, NULL, NULL); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + piLen = (int*)malloc(sizeof(int) * iRows * iCols); + //second call to retrieve length of each string + sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows, &iCols, piLen, NULL); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + pstData = (char**)malloc(sizeof(char*) * iRows * iCols); + for(int i = 0 ; i < iRows * iCols ; i++) + { + pstData[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination + } + //third call to retrieve data + sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows, &iCols, piLen, pstData); + if(sciErr.iErr) + { + printError(&sciErr, 0); + return 0; + } + + //image path will contain the path where the image has to be written + string image_path=pstData[0]; + + // image_path="\""+image_path+"\""; + + //writes to the path + imwrite(image_path,image); + + return 0; + } +/* ==================================================================== */ +} -- cgit