summaryrefslogtreecommitdiff
path: root/sci_gateway1/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sci_gateway1/cpp')
-rw-r--r--sci_gateway1/cpp/builder_gateway_cpp.sce312
-rw-r--r--sci_gateway1/cpp/builder_gateway_cpp.sce~312
-rw-r--r--sci_gateway1/cpp/cleaner.sce22
-rw-r--r--sci_gateway1/cpp/common.cpp890
-rw-r--r--sci_gateway1/cpp/common.cpp~924
-rw-r--r--sci_gateway1/cpp/common.h9
-rw-r--r--sci_gateway1/cpp/common.h~10
-rw-r--r--sci_gateway1/cpp/common1.cpp897
-rw-r--r--sci_gateway1/cpp/common2.cpp2527
-rw-r--r--sci_gateway1/cpp/common3.cpp925
-rw-r--r--sci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.c30
-rwxr-xr-xsci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.sobin0 -> 51031 bytes
-rw-r--r--sci_gateway1/cpp/libskeleton_imageprocessing.c38
-rwxr-xr-xsci_gateway1/cpp/libskeleton_imageprocessing.sobin0 -> 67073 bytes
-rw-r--r--sci_gateway1/cpp/loader.sce25
-rw-r--r--sci_gateway1/cpp/opencv_BRISKPoints.cpp113
-rw-r--r--sci_gateway1/cpp/opencv_BlockMatcher.cpp606
-rw-r--r--sci_gateway1/cpp/opencv_CascadeObjectDetector.cpp431
-rw-r--r--sci_gateway1/cpp/opencv_DCT.cpp77
-rw-r--r--sci_gateway1/cpp/opencv_Deinterlacer.cpp201
-rw-r--r--sci_gateway1/cpp/opencv_FFT.cpp89
-rw-r--r--sci_gateway1/cpp/opencv_ForegroundDetector.cpp415
-rw-r--r--sci_gateway1/cpp/opencv_GeometricShearer.cpp178
-rw-r--r--sci_gateway1/cpp/opencv_HistogramBasedTracker.cpp257
-rw-r--r--sci_gateway1/cpp/opencv_IDCT.cpp72
-rw-r--r--sci_gateway1/cpp/opencv_IFFT.cpp69
-rw-r--r--sci_gateway1/cpp/opencv_KalmanFilter.cpp690
-rw-r--r--sci_gateway1/cpp/opencv_SURFPoints.cpp123
-rw-r--r--sci_gateway1/cpp/opencv_TemplateMatcher.cpp146
-rw-r--r--sci_gateway1/cpp/opencv_VideoPlayer.cpp78
-rw-r--r--sci_gateway1/cpp/opencv_VideoReader.cpp389
-rw-r--r--sci_gateway1/cpp/opencv_arrowedline.cpp221
-rw-r--r--sci_gateway1/cpp/opencv_bagOfFeatures.cpp550
-rw-r--r--sci_gateway1/cpp/opencv_bbox2points.cpp117
-rw-r--r--sci_gateway1/cpp/opencv_bboxOverlapRatio.cpp275
-rw-r--r--sci_gateway1/cpp/opencv_blobAnalysis.cpp381
-rw-r--r--sci_gateway1/cpp/opencv_blur.cpp134
-rw-r--r--sci_gateway1/cpp/opencv_boundingRect.cpp82
-rw-r--r--sci_gateway1/cpp/opencv_bundleAdjustment.cpp382
-rw-r--r--sci_gateway1/cpp/opencv_cameraMatrix.cpp186
-rw-r--r--sci_gateway1/cpp/opencv_canny.cpp121
-rw-r--r--sci_gateway1/cpp/opencv_circle.cpp203
-rw-r--r--sci_gateway1/cpp/opencv_clipline.cpp149
-rw-r--r--sci_gateway1/cpp/opencv_convexhull.cpp140
-rw-r--r--sci_gateway1/cpp/opencv_convolver.cpp243
-rw-r--r--sci_gateway1/cpp/opencv_copymakeborder.cpp195
-rw-r--r--sci_gateway1/cpp/opencv_corner.cpp469
-rw-r--r--sci_gateway1/cpp/opencv_cornerEigenValsAndVecs.cpp127
-rw-r--r--sci_gateway1/cpp/opencv_cornerHarris.cpp144
-rw-r--r--sci_gateway1/cpp/opencv_cornerMinEigenVal.cpp125
-rw-r--r--sci_gateway1/cpp/opencv_cvtColor.cpp183
-rw-r--r--sci_gateway1/cpp/opencv_demosaic.cpp127
-rw-r--r--sci_gateway1/cpp/opencv_detectBRISKFeatures.cpp421
-rw-r--r--sci_gateway1/cpp/opencv_detectCheckerboardPoints.cpp731
-rw-r--r--sci_gateway1/cpp/opencv_detectFASTFeatures.cpp569
-rw-r--r--sci_gateway1/cpp/opencv_detectHarrisFeatures.cpp402
-rw-r--r--sci_gateway1/cpp/opencv_detectMSERFeatures.cpp451
-rw-r--r--sci_gateway1/cpp/opencv_detectMinEigenFeatures.cpp366
-rw-r--r--sci_gateway1/cpp/opencv_detectSURFFeatures.cpp432
-rw-r--r--sci_gateway1/cpp/opencv_dilate.cpp119
-rw-r--r--sci_gateway1/cpp/opencv_ellipse.cpp278
-rw-r--r--sci_gateway1/cpp/opencv_ellipse2poly.cpp171
-rw-r--r--sci_gateway1/cpp/opencv_epipolarlines.cpp321
-rw-r--r--sci_gateway1/cpp/opencv_erode.cpp117
-rw-r--r--sci_gateway1/cpp/opencv_estimateFundamentalMatrix.cpp318
-rw-r--r--sci_gateway1/cpp/opencv_estimateGeometricTransform.cpp164
-rw-r--r--sci_gateway1/cpp/opencv_estimateUncalibratedRectification.cpp201
-rw-r--r--sci_gateway1/cpp/opencv_evaluate.cpp417
-rw-r--r--sci_gateway1/cpp/opencv_evaluateImageRetrieval.cpp566
-rw-r--r--sci_gateway1/cpp/opencv_extractFeatures.cpp1706
-rw-r--r--sci_gateway1/cpp/opencv_extractHOGFeatures.cpp399
-rw-r--r--sci_gateway1/cpp/opencv_extractLBPFeatures.cpp515
-rw-r--r--sci_gateway1/cpp/opencv_fillconvexpoly.cpp173
-rw-r--r--sci_gateway1/cpp/opencv_filter2D.cpp184
-rw-r--r--sci_gateway1/cpp/opencv_findContours.cpp199
-rw-r--r--sci_gateway1/cpp/opencv_gaussianblur.cpp132
-rw-r--r--sci_gateway1/cpp/opencv_generateCheckerboardPoints.cpp157
-rw-r--r--sci_gateway1/cpp/opencv_getStructuringElement.cpp147
-rw-r--r--sci_gateway1/cpp/opencv_getTextSize.cpp188
-rw-r--r--sci_gateway1/cpp/opencv_getgaussiankernel.cpp142
-rw-r--r--sci_gateway1/cpp/opencv_getrectsubpix.cpp142
-rw-r--r--sci_gateway1/cpp/opencv_getrotationmatrix2D.cpp121
-rw-r--r--sci_gateway1/cpp/opencv_goodfeaturestotrack.cpp168
-rw-r--r--sci_gateway1/cpp/opencv_houghcircles.cpp164
-rw-r--r--sci_gateway1/cpp/opencv_houghlines.cpp133
-rw-r--r--sci_gateway1/cpp/opencv_houghlinesp.cpp134
-rw-r--r--sci_gateway1/cpp/opencv_im2double.cpp56
-rw-r--r--sci_gateway1/cpp/opencv_imageSet.cpp294
-rw-r--r--sci_gateway1/cpp/opencv_imcontrast.cpp100
-rw-r--r--sci_gateway1/cpp/opencv_imcrop.cpp130
-rw-r--r--sci_gateway1/cpp/opencv_imfindcircles.cpp128
-rw-r--r--sci_gateway1/cpp/opencv_imread.cpp99
-rw-r--r--sci_gateway1/cpp/opencv_imread.cpp~99
-rw-r--r--sci_gateway1/cpp/opencv_imresize.cpp94
-rw-r--r--sci_gateway1/cpp/opencv_imsharpen.cpp59
-rw-r--r--sci_gateway1/cpp/opencv_imwrite.cpp85
-rw-r--r--sci_gateway1/cpp/opencv_indexImages.cpp663
-rw-r--r--sci_gateway1/cpp/opencv_integralFilter.cpp250
-rw-r--r--sci_gateway1/cpp/opencv_integralImage.cpp153
-rw-r--r--sci_gateway1/cpp/opencv_integralKernel.cpp251
-rw-r--r--sci_gateway1/cpp/opencv_isEpipoleInImage.cpp164
-rw-r--r--sci_gateway1/cpp/opencv_isfilter.cpp237
-rw-r--r--sci_gateway1/cpp/opencv_laplacian.cpp156
-rw-r--r--sci_gateway1/cpp/opencv_line.cpp211
-rw-r--r--sci_gateway1/cpp/opencv_matchFeatures.cpp490
-rw-r--r--sci_gateway1/cpp/opencv_medianblur.cpp81
-rw-r--r--sci_gateway1/cpp/opencv_montage.cpp216
-rw-r--r--sci_gateway1/cpp/opencv_morphologyEx.cpp232
-rw-r--r--sci_gateway1/cpp/opencv_ocr.cpp175
-rw-r--r--sci_gateway1/cpp/opencv_opticalFlowFarneback.cpp553
-rw-r--r--sci_gateway1/cpp/opencv_partition.cpp488
-rw-r--r--sci_gateway1/cpp/opencv_peopleDetector.cpp468
-rw-r--r--sci_gateway1/cpp/opencv_predict.cpp222
-rw-r--r--sci_gateway1/cpp/opencv_projectPoints.cpp256
-rw-r--r--sci_gateway1/cpp/opencv_puttext.cpp311
-rw-r--r--sci_gateway1/cpp/opencv_pyrDown.cpp156
-rw-r--r--sci_gateway1/cpp/opencv_pyrUp.cpp156
-rw-r--r--sci_gateway1/cpp/opencv_pyramid.cpp134
-rw-r--r--sci_gateway1/cpp/opencv_rectangle.cpp207
-rw-r--r--sci_gateway1/cpp/opencv_rectifyStereoImages.cpp243
-rw-r--r--sci_gateway1/cpp/opencv_retrieveImages.cpp506
-rw-r--r--sci_gateway1/cpp/opencv_rotationVectorToMatrix.cpp205
-rw-r--r--sci_gateway1/cpp/opencv_scharr.cpp155
-rw-r--r--sci_gateway1/cpp/opencv_sepFilter2D.cpp261
-rw-r--r--sci_gateway1/cpp/opencv_showMatchedFeatures.cpp275
-rw-r--r--sci_gateway1/cpp/opencv_sobel.cpp172
-rw-r--r--sci_gateway1/cpp/opencv_threshold.cpp146
-rw-r--r--sci_gateway1/cpp/opencv_trainImageCategoryClassifier.cpp349
-rw-r--r--sci_gateway1/cpp/opencv_triangulatePoints.cpp166
-rw-r--r--sci_gateway1/cpp/opencv_undistort.cpp118
-rw-r--r--sci_gateway1/cpp/opencv_undistortImage.cpp271
-rw-r--r--sci_gateway1/cpp/opencv_undistortPoints.cpp190
-rw-r--r--sci_gateway1/cpp/rotationMatrixToVector.cpp139
133 files changed, 36827 insertions, 0 deletions
diff --git a/sci_gateway1/cpp/builder_gateway_cpp.sce b/sci_gateway1/cpp/builder_gateway_cpp.sce
new file mode 100644
index 0000000..e450af1
--- /dev/null
+++ b/sci_gateway1/cpp/builder_gateway_cpp.sce
@@ -0,0 +1,312 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the BSD.
+// This source file is licensed as described in the file LICENSE, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// https://opensource.org/licenses/BSD-3-Clause
+// Author: Shamika Mohanan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+//mode(-1)
+//lines(0)
+
+//toolbox_title = "FOSSEE_Image_Processing_Toolbox";
+
+//Build_64Bits = %t;
+
+//path_builder = get_absolute_file_path('builder_gateway_cpp.sce');
+
+Function_Names = [
+ "opencv_imread","opencv_imread";
+// //"blur","opencv_blur";
+// //"arrowedline","opencv_arrowedline";
+// //"canny","opencv_canny";
+// //"circle","opencv_circle";
+// //"clipline","opencv_clipline";
+// //"convexhull","opencv_convexhull";
+// //"cornerEigenValsAndVecs","opencv_cornerEigenValsAndVecs";
+// //"cornerHarris","opencv_cornerHarris";
+// //"cornerMinEigenVal","opencv_cornerMinEigenVal";
+// //"dilate","opencv_dilate";
+// //"ellipse2poly","opencv_ellipse2poly";
+// //"erode","opencv_erode";
+// //"fillconvexpoly","opencv_fillconvexpoly";
+// //"filter2D","opencv_filter2D";
+// //"findContours","opencv_findContours";
+// //"gaussianblur","opencv_gaussianblur";
+// //"getStructuringElement","opencv_getStructuringElement";
+// //"getTextSize","opencv_getTextSize";
+// //"goodfeaturestotrack","opencv_goodfeaturestotrack";
+// //"houghcircles","opencv_houghcircles";
+// //"houghlines","opencv_houghlines";
+// //"im2double","opencv_im2double";
+// //"imcontrast","opencv_imcontrast";
+ "opencv_imcrop","opencv_imcrop";
+ "opencv_imresize","opencv_imresize";
+ "opencv_imsharpen","opencv_imsharpen";
+ "opencv_imwrite","opencv_imwrite";
+// //"laplacian","opencv_laplacian";
+// //"line","opencv_line";
+// //"medianblur","opencv_medianblur";
+// //"puttext","opencv_puttext";
+// //"scharr","opencv_scharr";
+// //"sobel","opencv_sobel";
+// //"threshold","opencv_threshold";
+// //"undistort","opencv_undistort";
+// //"boundingRect","opencv_boundingRect";
+// //"ellipse","opencv_ellipse";
+// //"montage","opencv_montage";
+// //"morphologyEx","opencv_morphologyEx";
+// //"pyrDown","opencv_pyrDown";
+// //"pyrUp","opencv_pyrUp";
+// //"rectangle","opencv_rectangle";
+// //"sepFilter2D","opencv_sepFilter2D";
+// //"copymakeborder","opencv_copymakeborder";
+// //"cvtColor","opencv_cvtColor";
+// //"getgaussiankernel","opencv_getgaussiankernel";
+// //"getrectsubpix","opencv_getrectsubpix";
+// //"getrotationmatrix2D","opencv_getrotationmatrix2D";
+// //"houghlinesp","opencv_houghlinesp";
+// //"demosaic", "opencv_demosaic";
+// //"imfindcircles", "opencv_imfindcircles";
+// "opencv_detectHarrisFeatures", "opencv_detectHarrisFeatures";
+// "opencv_detectMinEigenFeatures", "opencv_detectMinEigenFeatures";
+// "opencv_corner","opencv_corner";
+// "opencv_ocr","opencv_ocr";
+// "opencv_imageSet","opencv_imageSet";
+// "opencv_partition","opencv_partition";
+// "opencv_trainImageCategoryClassifier","opencv_trainImageCategoryClassifier";
+// "opencv_bagOfFeatures","opencv_bagOfFeatures";
+// "opencv_predict","opencv_predict";
+// "opencv_evaluate","opencv_evaluate";
+// "opencv_detectCheckerboardPoints","opencv_detectCheckerboardPoints";
+// //"opencv_TemplateMatcher", "opencv_TemplateMatcher";
+// //"opencv_peopleDetector", "opencv_peopleDetector";
+// //"opencv_IDCT", "opencv_IDCT";
+// //"opencv_isEpipoleInImage", "opencv_isEpipoleInImage";
+// //"opencv_undistortImage", "opencv_undistortImage";
+// //"opencv_bundleAdjustment", "opencv_bundleAdjustment";
+// "opencv_projectPoints","opencv_projectPoints";
+// "opencv_estimateFundamentalMatrix","opencv_estimateFundamentalMatrix";
+// "opencv_estimateUncalibratedRectification","opencv_estimateUncalibratedRectification";
+// "opencv_FFT","opecv_FFT";
+// "IFFT","opencv_IFFT";
+// "GeometricShearer","opencv_GeometricShearer";
+// "pyramid","opencv_pyramid";
+// "insertObjectAnnotation","opencv_CascadeObjectDetector";
+// "rectifyStereoImages","opencv_rectifyStereoImages";
+// "bbox2points","opencv_bbox2points";
+// "bboxOverlapRatio","opencv_bboxOverlapRatio";
+// "BlockMatcher","opencv_BlockMatcher";
+// "cameraMatrix","opencv_cameraMatrix";
+// "extractLBPFeatures","opencv_extractLBPFeatures";
+// "genCheckerboardPoints","opencv_generateCheckerboardPoints";
+// "HistogramBasedTracker","opencv_HistogramBasedTracker";
+// "integralFilter","opencv_integralFilter";
+// "integralImage","opencv_integralImage";
+// "integralKernel","opencv_integralKernel";
+// "rotationVectorToMatrix","opencv_rotationVectorToMatrix";
+// "VideoPlayer","opencv_VideoPlayer";
+// "detectFASTFeatures","opencv_detectFASTFeatures";
+// "detectMSERFeatures","opencv_detectMSERFeatures";
+// "evaluateImageRetieval","opencv_evaluateImageRetrieval";
+// "extractFeatures","opencv_extractFeatures";
+// "matchFeatures","opencv_matchFeatures";
+// "retrieveImages","opencv_retrieveImages";
+// "indexImages","opencv_indexImages";
+// "ocv_detectSURFFeatures", "opencv_detectSURFFeatures";
+// "KalmanFilter","opencv_KalmanFilter";
+// "isfilter", "opencv_isfilter";
+// "convolver","opencv_convolver";
+// "opticalFlowFarneback","opencv_opticalFlowFarneback";
+// "extractHOGFeatures","opencv_extractHOGFeatures";
+// "showMatchedFeatures","opencv_showMatchedFeatures";
+// "estimateGeometricTransform","opencv_estimateGeometricTransform";
+// "epipolarlines","opencv_epipolarlines";
+// "ocv_SURFPoints", "opencv_SURFPoints";
+// "ocv_detectBRISKFeatures", "opencv_detectBRISKFeatures";
+// "ocv_BRISKPoints", "opencv_BRISKPoints";
+// "ocv_VideoReader", "opencv_VideoReader";
+// "ocv_hasFrame", "has_frame";
+// "ocv_readFrame", "read_frame";
+// "rotationMatrixToVector", "rotationMTV";
+// "ocv_ForegroundDetector", "opencv_ForegroundDetector";
+// "ocv_readForegroundMask", "opencv_readForegroundMask";
+// "rotationMatrixtoVector", "rotationMTV";
+// "opencv_blobAnalysis", "opencv_blobAnalysis";
+// "opencv_DCT", "opencv_DCT"
+// "opencv_Deinterlacer", "opencv_Deinterlacer";
+// "opencv_triangulatePoints", "opencv_triangulatePoints";
+// "opencv_undistortPoints", "opencv_undistortPoints";
+ ];
+
+files = [
+// "common.cpp",
+ "opencv_imread.cpp",
+// //"opencv_blur.cpp",
+// //"opencv_arrowedline.cpp",
+// //"opencv_canny.cpp",
+// //"opencv_circle.cpp",
+// //"opencv_clipline.cpp",
+// //"opencv_convexhull.cpp",
+// //"opencv_cornerEigenValsAndVecs.cpp"
+// //"opencv_cornerHarris.cpp",
+// //"opencv_cornerMinEigenVal.cpp",
+// //"opencv_dilate.cpp",
+// //"opencv_ellipse2poly.cpp",
+// //"opencv_erode.cpp",
+// //"opencv_fillconvexpoly.cpp",
+// //"opencv_filter2D.cpp",
+// //"opencv_findContours.cpp",
+// //"opencv_gaussianblur.cpp",
+// //"opencv_getStructuringElement.cpp",
+// //"opencv_getTextSize.cpp",
+// //"opencv_goodfeaturestotrack.cpp",
+// //"opencv_houghcircles.cpp",
+// //"opencv_houghlines.cpp",
+// //"opencv_im2double.cpp",
+// //"opencv_imcontrast.cpp",
+ "opencv_imcrop.cpp",
+ "opencv_imresize.cpp",
+ "opencv_imsharpen.cpp",
+ "opencv_imwrite.cpp",
+// //"opencv_laplacian.cpp",
+// //"opencv_line.cpp",
+// //"opencv_medianblur.cpp",
+// //"opencv_puttext.cpp",
+// //"opencv_scharr.cpp",
+// //"opencv_sobel.cpp",
+// //"opencv_threshold.cpp",
+// //"opencv_undistort.cpp",
+// //"opencv_boundingRect.cpp",
+// //"opencv_ellipse.cpp",
+// //"opencv_montage.cpp",
+// //"opencv_morphologyEx.cpp",
+// //"opencv_pyrDown.cpp",
+// //"opencv_pyrUp.cpp",
+// //"opencv_rectangle.cpp",
+// //"opencv_sepFilter2D.cpp",
+// //"opencv_copymakeborder.cpp",
+// //"opencv_cvtColor.cpp",
+// //"opencv_getgaussiankernel.cpp",
+// //"opencv_getrectsubpix.cpp",
+// //"opencv_getrotationmatrix2D.cpp",
+// //"opencv_houghlinesp.cpp",
+// //"opencv_demosaic.cpp",
+// //"opencv_imfindcircles.cpp",
+// "opencv_detectHarrisFeatures.cpp",
+// "opencv_detectMinEigenFeatures.cpp",
+// "opencv_corner.cpp",
+// "opencv_ocr.cpp",
+// "opencv_imageSet.cpp",
+// "opencv_partition.cpp",
+// "opencv_trainImageCategoryClassifier.cpp",
+// "opencv_bagOfFeatures.cpp",
+// "opencv_predict.cpp",
+// "opencv_evaluate.cpp",
+// "opencv_detectCheckerboardPoints.cpp",
+// //"opencv_TemplateMatcher.cpp",
+// //"opencv_peopleDetector.cpp",
+// //"opencv_IDCT.cpp",
+// //"opencv_isEpipoleInImage.cpp",
+// //"opencv_undistortImage.cpp",
+// //"opencv_bundleAdjustment.cpp",
+// "opencv_projectPoints.cpp",
+// "opencv_estimateFundamentalMatrix.cpp",
+// "opencv_estimateUncalibratedRectification.cpp",
+// "opencv_FFT.cpp"
+// "opencv_IFFT.cpp",
+// "opencv_GeometricShearer.cpp",
+// "opencv_pyramid.cpp",
+// "opencv_CascadeObjectDetector.cpp",
+// "opencv_rectifyStereoImages.cpp",
+// "opencv_bbox2points.cpp",
+// "opencv_bboxOverlapRatio.cpp",
+// "opencv_BlockMatcher.cpp",
+// "opencv_cameraMatrix.cpp",
+// "opencv_extractLBPFeatures.cpp",
+// "opencv_generateCheckerboardPoints.cpp",
+// "opencv_HistogramBasedTracker.cpp",
+// "opencv_integralFilter.cpp",
+// "opencv_integralImage.cpp",
+// "opencv_integralKernel.cpp",
+// "opencv_rotationVectorToMatrix.cpp",
+// "opencv_VideoPlayer.cpp",
+// "opencv_detectFASTFeatures.cpp",
+// "opencv_detectMSERFeatures.cpp",
+// "opencv_evaluateImageRetrieval.cpp",
+// "opencv_extractFeatures.cpp",
+// "opencv_matchFeatures.cpp",
+// "opencv_retrieveImages.cpp",
+// "opencv_indexImages.cpp",
+// "opencv_KalmanFilter.cpp",
+// "opencv_isfilter.cpp",
+// "opencv_convolver.cpp",
+// "opencv_opticalFlowFarneback.cpp",
+// "opencv_extractHOGFeatures.cpp",
+// "opencv_showMatchedFeatures.cpp",
+// "opencv_estimateGeometricTransform.cpp",
+// "opencv_epipolarlines.cpp",
+// "opencv_detectSURFFeatures.cpp",
+// "opencv_SURFPoints.cpp",
+// "opencv_detectBRISKFeatures.cpp",
+// "opencv_BRISKPoints.cpp",
+// "opencv_VideoReader.cpp",
+// "rotationMatrixToVector.cpp",
+// "opencv_ForegroundDetector.cpp",
+// "opencv_blobAnalysis.cpp",
+// "opencv_DCT.cpp",
+// "opencv_Deinterlacer.cpp",
+// "opencv_triangulatePoints.cpp",
+// "opencv_undistortPoints.cpp"
+ ];
+//[a, opt] = getversion();
+//Version = opt(2);
+
+////Build_64Bits = %f;
+
+//if getos()=="Windows" then
+//// third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty';
+//// lib_base_dir = third_dir + filesep() + 'windows' + filesep() + 'lib' + filesep() + Version + filesep();
+//// inc_base_dir = third_dir + filesep() + 'windows' + filesep() + 'include' + filesep() + 'coin';
+//// C_Flags=['-D__USE_DEPRECATED_STACK_FUNCTIONS__ -w -I '+path_builder+' '+ '-I '+inc_base_dir+' ']
+//// Linker_Flag = [lib_base_dir+"libClp.lib "+lib_base_dir+"libCgl.lib "+lib_base_dir+"libOsi.lib "+lib_base_dir+"libOsiClp.lib "+lib_base_dir+"libCoinUtils.lib "+lib_base_dir+"libSymphony.lib "+lib_base_dir+"IpOptFSS.lib "+lib_base_dir+"IpOpt-vc10.lib "]
+
+//else
+// third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty';
+// lib_base_dir = third_dir + filesep() + 'linux' + filesep() + 'lib' + filesep() + Version + filesep();
+// inc_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include' + filesep() + 'opencv';
+// incl_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include' + filesep() + 'opencv2';
+//
+//// C_Flags=[" -I"+inc_base_dir+" "+"- I"+incl_base_dir]
+// C_Flags=[" -I/usr/include/scilab -I/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/include/opencvopencv -I/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/include/opencvopencv2"]
+//
+//
+//// Linker_Flag = ["-L"+lib_base_dir+"libopencv_core"+" "+"-L"+lib_base_dir+"libopencv_highgui"+" "+"-L"+lib_base_dir+"libopencv_imgproc"]
+// Linker_Flag = ["-L/usr/lib -lopencv_core -L/usr/lib -lopencv_highgui -L/usr/lib -lopencv_imgproc"]
+//
+//end
+
+//copyfile("sci_gateway/cpp/common.h",TMPDIR);
+//copyfile("sci_gateway/cpp/common.cpp",TMPDIR);
+
+//tbx_build_gateway(toolbox_title,Function_Names,files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags,[]);
+
+//clear toolbox_title Function_Names files Linker_Flag C_Flags;
+
+
+function builder_gw_cpp()
+ WITHOUT_AUTO_PUTLHSVAR = %t;
+ copyfile("/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/sci_gateway/cpp/common.h",TMPDIR);
+ copyfile("/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/sci_gateway/cpp/common.cpp",TMPDIR);
+ tbx_build_gateway("skeleton_imageprocessing", ..
+ Function_Names, ..
+ files, ..
+ get_absolute_file_path("builder_gateway_cpp.sce"),[],["-L/usr/local/lib -lopencv_core -L/usr/local/lib -lopencv_highgui -L/usr/local/lib -lopencv_imgproc -L/usr/local/lib -lopencv_calib3d -L/usr/local/lib -lopencv_video -L/usr/local/lib -lopencv_nonfree -L/usr/local/lib -lopencv_ml -L/usr/local/lib -lopencv_objdetect"],["-I/usr/include/scilab -I/usr/include/opencv -I/usr/include/opencv2 "],"g++ ");
+// get_absolute_file_path("builder_gateway_cpp.sce"),[],["-L/usr/local/lib -lopencv_core -L/usr/local/lib -lopencv_highgui -L/usr/local/lib -lopencv_imgproc -L/usr/local/lib -lopencv_calib3d -L/usr/local/lib -lopencv_video -L/usr/local/lib -ltesseract -L/usr/local/lib -llept -L/usr/local/lib -lopencv_nonfree -L/usr/local/lib -lopencv_ml -L/usr/local/lib -lopencv_objdetect"],["-I/usr/include/scilab -I/usr/include/opencv -I/usr/include/opencv2 -I/usr/include/tesseract"],"g++ ");
+endfunction
+
+builder_gw_cpp();
+clear builder_gw_cpp; // remove builder_gw_cpp on stack
diff --git a/sci_gateway1/cpp/builder_gateway_cpp.sce~ b/sci_gateway1/cpp/builder_gateway_cpp.sce~
new file mode 100644
index 0000000..f9b2fc3
--- /dev/null
+++ b/sci_gateway1/cpp/builder_gateway_cpp.sce~
@@ -0,0 +1,312 @@
+// Copyright (C) 2015 - IIT Bombay - FOSSEE
+//
+// This file must be used under the terms of the BSD.
+// This source file is licensed as described in the file LICENSE, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// https://opensource.org/licenses/BSD-3-Clause
+// Author: Shamika Mohanan
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
+
+//mode(-1)
+//lines(0)
+
+//toolbox_title = "FOSSEE_Image_Processing_Toolbox";
+
+//Build_64Bits = %t;
+
+//path_builder = get_absolute_file_path('builder_gateway_cpp.sce');
+
+Function_Names = [
+ "opencv_imread","opencv_imread";
+// //"blur","opencv_blur";
+// //"arrowedline","opencv_arrowedline";
+// //"canny","opencv_canny";
+// //"circle","opencv_circle";
+// //"clipline","opencv_clipline";
+// //"convexhull","opencv_convexhull";
+// //"cornerEigenValsAndVecs","opencv_cornerEigenValsAndVecs";
+// //"cornerHarris","opencv_cornerHarris";
+// //"cornerMinEigenVal","opencv_cornerMinEigenVal";
+// //"dilate","opencv_dilate";
+// //"ellipse2poly","opencv_ellipse2poly";
+// //"erode","opencv_erode";
+// //"fillconvexpoly","opencv_fillconvexpoly";
+// //"filter2D","opencv_filter2D";
+// //"findContours","opencv_findContours";
+// //"gaussianblur","opencv_gaussianblur";
+// //"getStructuringElement","opencv_getStructuringElement";
+// //"getTextSize","opencv_getTextSize";
+// //"goodfeaturestotrack","opencv_goodfeaturestotrack";
+// //"houghcircles","opencv_houghcircles";
+// //"houghlines","opencv_houghlines";
+// //"im2double","opencv_im2double";
+// //"imcontrast","opencv_imcontrast";
+ "imcrop","opencv_imcrop";
+ "imresize","opencv_imresize";
+ "imsharpen","opencv_imsharpen";
+ "imwrite","opencv_imwrite";
+// //"laplacian","opencv_laplacian";
+// //"line","opencv_line";
+// //"medianblur","opencv_medianblur";
+// //"puttext","opencv_puttext";
+// //"scharr","opencv_scharr";
+// //"sobel","opencv_sobel";
+// //"threshold","opencv_threshold";
+// //"undistort","opencv_undistort";
+// //"boundingRect","opencv_boundingRect";
+// //"ellipse","opencv_ellipse";
+// //"montage","opencv_montage";
+// //"morphologyEx","opencv_morphologyEx";
+// //"pyrDown","opencv_pyrDown";
+// //"pyrUp","opencv_pyrUp";
+// //"rectangle","opencv_rectangle";
+// //"sepFilter2D","opencv_sepFilter2D";
+// //"copymakeborder","opencv_copymakeborder";
+// //"cvtColor","opencv_cvtColor";
+// //"getgaussiankernel","opencv_getgaussiankernel";
+// //"getrectsubpix","opencv_getrectsubpix";
+// //"getrotationmatrix2D","opencv_getrotationmatrix2D";
+// //"houghlinesp","opencv_houghlinesp";
+// //"demosaic", "opencv_demosaic";
+// //"imfindcircles", "opencv_imfindcircles";
+// "opencv_detectHarrisFeatures", "opencv_detectHarrisFeatures";
+// "opencv_detectMinEigenFeatures", "opencv_detectMinEigenFeatures";
+// "opencv_corner","opencv_corner";
+// "opencv_ocr","opencv_ocr";
+// "opencv_imageSet","opencv_imageSet";
+// "opencv_partition","opencv_partition";
+// "opencv_trainImageCategoryClassifier","opencv_trainImageCategoryClassifier";
+// "opencv_bagOfFeatures","opencv_bagOfFeatures";
+// "opencv_predict","opencv_predict";
+// "opencv_evaluate","opencv_evaluate";
+// "opencv_detectCheckerboardPoints","opencv_detectCheckerboardPoints";
+// //"opencv_TemplateMatcher", "opencv_TemplateMatcher";
+// //"opencv_peopleDetector", "opencv_peopleDetector";
+// //"opencv_IDCT", "opencv_IDCT";
+// //"opencv_isEpipoleInImage", "opencv_isEpipoleInImage";
+// //"opencv_undistortImage", "opencv_undistortImage";
+// //"opencv_bundleAdjustment", "opencv_bundleAdjustment";
+// "opencv_projectPoints","opencv_projectPoints";
+// "opencv_estimateFundamentalMatrix","opencv_estimateFundamentalMatrix";
+// "opencv_estimateUncalibratedRectification","opencv_estimateUncalibratedRectification";
+// "opencv_FFT","opecv_FFT";
+// "IFFT","opencv_IFFT";
+// "GeometricShearer","opencv_GeometricShearer";
+// "pyramid","opencv_pyramid";
+// "insertObjectAnnotation","opencv_CascadeObjectDetector";
+// "rectifyStereoImages","opencv_rectifyStereoImages";
+// "bbox2points","opencv_bbox2points";
+// "bboxOverlapRatio","opencv_bboxOverlapRatio";
+// "BlockMatcher","opencv_BlockMatcher";
+// "cameraMatrix","opencv_cameraMatrix";
+// "extractLBPFeatures","opencv_extractLBPFeatures";
+// "genCheckerboardPoints","opencv_generateCheckerboardPoints";
+// "HistogramBasedTracker","opencv_HistogramBasedTracker";
+// "integralFilter","opencv_integralFilter";
+// "integralImage","opencv_integralImage";
+// "integralKernel","opencv_integralKernel";
+// "rotationVectorToMatrix","opencv_rotationVectorToMatrix";
+// "VideoPlayer","opencv_VideoPlayer";
+// "detectFASTFeatures","opencv_detectFASTFeatures";
+// "detectMSERFeatures","opencv_detectMSERFeatures";
+// "evaluateImageRetieval","opencv_evaluateImageRetrieval";
+// "extractFeatures","opencv_extractFeatures";
+// "matchFeatures","opencv_matchFeatures";
+// "retrieveImages","opencv_retrieveImages";
+// "indexImages","opencv_indexImages";
+// "ocv_detectSURFFeatures", "opencv_detectSURFFeatures";
+// "KalmanFilter","opencv_KalmanFilter";
+// "isfilter", "opencv_isfilter";
+// "convolver","opencv_convolver";
+// "opticalFlowFarneback","opencv_opticalFlowFarneback";
+// "extractHOGFeatures","opencv_extractHOGFeatures";
+// "showMatchedFeatures","opencv_showMatchedFeatures";
+// "estimateGeometricTransform","opencv_estimateGeometricTransform";
+// "epipolarlines","opencv_epipolarlines";
+// "ocv_SURFPoints", "opencv_SURFPoints";
+// "ocv_detectBRISKFeatures", "opencv_detectBRISKFeatures";
+// "ocv_BRISKPoints", "opencv_BRISKPoints";
+// "ocv_VideoReader", "opencv_VideoReader";
+// "ocv_hasFrame", "has_frame";
+// "ocv_readFrame", "read_frame";
+// "rotationMatrixToVector", "rotationMTV";
+// "ocv_ForegroundDetector", "opencv_ForegroundDetector";
+// "ocv_readForegroundMask", "opencv_readForegroundMask";
+// "rotationMatrixtoVector", "rotationMTV";
+// "opencv_blobAnalysis", "opencv_blobAnalysis";
+// "opencv_DCT", "opencv_DCT"
+// "opencv_Deinterlacer", "opencv_Deinterlacer";
+// "opencv_triangulatePoints", "opencv_triangulatePoints";
+// "opencv_undistortPoints", "opencv_undistortPoints";
+ ];
+
+files = [
+// "common.cpp",
+ "opencv_imread.cpp",
+// //"opencv_blur.cpp",
+// //"opencv_arrowedline.cpp",
+// //"opencv_canny.cpp",
+// //"opencv_circle.cpp",
+// //"opencv_clipline.cpp",
+// //"opencv_convexhull.cpp",
+// //"opencv_cornerEigenValsAndVecs.cpp"
+// //"opencv_cornerHarris.cpp",
+// //"opencv_cornerMinEigenVal.cpp",
+// //"opencv_dilate.cpp",
+// //"opencv_ellipse2poly.cpp",
+// //"opencv_erode.cpp",
+// //"opencv_fillconvexpoly.cpp",
+// //"opencv_filter2D.cpp",
+// //"opencv_findContours.cpp",
+// //"opencv_gaussianblur.cpp",
+// //"opencv_getStructuringElement.cpp",
+// //"opencv_getTextSize.cpp",
+// //"opencv_goodfeaturestotrack.cpp",
+// //"opencv_houghcircles.cpp",
+// //"opencv_houghlines.cpp",
+// //"opencv_im2double.cpp",
+// //"opencv_imcontrast.cpp",
+ "opencv_imcrop.cpp",
+ "opencv_imresize.cpp",
+ "opencv_imsharpen.cpp",
+ "opencv_imwrite.cpp",
+// //"opencv_laplacian.cpp",
+// //"opencv_line.cpp",
+// //"opencv_medianblur.cpp",
+// //"opencv_puttext.cpp",
+// //"opencv_scharr.cpp",
+// //"opencv_sobel.cpp",
+// //"opencv_threshold.cpp",
+// //"opencv_undistort.cpp",
+// //"opencv_boundingRect.cpp",
+// //"opencv_ellipse.cpp",
+// //"opencv_montage.cpp",
+// //"opencv_morphologyEx.cpp",
+// //"opencv_pyrDown.cpp",
+// //"opencv_pyrUp.cpp",
+// //"opencv_rectangle.cpp",
+// //"opencv_sepFilter2D.cpp",
+// //"opencv_copymakeborder.cpp",
+// //"opencv_cvtColor.cpp",
+// //"opencv_getgaussiankernel.cpp",
+// //"opencv_getrectsubpix.cpp",
+// //"opencv_getrotationmatrix2D.cpp",
+// //"opencv_houghlinesp.cpp",
+// //"opencv_demosaic.cpp",
+// //"opencv_imfindcircles.cpp",
+// "opencv_detectHarrisFeatures.cpp",
+// "opencv_detectMinEigenFeatures.cpp",
+// "opencv_corner.cpp",
+// "opencv_ocr.cpp",
+// "opencv_imageSet.cpp",
+// "opencv_partition.cpp",
+// "opencv_trainImageCategoryClassifier.cpp",
+// "opencv_bagOfFeatures.cpp",
+// "opencv_predict.cpp",
+// "opencv_evaluate.cpp",
+// "opencv_detectCheckerboardPoints.cpp",
+// //"opencv_TemplateMatcher.cpp",
+// //"opencv_peopleDetector.cpp",
+// //"opencv_IDCT.cpp",
+// //"opencv_isEpipoleInImage.cpp",
+// //"opencv_undistortImage.cpp",
+// //"opencv_bundleAdjustment.cpp",
+// "opencv_projectPoints.cpp",
+// "opencv_estimateFundamentalMatrix.cpp",
+// "opencv_estimateUncalibratedRectification.cpp",
+// "opencv_FFT.cpp"
+// "opencv_IFFT.cpp",
+// "opencv_GeometricShearer.cpp",
+// "opencv_pyramid.cpp",
+// "opencv_CascadeObjectDetector.cpp",
+// "opencv_rectifyStereoImages.cpp",
+// "opencv_bbox2points.cpp",
+// "opencv_bboxOverlapRatio.cpp",
+// "opencv_BlockMatcher.cpp",
+// "opencv_cameraMatrix.cpp",
+// "opencv_extractLBPFeatures.cpp",
+// "opencv_generateCheckerboardPoints.cpp",
+// "opencv_HistogramBasedTracker.cpp",
+// "opencv_integralFilter.cpp",
+// "opencv_integralImage.cpp",
+// "opencv_integralKernel.cpp",
+// "opencv_rotationVectorToMatrix.cpp",
+// "opencv_VideoPlayer.cpp",
+// "opencv_detectFASTFeatures.cpp",
+// "opencv_detectMSERFeatures.cpp",
+// "opencv_evaluateImageRetrieval.cpp",
+// "opencv_extractFeatures.cpp",
+// "opencv_matchFeatures.cpp",
+// "opencv_retrieveImages.cpp",
+// "opencv_indexImages.cpp",
+// "opencv_KalmanFilter.cpp",
+// "opencv_isfilter.cpp",
+// "opencv_convolver.cpp",
+// "opencv_opticalFlowFarneback.cpp",
+// "opencv_extractHOGFeatures.cpp",
+// "opencv_showMatchedFeatures.cpp",
+// "opencv_estimateGeometricTransform.cpp",
+// "opencv_epipolarlines.cpp",
+// "opencv_detectSURFFeatures.cpp",
+// "opencv_SURFPoints.cpp",
+// "opencv_detectBRISKFeatures.cpp",
+// "opencv_BRISKPoints.cpp",
+// "opencv_VideoReader.cpp",
+// "rotationMatrixToVector.cpp",
+// "opencv_ForegroundDetector.cpp",
+// "opencv_blobAnalysis.cpp",
+// "opencv_DCT.cpp",
+// "opencv_Deinterlacer.cpp",
+// "opencv_triangulatePoints.cpp",
+// "opencv_undistortPoints.cpp"
+ ];
+//[a, opt] = getversion();
+//Version = opt(2);
+
+////Build_64Bits = %f;
+
+//if getos()=="Windows" then
+//// third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty';
+//// lib_base_dir = third_dir + filesep() + 'windows' + filesep() + 'lib' + filesep() + Version + filesep();
+//// inc_base_dir = third_dir + filesep() + 'windows' + filesep() + 'include' + filesep() + 'coin';
+//// C_Flags=['-D__USE_DEPRECATED_STACK_FUNCTIONS__ -w -I '+path_builder+' '+ '-I '+inc_base_dir+' ']
+//// Linker_Flag = [lib_base_dir+"libClp.lib "+lib_base_dir+"libCgl.lib "+lib_base_dir+"libOsi.lib "+lib_base_dir+"libOsiClp.lib "+lib_base_dir+"libCoinUtils.lib "+lib_base_dir+"libSymphony.lib "+lib_base_dir+"IpOptFSS.lib "+lib_base_dir+"IpOpt-vc10.lib "]
+
+//else
+// third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty';
+// lib_base_dir = third_dir + filesep() + 'linux' + filesep() + 'lib' + filesep() + Version + filesep();
+// inc_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include' + filesep() + 'opencv';
+// incl_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include' + filesep() + 'opencv2';
+//
+//// C_Flags=[" -I"+inc_base_dir+" "+"- I"+incl_base_dir]
+// C_Flags=[" -I/usr/include/scilab -I/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/include/opencvopencv -I/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/include/opencvopencv2"]
+//
+//
+//// Linker_Flag = ["-L"+lib_base_dir+"libopencv_core"+" "+"-L"+lib_base_dir+"libopencv_highgui"+" "+"-L"+lib_base_dir+"libopencv_imgproc"]
+// Linker_Flag = ["-L/usr/lib -lopencv_core -L/usr/lib -lopencv_highgui -L/usr/lib -lopencv_imgproc"]
+//
+//end
+
+//copyfile("sci_gateway/cpp/common.h",TMPDIR);
+//copyfile("sci_gateway/cpp/common.cpp",TMPDIR);
+
+//tbx_build_gateway(toolbox_title,Function_Names,files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags,[]);
+
+//clear toolbox_title Function_Names files Linker_Flag C_Flags;
+
+
+function builder_gw_cpp()
+ WITHOUT_AUTO_PUTLHSVAR = %t;
+ copyfile("/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/sci_gateway/cpp/common.h",TMPDIR);
+ copyfile("/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/sci_gateway/cpp/common.cpp",TMPDIR);
+ tbx_build_gateway("skeleton_imageprocessing", ..
+ Function_Names, ..
+ files, ..
+ get_absolute_file_path("builder_gateway_cpp.sce"),[],["-L/usr/local/lib -lopencv_core -L/usr/local/lib -lopencv_highgui -L/usr/local/lib -lopencv_imgproc -L/usr/local/lib -lopencv_calib3d -L/usr/local/lib -lopencv_video -L/usr/local/lib -lopencv_nonfree -L/usr/local/lib -lopencv_ml -L/usr/local/lib -lopencv_objdetect"],["-I/usr/include/scilab -I/usr/include/opencv -I/usr/include/opencv2 "],"g++ ");
+// get_absolute_file_path("builder_gateway_cpp.sce"),[],["-L/usr/local/lib -lopencv_core -L/usr/local/lib -lopencv_highgui -L/usr/local/lib -lopencv_imgproc -L/usr/local/lib -lopencv_calib3d -L/usr/local/lib -lopencv_video -L/usr/local/lib -ltesseract -L/usr/local/lib -llept -L/usr/local/lib -lopencv_nonfree -L/usr/local/lib -lopencv_ml -L/usr/local/lib -lopencv_objdetect"],["-I/usr/include/scilab -I/usr/include/opencv -I/usr/include/opencv2 -I/usr/include/tesseract"],"g++ ");
+endfunction
+
+builder_gw_cpp();
+clear builder_gw_cpp; // remove builder_gw_cpp on stack
diff --git a/sci_gateway1/cpp/cleaner.sce b/sci_gateway1/cpp/cleaner.sce
new file mode 100644
index 0000000..12b9fbb
--- /dev/null
+++ b/sci_gateway1/cpp/cleaner.sce
@@ -0,0 +1,22 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce : Please, do not edit this file
+// cleaner.sce
+// ------------------------------------------------------
+curdir = pwd();
+cleaner_path = get_file_path('cleaner.sce');
+chdir(cleaner_path);
+// ------------------------------------------------------
+if fileinfo('loader.sce') <> [] then
+ mdelete('loader.sce');
+end
+// ------------------------------------------------------
+if fileinfo('libskeleton_imageprocessing.so') <> [] then
+ mdelete('libskeleton_imageprocessing.so');
+end
+// ------------------------------------------------------
+if fileinfo('libskeleton_imageprocessing.c') <> [] then
+ mdelete('libskeleton_imageprocessing.c');
+end
+// ------------------------------------------------------
+chdir(curdir);
+// ------------------------------------------------------
diff --git a/sci_gateway1/cpp/common.cpp b/sci_gateway1/cpp/common.cpp
new file mode 100644
index 0000000..c19f58a
--- /dev/null
+++ b/sci_gateway1/cpp/common.cpp
@@ -0,0 +1,890 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+//takes the matrix type as parameter and returns a string of the type
+string type2str(int type)
+{
+ string r;
+ uchar depth = type & CV_MAT_DEPTH_MASK;
+ switch ( depth )
+ {
+ case CV_8U: r = "8U"; break;
+ case CV_8S: r = "8S"; break;
+ case CV_16U: r = "16U"; break;
+ case CV_16S: r = "16S"; break;
+ case CV_32S: r = "32S"; break;
+ case CV_32F: r = "32F"; break;
+ case CV_64F: r = "64F"; break;
+ default: r = "User"; break;
+ }
+ return r;
+}
+
+//takes matrix type as parameter and returns no. of channels of the image matrix
+int no_of_channels(int type)
+{
+ uchar chans = 1 + (type >> CV_CN_SHIFT);
+ return chans;
+}
+
+//function used to retrieve image matrix from Scilab environment
+/*
+ We need to retrieve image from the Scilab environment
+ We do this by getting a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int retrieveImage(Mat &image,int pos)
+{
+
+ SciErr sciErr;
+ int iRows=0,iCols=0,i,j,k=0;
+ int *piAddr = NULL;
+ int *piAddrChild = NULL;
+ int iPrec = 0,iItem = 0;
+
+ //retrieving number of items in the list and type of data(integer/float)
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isIntegerType(pvApiCtx, piAddrChild))
+ {
+ //getting precision
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrChild, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8
+ {
+ if(iItem==3)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC3);
+
+ /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ unsigned char *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC1);
+
+ //Assigning matrix value to pixel
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16
+ {
+ if(iItem==3)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+ short unsigned int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ //i+iRows*j
+ }
+ }
+ }
+ else
+ {
+ short unsigned int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC1);
+
+ //Assigning matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<ushort>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_INT16: //for signed integer 16
+ {
+ if(iItem==3)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+ short int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ short int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<short>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ }
+ }
+ else //for floating point/ double precision values
+ {
+ if(iItem==3)
+ {
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&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,pos,&piAddrChild);
+ 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,pos,&piAddrChild);
+ 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;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3d>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3d>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ double *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&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;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<double>(i,j)=pstDataR[i+iRows*j];
+ }
+ }
+ return 1;
+}
+
+//function that returns an image matrix to the Scilab environment
+/*
+ What we now need, is to pass the image matrix to the Scilab environment.
+ We do this by passing a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int returnImage(char *checker,Mat img,int pos)
+{
+ int i,j,k=0;
+ int *piAddrNew = NULL;
+ SciErr sciErr;
+ int num=no_of_channels(img.type()); //num now contains no. of channels of the image
+ //creating the list that will be passed to the Scilab enviroment
+ if(num==3)
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 3, &piAddrNew);
+ else
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 1, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(strcmp(checker,"8U")==0) //for Unsigned Integer 8
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *g = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *b = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i, j);
+ r [i+img.rows*j]=intensity.val[2];
+ g [i+img.rows*j]=intensity.val[1];
+ b [i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<uchar>(i, j);
+
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"16U")==0) //for Unsigned Integer 16
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *g = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *b = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<ushort>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ }
+ else if(strcmp(checker,"16S")==0) //for Signed Integer 16
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *g = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *b = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<short>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"32S")==0) //for Signed Integer 16
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *g = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *b = (int *)malloc(img.rows * img.cols * sizeof(int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3i intensity = img.at<Vec3i>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<int>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+
+ else if(strcmp(checker,"32F")==0) //for Float 32
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<float>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+ else if(strcmp(checker,"64F")==0) //For Float 64
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<double>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+
+}
diff --git a/sci_gateway1/cpp/common.cpp~ b/sci_gateway1/cpp/common.cpp~
new file mode 100644
index 0000000..82d542f
--- /dev/null
+++ b/sci_gateway1/cpp/common.cpp~
@@ -0,0 +1,924 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+//takes the matrix type as parameter and returns a string of the type
+string type2str(int type)
+{
+ string r;
+ uchar depth = type & CV_MAT_DEPTH_MASK;
+ switch ( depth )
+ {
+ case CV_8U: r = "8U"; break;
+ case CV_8S: r = "8S"; break;
+ case CV_16U: r = "16U"; break;
+ case CV_16S: r = "16S"; break;
+ case CV_32S: r = "32S"; break;
+ case CV_32F: r = "32F"; break;
+ case CV_64F: r = "64F"; break;
+ default: r = "User"; break;
+ }
+ return r;
+}
+
+//takes matrix type as parameter and returns no. of channels of the image matrix
+int no_of_channels(int type)
+{
+ uchar chans = 1 + (type >> CV_CN_SHIFT);
+ return chans;
+}
+
+//function used to retrieve image matrix from Scilab environment
+/*
+ We need to retrieve image from the Scilab environment
+ We do this by getting a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int retrieveImage(Mat &image,int pos)
+{
+
+ SciErr sciErr;
+ int iRows=0,iCols=0,i,j,k=0;
+ int *piAddr = NULL;
+ int *piAddr1 = NULL;
+ int *piAddrChild = NULL;
+ int iPrec = 0,iItem = 0;
+ int r=0,c=0;
+
+ //retrieving number of items in the list and type of data(integer/float)
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+
+
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isIntegerType(pvApiCtx, piAddrChild))
+ {
+ //getting precision
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrChild, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8
+ {
+
+ if(iItem==3)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(r=0;r<iRows;r++)
+ {
+ for (c=0;c<iCols;c++)
+ {
+ sciprint("m=%d\n",pstDataR[r+iRows*c]);
+ }
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+
+
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC3);
+
+ /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ unsigned char *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC1);
+
+ //Assigning matrix value to pixel
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16
+ {
+
+ if(iItem==3)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+ short unsigned int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ //i+iRows*j
+ }
+ }
+ }
+ else
+ {
+ short unsigned int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC1);
+
+ //Assigning matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<ushort>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_INT16: //for signed integer 16
+ {
+
+ if(iItem==3)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+ short int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ short int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<short>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ }
+ }
+ else //for floating point/ double precision values
+ {
+
+ if(iItem==3)
+ {
+
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&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,pos,&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,pos,&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;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3d>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3d>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+
+ }
+ else
+ {
+
+ double *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<double>(i,j)=pstDataR[i+iRows*j];
+ }
+ }
+ return 1;
+}
+
+//function that returns an image matrix to the Scilab environment
+/*
+ What we now need, is to pass the image matrix to the Scilab environment.
+ We do this by passing a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int returnImage(char *checker,Mat img,int pos)
+{
+ int i,j,k=0;
+ int *piAddrNew = NULL;
+ SciErr sciErr;
+ int num=no_of_channels(img.type()); //num now contains no. of channels of the image
+ //creating the list that will be passed to the Scilab enviroment
+ if(num==3)
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 3, &piAddrNew);
+ else
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 1, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(strcmp(checker,"8U")==0) //for Unsigned Integer 8
+ {
+ if(num==3)
+ {
+
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *g = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *b = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i, j);
+ *(r + j*img.rows + i)=intensity.val[2];
+ *(g + j*img.rows + i)=intensity.val[1];
+ *(b + j*img.rows + i)=intensity.val[0];
+ }
+ }
+
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<uchar>(i, j);
+
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"16U")==0) //for Unsigned Integer 16
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *g = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *b = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<ushort>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ }
+ else if(strcmp(checker,"16S")==0) //for Signed Integer 16
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *g = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *b = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<short>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"32S")==0) //for Signed Integer 16
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *g = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *b = (int *)malloc(img.rows * img.cols * sizeof(int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3i intensity = img.at<Vec3i>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<int>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+
+ else if(strcmp(checker,"32F")==0) //for Float 32
+ {
+ if(num==3)
+ {
+
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<float>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+ else if(strcmp(checker,"64F")==0) //For Float 64
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<double>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+
+}
diff --git a/sci_gateway1/cpp/common.h b/sci_gateway1/cpp/common.h
new file mode 100644
index 0000000..5de6cf7
--- /dev/null
+++ b/sci_gateway1/cpp/common.h
@@ -0,0 +1,9 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+string type2str(int type);
+int no_of_channels(int type);
+int retrieveImage(Mat &image,int pos);
+int returnImage(char *checker,Mat img,int pos);
+
diff --git a/sci_gateway1/cpp/common.h~ b/sci_gateway1/cpp/common.h~
new file mode 100644
index 0000000..d42d9c7
--- /dev/null
+++ b/sci_gateway1/cpp/common.h~
@@ -0,0 +1,10 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+//using namespace std;
+
+string type2str(int type);
+int no_of_channels(int type);
+int retrieveImage(Mat &image,int pos);
+int returnImage(char *checker,Mat img,int pos);
+//int retrieveImageFromAddress(Mat &image,int *piAddr);
diff --git a/sci_gateway1/cpp/common1.cpp b/sci_gateway1/cpp/common1.cpp
new file mode 100644
index 0000000..41752e6
--- /dev/null
+++ b/sci_gateway1/cpp/common1.cpp
@@ -0,0 +1,897 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+//takes the matrix type as parameter and returns a string of the type
+string type2str(int type)
+{
+ string r;
+ uchar depth = type & CV_MAT_DEPTH_MASK;
+ switch ( depth )
+ {
+ case CV_8U: r = "8U"; break;
+ case CV_8S: r = "8S"; break;
+ case CV_16U: r = "16U"; break;
+ case CV_16S: r = "16S"; break;
+ case CV_32S: r = "32S"; break;
+ case CV_32F: r = "32F"; break;
+ case CV_64F: r = "64F"; break;
+ default: r = "User"; break;
+ }
+ return r;
+}
+
+//takes matrix type as parameter and returns no. of channels of the image matrix
+int no_of_channels(int type)
+{
+ uchar chans = 1 + (type >> CV_CN_SHIFT);
+ return chans;
+}
+
+//function used to retrieve image matrix from Scilab environment
+/*
+ We need to retrieve image from the Scilab environment
+ We do this by getting a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int retrieveImage(Mat &image,int pos)
+{
+
+ SciErr sciErr;
+ int iRows=0,iCols=0,i,j,k=0;
+ int *piAddr = NULL;
+ int *piAddrChild = NULL;
+ int iPrec = 0,iItem = 0;
+
+ //retrieving number of items in the list and type of data(integer/float)
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciprint("Test1");
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciprint("Testing1");
+ if(isIntegerType(pvApiCtx, piAddrChild))
+ {
+ //getting precision
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrChild, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8
+ {
+ if(iItem==3)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC3);
+
+ /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ unsigned char *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC1);
+
+ //Assigning matrix value to pixel
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16
+ {
+ if(iItem==3)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+ short unsigned int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ //i+iRows*j
+ }
+ }
+ }
+ else
+ {
+ short unsigned int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC1);
+
+ //Assigning matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<ushort>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_INT16: //for signed integer 16
+ {
+ if(iItem==3)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+ short int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ short int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<short>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ }
+ }
+ else //for floating point/ double precision values
+ {
+ sciprint("Test2");
+ if(iItem==3)
+ {
+ sciprint("Again");
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+// sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+ sciprint("Testing2");
+ //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,pos,&piAddr);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+ sciprint("Testing3");
+ //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,pos,&piAddr);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+ sciprint("Testing4");
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3d>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3d>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ sciprint("Test3");
+ }
+ else
+ {
+ double *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&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;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<double>(i,j)=pstDataR[i+iRows*j];
+ }
+ }
+ return 1;
+}
+
+//function that returns an image matrix to the Scilab environment
+/*
+ What we now need, is to pass the image matrix to the Scilab environment.
+ We do this by passing a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int returnImage(char *checker,Mat img,int pos)
+{
+ int i,j,k=0;
+ int *piAddrNew = NULL;
+ SciErr sciErr;
+ int num=no_of_channels(img.type()); //num now contains no. of channels of the image
+ //creating the list that will be passed to the Scilab enviroment
+ if(num==3)
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 3, &piAddrNew);
+ else
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 1, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(strcmp(checker,"8U")==0) //for Unsigned Integer 8
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *g = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *b = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i, j);
+ *(r + j*img.rows + i)=intensity.val[2];
+ *(g + j*img.rows + i)=intensity.val[1];
+ *(b + j*img.rows + i)=intensity.val[0];
+ }
+ }
+
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<uchar>(i, j);
+
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"16U")==0) //for Unsigned Integer 16
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *g = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *b = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<ushort>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ }
+ else if(strcmp(checker,"16S")==0) //for Signed Integer 16
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *g = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *b = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<short>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"32S")==0) //for Signed Integer 16
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *g = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *b = (int *)malloc(img.rows * img.cols * sizeof(int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3i intensity = img.at<Vec3i>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<int>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+
+ else if(strcmp(checker,"32F")==0) //for Float 32
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<float>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+ else if(strcmp(checker,"64F")==0) //For Float 64
+ {
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<double>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+
+}
diff --git a/sci_gateway1/cpp/common2.cpp b/sci_gateway1/cpp/common2.cpp
new file mode 100644
index 0000000..0f296ed
--- /dev/null
+++ b/sci_gateway1/cpp/common2.cpp
@@ -0,0 +1,2527 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+//takes the matrix type as parameter and returns a string of the type
+string type2str(int type)
+{
+ string r;
+ uchar depth = type & CV_MAT_DEPTH_MASK;
+ switch ( depth )
+ {
+ case CV_8U: r = "8U"; break;
+ case CV_8S: r = "8S"; break;
+ case CV_16U: r = "16U"; break;
+ case CV_16S: r = "16S"; break;
+ case CV_32S: r = "32S"; break;
+ case CV_32F: r = "32F"; break;
+ case CV_64F: r = "64F"; break;
+ default: r = "User"; break;
+ }
+ return r;
+}
+
+//takes matrix type as parameter and returns no. of channels of the image matrix
+//int no_of_channels(int type)
+//{
+// uchar chans = 1 + (type >> CV_CN_SHIFT);
+// return chans;
+//}
+//function used to retrieve image matrix from Scilab environment
+//int retrieveImageFromAddress(Mat &image,int *piAddr)
+//{
+// SciErr sciErr;
+// int iRows=0,iCols=0,i,j,k=0;
+// int *piChild = NULL;
+// int iPrec = 0,iItem = 0;
+// sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piChild);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// if(isIntegerType(pvApiCtx, piChild))
+// {
+// //getting precision
+// sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piChild, &iPrec);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// switch(iPrec)
+// {
+// case SCI_UINT8: //for unsigned integer 8
+// {
+// if(iItem==3)
+// {
+// unsigned char *pstDataR = NULL;
+// unsigned char *pstDataG = NULL;
+// unsigned char *pstDataB = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// //retrive the matrix of the G values
+// sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// //retrive the matrix of the B values
+// sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_8UC3);
+
+// /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+// k=0;
+// for(i=0;i<iRows;i++)
+// {
+// for(j=0;j<iCols;j++)
+// {
+// image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+// image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+// image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+// }
+// }
+// }
+// else
+// {
+// unsigned char *pstDataR = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_8UC1);
+
+// //Assigning matrix value to pixel
+// k=0;
+// for(i=0;i<iRows;i++)
+// for(j=0;j<iCols;j++)
+// image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+// }
+// break;
+// }
+// case SCI_UINT16: //for unsigned integer 16
+// {
+// if(iItem==3)
+// {
+// short unsigned int *pstDataR = NULL;
+// short unsigned int *pstDataG = NULL;
+// short unsigned int *pstDataB = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// //retrive the matrix of the G values
+// sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// //retrive the matrix of the B values
+// sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_16UC3);
+
+// //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+// k=0;
+// for(i=0;i<iRows;i++)
+// {
+// for(j=0;j<iCols;j++)
+// {
+// image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+// image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+// image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+// //i+iRows*j
+// }
+// }
+// }
+// else
+// {
+// short unsigned int *pstDataR = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_16UC1);
+
+// //Assigning matrix values to pixels
+// k=0;
+// for(i=0;i<iRows;i++)
+// for(j=0;j<iCols;j++)
+// image.at<ushort>(i,j)=pstDataR[i+iRows*j];
+// }
+// break;
+// }
+// case SCI_INT16: //for signed integer 16
+// {
+// if(iItem==3)
+// {
+// short int *pstDataR = NULL;
+// short int *pstDataG = NULL;
+// short int *pstDataB = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// //retrive the matrix of the G values
+// sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+// //retrive the matrix of the B values
+// sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_16SC3);
+
+// //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+// k=0;
+// for(i=0;i<iRows;i++)
+// {
+// for(j=0;j<iCols;j++)
+// {
+// image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+// image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+// image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+// }
+// }
+// }
+// else
+// {
+// short int *pstDataR = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_16SC1);
+
+// //Assigning image matrix values to pixels
+// k=0;
+// for(i=0;i<iRows;i++)
+// for(j=0;j<iCols;j++)
+// image.at<short>(i,j)=pstDataR[i+iRows*j];
+// }
+// break;
+// }
+// }
+// }
+// else //for floating point/ double precision values
+// {
+// if(iItem==3)
+// {
+// double *pstDataR = NULL;
+// double *pstDataG = NULL;
+// double *pstDataB = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// 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 the matrix of the B values
+// sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_64FC3);
+
+// //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+// k=0;
+// for(i=0;i<iRows;i++)
+// {
+// for(j=0;j<iCols;j++)
+// {
+// image.at<Vec3d>(i,j)[2]=pstDataR[i+iRows*j];
+// image.at<Vec3d>(i,j)[1]=pstDataG[i+iRows*j];
+// image.at<Vec3d>(i,j)[0]=pstDataB[i+iRows*j];
+// }
+// }
+// }
+// else
+// {
+// double *pstDataR = NULL;
+// //retrive the matrix of the R values
+// sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+// if(sciErr.iErr)
+// {
+// printError(&sciErr, 0);
+// return 0;
+// }
+
+// //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+// image = Mat(iRows,iCols,CV_64FC1);
+
+// //Assigning image matrix values to pixels
+// k=0;
+// for(i=0;i<iRows;i++)
+// for(j=0;j<iCols;j++)
+// image.at<double>(i,j)=pstDataR[i+iRows*j];
+// }
+// }
+// return 1;
+//}
+//function used to retrieve image matrix from Scilab environment
+/*
+ We need to retrieve image from the Scilab environment
+ We do this by getting a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int retrieveImage(Mat &image,int pos)
+{
+
+ SciErr sciErr;
+ int iRows=0,iCols=0,i,j,k=0;
+ int *piAddr = NULL;
+ int *piAddrChild = NULL;
+ int iPrec = 0,iItem = 0;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isIntegerType(pvApiCtx, piAddrChild))
+ {
+ //getting precision
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrChild, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8
+ {
+ if(iItem==2)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC2);
+
+ /*Now that we have the 2 matrices(R,G), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec2b>(i,j)[1]=pstDataR[i+iRows*j];
+ image.at<Vec2b>(i,j)[0]=pstDataG[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==3)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC3);
+
+ /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==4)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ unsigned char *pstDataA = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the A values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 4, &iRows, &iCols, &pstDataA);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC4);
+
+ /*Now that we have the 4 matrices(R,G,B,A), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec4b>(i,j)[3]=pstDataA[i+iRows*j];
+ image.at<Vec4b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec4b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec4b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ unsigned char *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC1);
+
+ //Assigning matrix value to pixel
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_INT8: //for signed integer 8
+ {
+ if(iItem==2)
+ {
+ char *pstDataR = NULL;
+ char *pstDataG = NULL;
+
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8SC2);
+
+ /*Now that we have the 2 matrices(R,G), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec2b>(i,j)[1]=pstDataR[i+iRows*j];
+ image.at<Vec2b>(i,j)[0]=pstDataG[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==3)
+ {
+ char *pstDataR = NULL;
+ char *pstDataG = NULL;
+ char *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8SC3);
+
+ /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==4)
+ {
+ char *pstDataR = NULL;
+ char *pstDataG = NULL;
+ char *pstDataB = NULL;
+ char *pstDataA = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the A values
+ sciErr = getMatrixOfInteger8InList(pvApiCtx, piAddr, 4, &iRows, &iCols, &pstDataA);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8SC4);
+
+ /*Now that we have the 4 matrices(R,G,B,A), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec4b>(i,j)[3]=pstDataA[i+iRows*j];
+ image.at<Vec4b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec4b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec4b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ unsigned char *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC1);
+
+ //Assigning matrix value to pixel
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16
+ {
+ if(iItem==2)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 16-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC2);
+
+ //Now that we have the 2 matrices(R,G), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec2s>(i,j)[1]=pstDataR[i+iRows*j];
+ image.at<Vec2s>(i,j)[0]=pstDataG[i+iRows*j];
+
+ }
+ }
+ }
+ else if(iItem==3)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+ short unsigned int *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ //i+iRows*j
+ }
+ }
+ }
+
+ else if(iItem==4)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+ short unsigned int *pstDataB = NULL;
+ short unsigned int *pstDataA = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the A values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 4, &iRows, &iCols, &pstDataA);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC4);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec4s>(i,j)[3]=pstDataA[i+iRows*j];
+ image.at<Vec4s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec4s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec4s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ short unsigned int *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC1);
+
+ //Assigning matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<ushort>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_INT16: //for signed integer 16
+ {
+ if(iItem==2)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC2);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec2s>(i,j)[1]=pstDataR[i+iRows*j];
+ image.at<Vec2s>(i,j)[0]=pstDataG[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==3)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+ short int *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==4)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+ short int *pstDataB = NULL;
+ short int *pstDataA = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 4, &iRows, &iCols, &pstDataA);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC4);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec4s>(i,j)[3]=pstDataA[i+iRows*j];
+ image.at<Vec4s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec4s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec4s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ short int *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<short>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+
+ case SCI_INT32: //for signed integer 32
+ {
+ if(iItem==2)
+ {
+ int *pstDataR = NULL;
+ int *pstDataG = NULL;
+
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_32SC2);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec2i>(i,j)[1]=pstDataR[i+iRows*j];
+ image.at<Vec2i>(i,j)[0]=pstDataG[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==3)
+ {
+ int *pstDataR = NULL;
+ int *pstDataG = NULL;
+ int *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_32SC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3i>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3i>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3i>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else if(iItem==4)
+ {
+ int *pstDataR = NULL;
+ int *pstDataG = NULL;
+ int *pstDataB = NULL;
+ int *pstDataA = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 4, &iRows, &iCols, &pstDataA);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_32SC4);
+
+ //Now that we have the 4 matrices(R,G,B,A), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec4i>(i,j)[3]=pstDataA[i+iRows*j];
+ image.at<Vec4i>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec4i>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec4i>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ int *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_32SC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<int>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ }
+ }
+
+
+ else //for floating point/ double precision values
+ {
+ if(iItem==2)
+ {
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ 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;
+ }
+
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC2);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec2d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec2d>(i,j)[1]=pstDataG[i+iRows*j];
+
+ }
+ }
+ }
+ else if(iItem==3)
+ {
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ 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 the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC3);
+
+ //Now that we have the 4 matrices(R,G,B,A), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+
+ image.at<Vec4d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec4d>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec4d>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ if(iItem==4)
+ {
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ double *pstDataA = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ 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 the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the A values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 4, &iRows, &iCols, &pstDataA);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC4);
+
+ //Now that we have the 4 matrices(R,G,B,A), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec4d>(i,j)[3]=pstDataA[i+iRows*j];
+ image.at<Vec4d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec4d>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec4d>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ double *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<double>(i,j)=pstDataR[i+iRows*j];
+ }
+ }
+ return 1;
+}
+
+
+//function that returns an image matrix to the Scilab environment
+/*
+ What we now need, is to pass the image matrix to the Scilab environment.
+ We do this by passing a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int returnImage(char *checker,Mat img,int pos)
+{
+ int i,j,k=0;
+ int *piAddrNew = NULL;
+ SciErr sciErr;
+
+ int num=img.channels(); //num now contains no. of channels of the image
+ //creating the list that will be passed to the Scilab enviroment
+ if(num==1)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 1, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ else if(num==2)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 2, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ }
+ else if(num==3)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ else if(num==4)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 4, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ else
+ sciprint("Image channel number not supported");
+
+
+ if(strcmp(checker,"8U")==0) //for Unsigned Integer 8
+ {
+
+ if(num==2)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *g = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+
+ //The next block of code retrieves the RG values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec2b intensity = img.at<Vec2b>(i, j);
+ r [i+img.rows*j]=intensity.val[1];
+ g [i+img.rows*j]=intensity.val[0];
+
+ }
+ }
+
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *g = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *b = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+
+ //The next block of code retrieves the RGBA values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i, j);
+
+ r [i+img.rows*j]=intensity.val[2];
+ g [i+img.rows*j]=intensity.val[1];
+ b [i+img.rows*j]=intensity.val[0];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+
+ else if(num==4)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *g = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *b = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *a = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the RGBA values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec4b intensity = img.at<Vec4b>(i, j);
+ a [i+img.rows*j]=intensity.val[3];
+ r [i+img.rows*j]=intensity.val[2];
+ g [i+img.rows*j]=intensity.val[1];
+ b [i+img.rows*j]=intensity.val[0];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the A value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 4, img.rows,img.cols, a);
+ free(a);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<uchar>(i, j);
+
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"8S")==0) //for signed Integer 8
+ {
+
+ if(num==2)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ char *r = (char *)malloc(img.rows * img.cols * sizeof(char));
+ char *g = (char *)malloc(img.rows * img.cols * sizeof(char));
+
+
+ //The next block of code retrieves the RG values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec2b intensity = img.at<Vec2b>(i, j);
+ r [i+img.rows*j]=intensity.val[1];
+ g [i+img.rows*j]=intensity.val[0];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ }
+
+ else if(num==3)
+ {
+
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ char *r = (char *)malloc(img.rows * img.cols * sizeof(char));
+ char *g = (char *)malloc(img.rows * img.cols * sizeof(char));
+ char *b = (char *)malloc(img.rows * img.cols * sizeof(char));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i, j);
+ r [i+img.rows*j]=intensity.val[2];
+ g [i+img.rows*j]=intensity.val[1];
+ b [i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else if(num==4)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ char *r = (char *)malloc(img.rows * img.cols * sizeof(char));
+ char *g = (char *)malloc(img.rows * img.cols * sizeof(char));
+ char *b = (char *)malloc(img.rows * img.cols * sizeof(char));
+ char *a = (char *)malloc(img.rows * img.cols * sizeof(char));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec4b intensity = img.at<Vec4b>(i, j);
+ a [i+img.rows*j]=intensity.val[3];
+ r [i+img.rows*j]=intensity.val[2];
+ g [i+img.rows*j]=intensity.val[1];
+ b [i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the A value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 4, img.rows,img.cols, a);
+ free(a);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ char *r = (char *)malloc(img.rows * img.cols * sizeof(char));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<char>(i, j);
+
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"16U")==0) //for Unsigned Integer 16
+ {
+
+ if(num==2)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *g = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec2s intensity = img.at<Vec2s>(i, j);
+ r[i+img.rows*j]=intensity.val[1];
+ g[i+img.rows*j]=intensity.val[0];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+
+ else if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *g = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *b = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else if(num==4)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *g = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *b = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *a = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec4s intensity = img.at<Vec4s>(i, j);
+ a[i+img.rows*j]=intensity.val[3];
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 4, img.rows,img.cols, a);
+ free(a);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<ushort>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ }
+ else if(strcmp(checker,"16S")==0) //for Signed Integer 16
+ {
+
+ if(num==2)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *g = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec2s intensity = img.at<Vec2s>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ }
+
+ else if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *g = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *b = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else if(num==4)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *g = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *b = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *a = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec4s intensity = img.at<Vec4s>(i, j);
+ a[i+img.rows*j]=intensity.val[3];
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the A value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 4, img.rows,img.cols,a);
+ free(a);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<short>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"32S")==0) //for Signed Integer 16
+ {
+
+ if(num==2)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *g = (int *)malloc(img.rows * img.cols * sizeof(int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec2i intensity = img.at<Vec2i>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+
+ else if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *g = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *b = (int *)malloc(img.rows * img.cols * sizeof(int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3i intensity = img.at<Vec3i>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else if(num==4)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *g = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *b = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *a = (int *)malloc(img.rows * img.cols * sizeof(int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec4i intensity = img.at<Vec4i>(i, j);
+ a[i+img.rows*j]=intensity.val[3];
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the A value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 4, img.rows,img.cols,a);
+ free(a);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<int>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+
+ else if(strcmp(checker,"32F")==0) //for Float 32
+ {
+
+
+ if(num==2)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec2d intensity = img.at<Vec2d>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else if(num==4)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *a = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec4d intensity = img.at<Vec4d>(i, j);
+ a[i+img.rows*j]=intensity.val[3];
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the A value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 4, img.rows,img.cols,a);
+ free(a);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<float>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+ else if(strcmp(checker,"64F")==0) //For Float 64
+ {
+
+ if(num==2)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec2d intensity = img.at<Vec2d>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else if(num==4)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *a = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ a[i+img.rows*j]=intensity.val[3];
+ r[i+img.rows*j]=intensity.val[2];
+ g[i+img.rows*j]=intensity.val[1];
+ b[i+img.rows*j]=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the A value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 4, img.rows,img.cols, a);
+ free(a);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ r[i+img.rows*j]=img.at<double>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+
+}
diff --git a/sci_gateway1/cpp/common3.cpp b/sci_gateway1/cpp/common3.cpp
new file mode 100644
index 0000000..45879a4
--- /dev/null
+++ b/sci_gateway1/cpp/common3.cpp
@@ -0,0 +1,925 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+//takes the matrix type as parameter and returns a string of the type
+string type2str(int type)
+{
+ string r;
+ uchar depth = type & CV_MAT_DEPTH_MASK;
+ switch ( depth )
+ {
+ case CV_8U: r = "8U"; break;
+ case CV_8S: r = "8S"; break;
+ case CV_16U: r = "16U"; break;
+ case CV_16S: r = "16S"; break;
+ case CV_32S: r = "32S"; break;
+ case CV_32F: r = "32F"; break;
+ case CV_64F: r = "64F"; break;
+ default: r = "User"; break;
+ }
+ return r;
+}
+
+//takes matrix type as parameter and returns no. of channels of the image matrix
+int no_of_channels(int type)
+{
+ uchar chans = 1 + (type >> CV_CN_SHIFT);
+ return chans;
+}
+
+//function used to retrieve image matrix from Scilab environment
+/*
+ We need to retrieve image from the Scilab environment
+ We do this by getting a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int retrieveImage(Mat &image,int pos)
+{
+
+ SciErr sciErr;
+ int iRows=0,iCols=0,i,j,k=0;
+ int *piAddr = NULL;
+ int *piAddr1 = NULL;
+ int *piAddrChild = NULL;
+ int iPrec = 0,iItem = 0;
+ int r=0,c=0;
+
+ //retrieving number of items in the list and type of data(integer/float)
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+
+
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isIntegerType(pvApiCtx, piAddrChild))
+ {
+ //getting precision
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrChild, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8
+ {
+
+ if(iItem==3)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciprint("testing");
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(r=0;r<iRows;r++)
+ {
+ for (c=0;c<iCols;c++)
+ {
+ sciprint("m=%d\n",pstDataR[r+iRows*c]);
+ }
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+
+
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC3);
+
+ /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ unsigned char *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC1);
+
+ //Assigning matrix value to pixel
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16
+ {
+
+ if(iItem==3)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+ short unsigned int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ //i+iRows*j
+ }
+ }
+ }
+ else
+ {
+ short unsigned int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC1);
+
+ //Assigning matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<ushort>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_INT16: //for signed integer 16
+ {
+
+ if(iItem==3)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+ short int *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ short int *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<short>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ }
+ }
+ else //for floating point/ double precision values
+ {
+
+ if(iItem==3)
+ {
+
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&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,pos,&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,pos,&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;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3d>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3d>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+
+ }
+ else
+ {
+
+ double *pstDataR = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,pos,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<double>(i,j)=pstDataR[i+iRows*j];
+ }
+ }
+ return 1;
+}
+
+//function that returns an image matrix to the Scilab environment
+/*
+ What we now need, is to pass the image matrix to the Scilab environment.
+ We do this by passing a List of 2-D matrices. The size of the list, in our case is known(either 3 or 1,
+ 3 for a coloured image and 1 for a grayscale image), hence we do not require the dynamic capability of a list.
+ Incase of a 3-channel image, the first matrix will be a matrix with dimensions img.rows X img.cols, and will denote the R(red)
+ values of the image. Similarly, the second will have the G(green) values, and the third will have B(blue) values.
+ For a single-channeled image, we will have only a single matrix
+*/
+int returnImage(char *checker,Mat img,int pos)
+{
+ int i,j,k=0;
+ int *piAddrNew = NULL;
+ SciErr sciErr;
+ int num=no_of_channels(img.type()); //num now contains no. of channels of the image
+ //creating the list that will be passed to the Scilab enviroment
+ if(num==3)
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 3, &piAddrNew);
+ else
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + pos, 1, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(strcmp(checker,"8U")==0) //for Unsigned Integer 8
+ {
+ if(num==3)
+ {
+
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *g = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+ unsigned char *b = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i, j);
+ *(r + j*img.rows + i)=intensity.val[2];
+ *(g + j*img.rows + i)=intensity.val[1];
+ *(b + j*img.rows + i)=intensity.val[0];
+ }
+ }
+
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ unsigned char *r = (unsigned char *)malloc(img.rows * img.cols * sizeof(unsigned char));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<uchar>(i, j);
+
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"16U")==0) //for Unsigned Integer 16
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *g = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+ short unsigned int *b = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short unsigned int *r = (short unsigned int *)malloc(img.rows * img.cols * sizeof(short unsigned int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<ushort>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ }
+ else if(strcmp(checker,"16S")==0) //for Signed Integer 16
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *g = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ short int *b = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3s intensity = img.at<Vec3s>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ short int *r = (short int *)malloc(img.rows * img.cols * sizeof(short int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<short>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+ else if(strcmp(checker,"32S")==0) //for Signed Integer 16
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *g = (int *)malloc(img.rows * img.cols * sizeof(int));
+ int *b = (int *)malloc(img.rows * img.cols * sizeof(int));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3i intensity = img.at<Vec3i>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ int *r = (int *)malloc(img.rows * img.cols * sizeof(int));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<int>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ }
+
+ else if(strcmp(checker,"32F")==0) //for Float 32
+ {
+ if(num==3)
+ {
+
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols,b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows+ j)=img.at<float>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1,img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+ else if(strcmp(checker,"64F")==0) //For Float 64
+ {
+
+ if(num==3)
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *g = (double *)malloc(img.rows * img.cols * sizeof(double));
+ double *b = (double *)malloc(img.rows * img.cols * sizeof(double));
+ //The next block of code retrieves the RGB values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ {
+ for(j=0;j<img.cols;j++)
+ {
+ Vec3d intensity = img.at<Vec3d>(i, j);
+ *(r + i*img.rows + j)=intensity.val[2];
+ *(g + i*img.rows + j)=intensity.val[1];
+ *(b + i*img.rows + j)=intensity.val[0];
+ }
+ }
+
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols,r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 2, img.rows,img.cols,g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 3, img.rows,img.cols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ double *r = (double *)malloc(img.rows * img.cols * sizeof(double));
+
+ //The next block of code retrieves the image colour values at a specified pixel, and assigns it to the matrices
+ for(i=0;i<img.rows;i++)
+ for(j=0;j<img.cols;j++)
+ *(r + i*img.rows + j)=img.at<double>(i, j);
+
+ //Adding the image colour value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+pos , piAddrNew, 1, img.rows,img.cols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+
+}
diff --git a/sci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.c b/sci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.c
new file mode 100644
index 0000000..a504d15
--- /dev/null
+++ b/sci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.c
@@ -0,0 +1,30 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <mex.h>
+#include <sci_gateway.h>
+#include <api_scilab.h>
+#include <MALLOC.h>
+static int direct_gateway(char *fname,void F(void)) { F();return 0;};
+extern Gatefunc opencv_imread;
+static GenericTable Tab[]={
+ {(Myinterfun)sci_gateway,opencv_imread,"opencv_imread"},
+};
+
+int C2F(libFOSSEE_Image_Processing_Toolbox)()
+{
+ Rhs = Max(0, Rhs);
+ if (*(Tab[Fin-1].f) != NULL)
+ {
+ if(pvApiCtx == NULL)
+ {
+ pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
+ }
+ pvApiCtx->pstName = (char*)Tab[Fin-1].name;
+ (*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);
+ }
+ return 0;
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/sci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.so b/sci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.so
new file mode 100755
index 0000000..3a6dc7a
--- /dev/null
+++ b/sci_gateway1/cpp/libFOSSEE_Image_Processing_Toolbox.so
Binary files differ
diff --git a/sci_gateway1/cpp/libskeleton_imageprocessing.c b/sci_gateway1/cpp/libskeleton_imageprocessing.c
new file mode 100644
index 0000000..4fbf87c
--- /dev/null
+++ b/sci_gateway1/cpp/libskeleton_imageprocessing.c
@@ -0,0 +1,38 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include <mex.h>
+#include <sci_gateway.h>
+#include <api_scilab.h>
+#include <MALLOC.h>
+static int direct_gateway(char *fname,void F(void)) { F();return 0;};
+extern Gatefunc opencv_imread;
+extern Gatefunc opencv_imcrop;
+extern Gatefunc opencv_imresize;
+extern Gatefunc opencv_imsharpen;
+extern Gatefunc opencv_imwrite;
+static GenericTable Tab[]={
+ {(Myinterfun)sci_gateway_without_putlhsvar,opencv_imread,"opencv_imread"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,opencv_imcrop,"opencv_imcrop"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,opencv_imresize,"opencv_imresize"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,opencv_imsharpen,"opencv_imsharpen"},
+ {(Myinterfun)sci_gateway_without_putlhsvar,opencv_imwrite,"opencv_imwrite"},
+};
+
+int C2F(libskeleton_imageprocessing)()
+{
+ Rhs = Max(0, Rhs);
+ if (*(Tab[Fin-1].f) != NULL)
+ {
+ if(pvApiCtx == NULL)
+ {
+ pvApiCtx = (StrCtx*)MALLOC(sizeof(StrCtx));
+ }
+ pvApiCtx->pstName = (char*)Tab[Fin-1].name;
+ (*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);
+ }
+ return 0;
+}
+#ifdef __cplusplus
+}
+#endif
diff --git a/sci_gateway1/cpp/libskeleton_imageprocessing.so b/sci_gateway1/cpp/libskeleton_imageprocessing.so
new file mode 100755
index 0000000..0902c8b
--- /dev/null
+++ b/sci_gateway1/cpp/libskeleton_imageprocessing.so
Binary files differ
diff --git a/sci_gateway1/cpp/loader.sce b/sci_gateway1/cpp/loader.sce
new file mode 100644
index 0000000..15332b1
--- /dev/null
+++ b/sci_gateway1/cpp/loader.sce
@@ -0,0 +1,25 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce : Please, do not edit this file
+// ----------------------------------------------------------------------------
+//
+libskeleton_imagepr_path = get_absolute_file_path('loader.sce');
+//
+// ulink previous function with same name
+[bOK, ilib] = c_link('libskeleton_imageprocessing');
+if bOK then
+ ulink(ilib);
+end
+//
+list_functions = [ 'opencv_imread';
+ 'opencv_imcrop';
+ 'opencv_imresize';
+ 'opencv_imsharpen';
+ 'opencv_imwrite';
+];
+addinter(libskeleton_imagepr_path + filesep() + 'libskeleton_imageprocessing' + getdynlibext(), 'libskeleton_imageprocessing', list_functions);
+// remove temp. variables on stack
+clear libskeleton_imagepr_path;
+clear bOK;
+clear ilib;
+clear list_functions;
+// ----------------------------------------------------------------------------
diff --git a/sci_gateway1/cpp/opencv_BRISKPoints.cpp b/sci_gateway1/cpp/opencv_BRISKPoints.cpp
new file mode 100644
index 0000000..224686d
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_BRISKPoints.cpp
@@ -0,0 +1,113 @@
+/***************************************************
+Author : Shashank Shekhar
+***************************************************/
+
+#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_BRISKPoints(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int *piChild = NULL;
+ int iType = 0;
+ int iRows, iCols = 0;
+ double *matData = NULL;
+
+ double *OrientationData = NULL;
+ double *MetricData = NULL;
+ double *ScaleData = NULL;
+
+ CheckInputArgument(pvApiCtx, 1,1);
+ CheckOutputArgument(pvApiCtx,1,5);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix || isVarComplex(pvApiCtx, piAddr))
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &matData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iCols!=2)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ OrientationData = (double *)malloc(sizeof(double)*iRows);
+ MetricData = (double *)malloc(sizeof(double)*iRows);
+ ScaleData = (double *)malloc(sizeof(double)*iRows);
+
+ for(int i = 0 ; i<iRows; i++)
+ {
+ OrientationData[i] = 0;
+ MetricData[i] = 0;
+ ScaleData[i] = 12;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows,2, matData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, iRows,1, OrientationData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, iRows,1, MetricData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 4, iRows,1, ScaleData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ createScalarInteger32(pvApiCtx,nbInputArgument(pvApiCtx) + 5, iRows);
+
+ for(int i=1;i<=5;i++)
+ {
+ AssignOutputVariable(pvApiCtx, i) = nbInputArgument(pvApiCtx) + i;
+ }
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_BlockMatcher.cpp b/sci_gateway1/cpp/opencv_BlockMatcher.cpp
new file mode 100644
index 0000000..654e5c8
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_BlockMatcher.cpp
@@ -0,0 +1,606 @@
+/***************************************************
+Author : Tanmay Chaudhari, Shashank Shekhar
+ ***************************************************/
+
+#include <bits/stdc++.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+
+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"
+ //#include "../common.cpp"
+ vector<pair<long double, pair<int, int > > > madv, msev;
+ vector<pair<pair<int, int>, pair<int, int > > > v;
+
+ int opencv_BlockMatcher(char *fname, unsigned long fname_len)
+ {
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int maxm, itr;
+ int iRows = 0;
+ int iCols = 0;
+ int nbInputArguments = 0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ bool *providedArgs = NULL;
+ char *currentArg = NULL;
+ char **pstData = NULL;
+ double *blocksize = NULL;
+ double *maximumDisplacement = NULL;
+ double *overlap = NULL;
+ double *horizontal = NULL;
+ double *vertical = NULL;
+ double *magnitude = NULL;
+ string s,t;
+ string matchCriteria;
+ string outputValue;
+ Mat img, img1, img2;
+
+ //Check input output arguments
+ CheckInputArgument(pvApiCtx, 2, 12);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ if((nbInputArguments-2)%2!=0)
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+ providedArgs = (bool*)malloc(sizeof(bool) * 5);
+ for(int i=0;i<5;i++)
+ providedArgs[i] = 0;
+
+ //Read image
+ //retrieveImage(img, 1);
+ //cvtColor(img, img1, CV_BGR2GRAY);
+ //retrieveImage(img, 2);
+ //cvtColor(img, img2, CV_BGR2GRAY);
+
+ //Reading first image
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ img1 = imread(pstData[0], CV_LOAD_IMAGE_GRAYSCALE);
+
+ //Reading second image
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ img2 = imread(pstData[0], CV_LOAD_IMAGE_GRAYSCALE);
+
+ for(int iter=3;iter<=nbInputArguments;iter++)
+ {
+ // Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ // providedArgs[] makes sure that no optional argument is provided more than once
+
+ if(strcmp(currentArg,"BlockSize")==0)
+ {
+ if(!providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, iter);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &blocksize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1 || iCols!=2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument BlockSize.\n");
+ return 0;
+ }
+ if(blocksize[0]<=0 || blocksize[1]<=0)
+ {
+ Scierror(999, "Positive inputs for BlockSize needed.\n");
+ return 0;
+ }
+ providedArgs[0]=1;
+ }
+ else if(providedArgs[0])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "Overlap")==0)
+ {
+ if(!providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, iter);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &overlap);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1 || iCols!=2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument Overlap.\n");
+ return 0;
+ }
+ if(overlap[0]<0 || overlap[1]<0)
+ {
+ Scierror(999, "Non-negative inputs for Overlap needed\n");
+ return 0;
+ }
+ providedArgs[1]=1;
+
+ }
+ else if(providedArgs[1])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "MaximumDisplacement")==0)
+ {
+ if(!providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, iter);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &maximumDisplacement);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1 || iCols!=2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument MaximumDisplacement.\n");
+ return 0;
+ }
+ if(maximumDisplacement[0]<0 || maximumDisplacement[1]<0)
+ {
+ Scierror(999, "Non-negative inputs for Overlap needed\n");
+ return 0;
+ }
+ providedArgs[2]=1;
+
+ }
+ else if(providedArgs[2])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "MatchCriteria")==0)
+ {
+ if(!providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp(pstData[0],"Mean square error")==0)
+ matchCriteria = "Mean Square Error";
+ else if(strcmp(pstData[0], "Mean absolute difference")==0)
+ matchCriteria = " ";
+ else
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are Mean square error or Mean absolute difference.\n", currentArg);
+ return 0;
+ }
+ providedArgs[3]=1;
+ }
+ else if(providedArgs[3])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "OutputValue")==0)
+ {
+ if(!providedArgs[4])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp(pstData[0],"Magnitude-squared")==0)
+ outputValue = "Magnitude-squared";
+ else if(strcmp(pstData[0], "Horizontal and vertical components")==0)
+ outputValue = "Horizontal and vertical components";
+ else
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are Magnitude-squared or Horizontal and vertical components.\n", currentArg);
+ return 0;
+ }
+ providedArgs[4]=1;
+ }
+ else if(providedArgs[4])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ }
+
+ //Initialisaton
+ if(!providedArgs[0])
+ {
+ blocksize = (double*)malloc(sizeof(double) * 2);
+ blocksize[0] = 17;
+ blocksize[1] = 17;
+ }
+
+ if(!providedArgs[1])
+ {
+ overlap = (double*)malloc(sizeof(double) * 2);
+ overlap[0] = 0;
+ overlap[1] = 0;
+ }
+
+ if(!providedArgs[2])
+ {
+ maximumDisplacement = (double*)malloc(sizeof(double) * 2);
+ maximumDisplacement[0] = 7;
+ maximumDisplacement[1] = 7;
+ }
+
+ if(!providedArgs[3])
+ {
+ matchCriteria = "Mean Square Error";
+ }
+
+ if(!providedArgs[4])
+ {
+ outputValue = "Magnitude-squared";
+ }
+
+ if(outputValue == "Magnitude-squared")
+ {
+ magnitude = (double*)malloc(sizeof(double) * int(img1.rows) * int(img1.cols));
+ }
+ else
+ {
+ horizontal = (double*)malloc(sizeof(double) * int(img1.rows) * int(img1.cols));
+ vertical = (double*)malloc(sizeof(double) * int(img1.rows) * int(img1.cols));
+ }
+
+ iRows = iCols = 0;
+ for(int i=0;i<int(img1.rows);i+=int(blocksize[0])-int(overlap[0]))
+ {
+ if(i+int(blocksize[0])>=int(img1.rows))
+ break;
+ for(int j=0;j<int(img1.cols);j+=int(blocksize[1])-int(overlap[1]))
+ {
+ if(j+int(blocksize[1])>=int(img1.cols))
+ break;
+ madv.clear();
+ msev.clear();
+ for(int k=-int(maximumDisplacement[0]);k<=int(maximumDisplacement[0]);k++)
+ {
+ if((i+k>=int(img2.rows)) || (i+k+int(blocksize[0])>=int(img2.rows)))
+ break;
+ if(i+k<0)
+ continue;
+ for(int l=-int(maximumDisplacement[1]);l<=int(maximumDisplacement[1]);l++)
+ {
+ if((j+l>=int(img2.cols)) || (j+l+int(blocksize[1])>=int(img2.cols)))
+ break;
+ if(j+l<0)
+ continue;
+
+ long double mad = 0;
+ long double mse = 0;
+
+ for(int it1=0;it1<blocksize[0];it1++)
+ {
+ for(int it2=0;it2<blocksize[1];it2++)
+ {
+ long double cur1=img1.at<int>(i+it1,j+it2);
+ long double cur2=img2.at<int>(i+k+it1,j+l+it2);
+ long double error=cur1-cur2;
+ mad+=abs(error);
+ mad/=blocksize[0]*blocksize[1];
+ mse+=error*error;
+ mse/=blocksize[0]*blocksize[1];
+ }
+ }
+
+ madv.push_back(make_pair(mad,make_pair(i+k,j+l)));
+ msev.push_back(make_pair(mse,make_pair(i+k,j+l)));
+ }
+ }
+ if(outputValue == "Magnitude-squared")
+ {
+ sort(msev.begin(),msev.end());
+ if(msev.empty())
+ v.push_back(make_pair(make_pair(i,j),make_pair(i+int(blocksize[0]),j+int(blocksize[1]))));
+ else
+ v.push_back(make_pair(make_pair(i,j),msev[0].second));
+ }
+ else
+ {
+ sort(madv.begin(),madv.end());
+ if(madv.empty())
+ v.push_back(make_pair(make_pair(i,j),make_pair(i+int(blocksize[0]),j+int(blocksize[1]))));
+ else
+ v.push_back(make_pair(make_pair(i,j),madv[0].second));
+ }
+ iCols++;
+ }
+ iRows++;
+ }
+
+ if(outputValue == "Magnitude-squared")
+ {
+ //Creating list to store magnitude matrix in it
+ magnitude = (double*)malloc(sizeof(double) * int (v.size()));
+ for(int i=0;i<v.size();i++)
+ {
+ double mag = (v[i].second.first-v[i].first.first)*(v[i].second.first-v[i].first.first) + (v[i].second.second-v[i].first.second)*(v[i].second.second-v[i].first.second);
+ magnitude[i]=mag;
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, iRows, (iCols/iRows), magnitude);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //Creating list to store horizontal and vertical matrix in it
+ horizontal = (double*)malloc(sizeof(double) * int(v.size()));
+ vertical = (double*)malloc(sizeof(double) * int(v.size()));
+ for(int i=0;i<v.size();i++)
+ {
+ horizontal[i] = v[i].second.first-v[i].first.first;
+ vertical[i] = v[i].second.second-v[i].first.second;
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, iRows, (iCols/iRows), horizontal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 2, iRows, (iCols/iRows), vertical);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ //return output Arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ madv.clear();
+ msev.clear();
+ v.clear();
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_CascadeObjectDetector.cpp b/sci_gateway1/cpp/opencv_CascadeObjectDetector.cpp
new file mode 100644
index 0000000..49adad4
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_CascadeObjectDetector.cpp
@@ -0,0 +1,431 @@
+/********************************************************
+Author: Diwakar Bhardwaj
+*********************************************************
+Usage :return_image=insertObjectAnnotation(input_image,'object')
+
+where object can be mouth,nose,ear or upperbody etc.
+********************************************************/
+
+#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_CascadeObjectDetector(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piLen = NULL;
+ char **object = NULL;
+ double *bboxes = NULL;
+ int i,j,k=0,l=0;
+ double alpha, beta,x,n;
+
+ CascadeClassifier face_cascade;
+ CascadeClassifier eyes_cascade;
+ CascadeClassifier mouth_cascade;
+ CascadeClassifier nose_cascade;
+ CascadeClassifier upperbody_cascade;
+
+ vector<Rect>faces,eyes,mouth,nose,upperbody;
+ face_cascade.load("/home/diwakar/Desktop/opencv-2.4.9/data/haarcascades/haarcascade_frontalface_alt.xml");
+ eyes_cascade.load("/home/diwakar/Desktop/opencv-2.4.9/data/haarcascades/haarcascade_mcs_eyepair_big.xml");
+ mouth_cascade.load("/home/diwakar/Desktop/opencv-2.4.9/data/haarcascades/haarcascade_mcs_mouth.xml");
+ nose_cascade.load("/home/diwakar/Desktop/opencv-2.4.9/data/haarcascades/haarcascade_mcs_nose.xml");
+ upperbody_cascade.load("/home/diwakar/Desktop/opencv-2.4.9/data/haarcascades/haarcascade_mcs_upperbody.xml");
+
+ float eye_x1,eye_y1,eye_x2,eye_y2,mouth_x1,mouth_y1,mouth_x2,mouth_y2,nose_x1,nose_y1,nose_x2,nose_y2;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ Mat image,new_image,image_gray;
+
+ retrieveImage(image, 1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,2, &piAddr2);
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ object= (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ object[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen,object);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m;
+ double *bboxes = NULL;
+ bboxes = (double*)malloc(sizeof(double) * (int)answer.size() * 4);
+ int tbox=0;
+ //Converting image from rgb to gray scale image.
+ cvtColor( image, image_gray, CV_BGR2GRAY );
+ //equalizing the histrogram of gray scale image
+ equalizeHist( image_gray, image_gray );
+
+ face_cascade.detectMultiScale( image, faces, 1.2,2,CV_HAAR_SCALE_IMAGE | CV_HAAR_DO_CANNY_PRUNING, cvSize(0,0), cvSize(255,255) );
+ if(strcmp(object[0],"face")==0)
+ {
+ for( int i = 0; i < faces.size(); i++ )
+ {
+<<<<<<< HEAD
+ tbox = (int)faces.Size();
+ bboxes[i + 0 * (int)faces.size()] = faces[i].x;
+ bboxes[i + 1 * (int)faces.size()] = faces[i].y;
+ bboxes[i + 2 * (int)faces.size()] = faces[i].width;
+ bboxes[i + 3 * (int)faces.size()] = faces[i].height;
+=======
+>>>>>>> c6d5c3d8dbf4db6da6d7ac081918599b6977960a
+
+ Point point1( faces[i].x + faces[i].width, faces[i].y + faces[i].height );
+ Point point2( faces[i].x, faces[i].y);
+ rectangle(image,point1,point2,cvScalar(0,255,0),1,16,0);
+<<<<<<< HEAD
+ Mat faceROI = image_gray( faces[i] );
+
+ eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+
+ for( int j = 0; j < eyes.size(); j++ )
+ {
+ Point point3( faces[i].x + eyes[j].x + eyes[j].width, faces[i].y + eyes[j].y + eyes[j].height );
+ Point point4(faces[i].x + eyes[j].x, faces[i].y + eyes[j].y );
+
+ //rectangle(image,point3,point4,cvScalar(0,0,255),1,8,0);
+ }
+ eye_x1=faces[0].x + eyes[0].x + eyes[0].width;
+ eye_y1=faces[0].y + eyes[0].y + eyes[0].height;
+ eye_x2=faces[0].x + eyes[0].x;
+ eye_y2=faces[0].y + eyes[0].y;
+
+ nose_cascade.detectMultiScale( faceROI, nose, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < nose.size(); j++ )
+ {
+ if((faces[i].x +nose[j].x + nose[j].width)<eye_x1 && (faces[i].y + nose[j].y + nose[j].height)>eye_y1)
+ if((faces[i].x +nose[j].x)>eye_x2)
+ {
+ Point point7(faces[i].x +nose[j].x + nose[j].width,faces[i].y + nose[j].y + nose[j].height );
+ Point point8(faces[i].x +nose[j].x,faces[i].y+nose[j].y );
+
+ //rectangle(image,point7,point8,cvScalar(255,255,0),1,8,0);
+ m=j;
+
+ }
+ }
+
+ nose_x1=faces[0].x + nose[m].x + nose[m].width;
+ nose_y1=faces[0].y + nose[m].y + nose[m].height;
+ nose_x2=faces[0].x + nose[m].x;
+ nose_y2=faces[0].y + nose[m].y;
+
+ mouth_cascade.detectMultiScale( faceROI, mouth, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < mouth.size(); j++ )
+ {
+
+ if((faces[i].x +mouth[j].x + mouth[j].width)<eye_x1 && (faces[i].x +mouth[j].x)>eye_x2)
+ {
+ if((faces[i].y + mouth[j].y + mouth[j].height)>(faces[i].y+nose[m].y +nose[m].height))
+ {
+ Point point5(faces[i].x +mouth[j].x + mouth[j].width,faces[i].y + mouth[j].y + mouth[j].height );
+ Point point6(faces[i].x +mouth[j].x,faces[i].y + mouth[j].y );
+
+ //rectangle(image,point5,point6,cvScalar(0,255,0),1,8,0);
+ m=j;
+ }
+ }
+ }
+ mouth_x1=faces[0].x + mouth[m].x + mouth[m].width;
+ mouth_y1=faces[0].y + mouth[m].y + mouth[m].height;
+ mouth_x2=faces[0].x + mouth[m].x;
+ mouth_y2=faces[0].y + mouth[m].y;
+=======
+>>>>>>> c6d5c3d8dbf4db6da6d7ac081918599b6977960a
+
+ }
+ }
+ else if(strcmp(object[0],"eyes")==0)
+ {
+ for( int i = 0; i < faces.size(); i++ )
+ {
+ Point point1( faces[i].x + faces[i].width, faces[i].y + faces[i].height );
+ Point point2( faces[i].x, faces[i].y);
+ //rectangle(image,point1,point2,cvScalar(0,255,0),1,16,0);
+ Mat faceROI = image_gray( faces[i] );
+
+ eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+
+ for( int j = 0; j < eyes.size(); j++ )
+ {
+ Point point3( faces[i].x + eyes[j].x + eyes[j].width, faces[i].y + eyes[j].y + eyes[j].height );
+ Point point4(faces[i].x + eyes[j].x, faces[i].y + eyes[j].y );
+
+ rectangle(image,point3,point4,cvScalar(0,0,255),1,8,0);
+ }
+ eye_x1=faces[0].x + eyes[0].x + eyes[0].width;
+ eye_y1=faces[0].y + eyes[0].y + eyes[0].height;
+ eye_x2=faces[0].x + eyes[0].x;
+ eye_y2=faces[0].y + eyes[0].y;
+
+ nose_cascade.detectMultiScale( faceROI, nose, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < nose.size(); j++ )
+ {
+ if((faces[i].x +nose[j].x + nose[j].width)<eye_x1 && (faces[i].y + nose[j].y + nose[j].height)>eye_y1)
+ if((faces[i].x +nose[j].x)>eye_x2)
+ {
+ Point point7(faces[i].x +nose[j].x + nose[j].width,faces[i].y + nose[j].y + nose[j].height );
+ Point point8(faces[i].x +nose[j].x,faces[i].y+nose[j].y );
+
+ //rectangle(image,point7,point8,cvScalar(255,255,0),1,8,0);
+ m=j;
+
+ }
+ }
+
+ nose_x1=faces[0].x + nose[m].x + nose[m].width;
+ nose_y1=faces[0].y + nose[m].y + nose[m].height;
+ nose_x2=faces[0].x + nose[m].x;
+ nose_y2=faces[0].y + nose[m].y;
+
+ mouth_cascade.detectMultiScale( faceROI, mouth, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < mouth.size(); j++ )
+ {
+
+ if((faces[i].x +mouth[j].x + mouth[j].width)<eye_x1 && (faces[i].x +mouth[j].x)>eye_x2)
+ {
+ if((faces[i].y + mouth[j].y + mouth[j].height)>(faces[i].y+nose[m].y +nose[m].height))
+ {
+ Point point5(faces[i].x +mouth[j].x + mouth[j].width,faces[i].y + mouth[j].y + mouth[j].height );
+ Point point6(faces[i].x +mouth[j].x,faces[i].y + mouth[j].y );
+
+ //rectangle(image,point5,point6,cvScalar(0,255,0),1,8,0);
+ m=j;
+ }
+ }
+ }
+ mouth_x1=faces[0].x + mouth[m].x + mouth[m].width;
+ mouth_y1=faces[0].y + mouth[m].y + mouth[m].height;
+ mouth_x2=faces[0].x + mouth[m].x;
+ mouth_y2=faces[0].y + mouth[m].y;
+
+ }
+ }
+ else if(strcmp(object[0],"nose")==0)
+ {
+ for( int i = 0; i < faces.size(); i++ )
+ {
+ Point point1( faces[i].x + faces[i].width, faces[i].y + faces[i].height );
+ Point point2( faces[i].x, faces[i].y);
+ //rectangle(image,point1,point2,cvScalar(0,255,0),1,16,0);
+ Mat faceROI = image_gray( faces[i] );
+
+ eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+
+ for( int j = 0; j < eyes.size(); j++ )
+ {
+ Point point3( faces[i].x + eyes[j].x + eyes[j].width, faces[i].y + eyes[j].y + eyes[j].height );
+ Point point4(faces[i].x + eyes[j].x, faces[i].y + eyes[j].y );
+
+ //rectangle(image,point3,point4,cvScalar(0,0,255),1,8,0);
+ }
+ eye_x1=faces[0].x + eyes[0].x + eyes[0].width;
+ eye_y1=faces[0].y + eyes[0].y + eyes[0].height;
+ eye_x2=faces[0].x + eyes[0].x;
+ eye_y2=faces[0].y + eyes[0].y;
+
+ nose_cascade.detectMultiScale( faceROI, nose, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < nose.size(); j++ )
+ {
+ if((faces[i].x +nose[j].x + nose[j].width)<eye_x1 && (faces[i].y + nose[j].y + nose[j].height)>eye_y1)
+ if((faces[i].x +nose[j].x)>eye_x2)
+ {
+ Point point7(faces[i].x +nose[j].x + nose[j].width,faces[i].y + nose[j].y + nose[j].height );
+ Point point8(faces[i].x +nose[j].x,faces[i].y+nose[j].y );
+
+ rectangle(image,point7,point8,cvScalar(255,255,0),1,8,0);
+ m=j;
+
+ }
+ }
+
+ nose_x1=faces[0].x + nose[m].x + nose[m].width;
+ nose_y1=faces[0].y + nose[m].y + nose[m].height;
+ nose_x2=faces[0].x + nose[m].x;
+ nose_y2=faces[0].y + nose[m].y;
+
+ mouth_cascade.detectMultiScale( faceROI, mouth, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < mouth.size(); j++ )
+ {
+
+ if((faces[i].x +mouth[j].x + mouth[j].width)<eye_x1 && (faces[i].x +mouth[j].x)>eye_x2)
+ {
+ if((faces[i].y + mouth[j].y + mouth[j].height)>(faces[i].y+nose[m].y +nose[m].height))
+ {
+ Point point5(faces[i].x +mouth[j].x + mouth[j].width,faces[i].y + mouth[j].y + mouth[j].height );
+ Point point6(faces[i].x +mouth[j].x,faces[i].y + mouth[j].y );
+ //rectangle(image,point5,point6,cvScalar(0,255,0),1,8,0);
+ m=j;
+ }
+ }
+ }
+ mouth_x1=faces[0].x + mouth[m].x + mouth[m].width;
+ mouth_y1=faces[0].y + mouth[m].y + mouth[m].height;
+ mouth_x2=faces[0].x + mouth[m].x;
+ mouth_y2=faces[0].y + mouth[m].y;
+
+ }
+ }
+ else if(strcmp(object[0],"mouth")==0)
+ {
+ for( int i = 0; i < faces.size(); i++ )
+ {
+ Point point1( faces[i].x + faces[i].width, faces[i].y + faces[i].height );
+ Point point2( faces[i].x, faces[i].y);
+ //rectangle(image,point1,point2,cvScalar(0,255,0),1,16,0);
+ Mat faceROI = image_gray( faces[i] );
+
+ eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+
+ for( int j = 0; j < eyes.size(); j++ )
+ {
+ Point point3( faces[i].x + eyes[j].x + eyes[j].width, faces[i].y + eyes[j].y + eyes[j].height );
+ Point point4(faces[i].x + eyes[j].x, faces[i].y + eyes[j].y );
+
+ //rectangle(image,point3,point4,cvScalar(0,0,255),1,8,0);
+ }
+ eye_x1=faces[0].x + eyes[0].x + eyes[0].width;
+ eye_y1=faces[0].y + eyes[0].y + eyes[0].height;
+ eye_x2=faces[0].x + eyes[0].x;
+ eye_y2=faces[0].y + eyes[0].y;
+
+ nose_cascade.detectMultiScale( faceROI, nose, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < nose.size(); j++ )
+ {
+ if((faces[i].x +nose[j].x + nose[j].width)<eye_x1 && (faces[i].y + nose[j].y + nose[j].height)>eye_y1)
+ if((faces[i].x +nose[j].x)>eye_x2)
+ {
+ Point point7(faces[i].x +nose[j].x + nose[j].width,faces[i].y + nose[j].y + nose[j].height );
+ Point point8(faces[i].x +nose[j].x,faces[i].y+nose[j].y );
+
+ //rectangle(image,point7,point8,cvScalar(255,255,0),1,8,0);
+ m=j;
+
+ }
+ }
+
+ nose_x1=faces[0].x + nose[m].x + nose[m].width;
+ nose_y1=faces[0].y + nose[m].y + nose[m].height;
+ nose_x2=faces[0].x + nose[m].x;
+ nose_y2=faces[0].y + nose[m].y;
+ mouth_cascade.detectMultiScale( faceROI, mouth, 1.1, 2, 0 |CV_HAAR_SCALE_IMAGE, Size(30, 30) );
+ for( int j = 0; j < mouth.size(); j++ )
+ {
+ if((faces[i].x +mouth[j].x + mouth[j].width)<eye_x1 && (faces[i].x +mouth[j].x)>eye_x2)
+ {
+ if((faces[i].y + mouth[j].y + mouth[j].height)>(faces[i].y+nose[m].y +nose[m].height))
+ {
+ Point point5(faces[i].x +mouth[j].x + mouth[j].width,faces[i].y + mouth[j].y + mouth[j].height );
+ Point point6(faces[i].x +mouth[j].x,faces[i].y + mouth[j].y );
+ //if(strcmp(object[0],"mouth")==0)
+ rectangle(image,point5,point6,cvScalar(0,255,0),1,8,0);
+ m=j;
+ }
+ }
+ }
+ mouth_x1=faces[0].x + mouth[m].x + mouth[m].width;
+ mouth_y1=faces[0].y + mouth[m].y + mouth[m].height;
+ mouth_x2=faces[0].x + mouth[m].x;
+ mouth_y2=faces[0].y + mouth[m].y;
+
+ }
+ }
+ else if(strcmp(object[0],"upper_body")==0)
+ {
+ upperbody_cascade.detectMultiScale( image_gray, upperbody, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(255, 255) );
+
+ for( int i = 0; i < upperbody.size(); i++ )
+ {
+ Rect t = upperbody[i];
+ t.y += 100;
+ rectangle(image, t, Scalar(255,255,255), 4, 8);
+ }
+ }
+ else
+ {
+ sciprint("Wrong object type");
+
+ }
+
+ //new_image=image;
+
+
+
+<<<<<<< HEAD
+ /*int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker); */
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, tbox, 4, bboxes);
+=======
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,image,1);
+ free(checker);
+ /*sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, tbox, 4, bboxes);
+>>>>>>> c6d5c3d8dbf4db6da6d7ac081918599b6977960a
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_DCT.cpp b/sci_gateway1/cpp/opencv_DCT.cpp
new file mode 100644
index 0000000..087c61b
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_DCT.cpp
@@ -0,0 +1,77 @@
+/********************************************************
+Author: Deepshikha
+return_image = DCT(source_image)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+using namespace cv;
+using namespace std;
+
+extern "C"{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+
+ int opencv_DCT(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j;
+ int flags = 0;
+
+ /// checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ if(image.channels() != 1){
+ Scierror(999, "Input should be single channel\n");
+ return 0;
+ }
+
+ /// even sized rows and columns required
+ if(image.rows%2 != 0){
+ Scierror(999, "%s: Odd number of rows found\n");
+ return 0;
+ }
+
+ if(image.cols%2 != 0){
+ Scierror(999, "%s: Odd number of columns found\n");
+ return 0;
+ }
+
+ /// transformed_idct stores the transformed image
+ Mat new_image(image.rows, image.cols, image.type());
+ dct(image, new_image, flags);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, new_image, 1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
+
diff --git a/sci_gateway1/cpp/opencv_Deinterlacer.cpp b/sci_gateway1/cpp/opencv_Deinterlacer.cpp
new file mode 100644
index 0000000..04db27f
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_Deinterlacer.cpp
@@ -0,0 +1,201 @@
+/********************************************************
+Author: Deepshikha
+return_image = Deinterlacer(source_image)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+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_Deinterlacer(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j, k , ch;
+ int iRows=0;
+ int iCols=0;
+ int *piAddr2=NULL;
+ int *piLen = 0;
+
+ // to specify deinterlacing method
+ char **method=NULL;
+
+ /// checking input argument
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ vector <uint> v;
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ /// new_image contains deinterlaced image of original image
+ Mat new_image(image.rows, image.cols, image.type());
+
+ int nbInputArguments = *getNbInputArgument(pvApiCtx);
+ if(nbInputArguments == 2)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ /// Retrieve string from input parameter. (requires 3 calls)
+ /// first to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //second call to retrieve length of each string
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ method = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ method[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, method);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // if second argument, method is Linear interpolation
+ if(strcmp(method[0],"Linear interpolation")==0)
+ {
+ for(i = 0; i < image.rows; i++)
+ {
+ for(j = 0; j < image.cols; j++)
+ {
+ if(i == image.rows-1)
+ {
+ if(i%2!=0)
+ new_image.at <uint> (i,j) = image.at <uint> (i-1,j);
+ else
+ new_image.at <uint> (i,j) = image.at <uint> (i,j);
+ }
+ else if(i%2 != 0 and i+1 < image.rows and i-1 >= 0)
+ new_image.at <uint> (i,j) = ( image.at <uint> (i-1,j) + image.at <uint> (i+1,j) ) / 2;
+ else
+ new_image.at <uint> (i,j) = image.at <uint> (i,j);
+ }
+ }
+ }
+
+ // if second argument, method is Vertical temporal median filtering
+ else if(strcmp(method[0],"Vertical temporal median filtering")==0)
+ {
+ for(i = 0; i < image.rows; i++)
+ {
+ for(j = 0;j < image.cols; j++)
+ {
+ v.clear();
+ if(i == image.rows-1)
+ {
+ if(i%2!=0)
+ new_image.at <uint> (i,j) = image.at <uint> (i-1,j);
+ else
+ new_image.at <uint> (i,j) = image.at <uint> (i,j);
+ }
+ else if(i%2 != 0 and i-1 >= 0 and i+1 < image.rows)
+ {
+ v.push_back( image.at <uint> (i-1,j) );
+ v.push_back( image.at <uint> (i,j) );
+ v.push_back( image.at <uint> (i+1,j) );
+
+ sort( v.begin(),v.end() ); // to find median
+
+ new_image.at <uint> (i,j) = v[1];
+ }
+ else
+ new_image.at <uint> (i,j) = image.at <uint> (i,j);
+ }
+ }
+ }
+
+ // if second argument, method is Line repetition
+ else if(strcmp(method[0],"Line repetition")==0)
+ {
+ for( i = 0; i < image.rows; i++ )
+ {
+ for(j = 0; j < image.cols; j++ )
+ {
+ if( i == image.rows-1 and i%2!=0 )
+ new_image.at <uint> (i,j,k) = image.at <uint> (i,j,k);
+ if( i%2 != 0 and i-1 >=0 )
+ new_image.at <uint> (i,j,k) = image.at <uint> (i-1,j,k);
+ else
+ new_image.at <uint> (i,j, k) = image.at<uint> (i,j,k);
+ }
+ }
+ }
+ // if any other invalid method name is passed as argument
+ else
+ {
+ Scierror(99,"Wrong method specified, use Linear interpolation or Vertical temporal median filtering or Line repetition as method name \n");
+ return 0;
+ }
+ }
+
+ // if no of input argument is 1 that is no method is specified then we use Line repetition method by default
+ else
+ {
+ for( i = 0; i < image.rows; i++ )
+ {
+ for(j = 0; j < image.cols; j++ )
+ {
+ if( i == image.rows-1 and i%2!=0 )
+ new_image.at <uint> (i,j,k) = image.at <uint> (i,j,k);
+ if( i%2 != 0 and i-1 >=0 )
+ new_image.at <uint> (i,j,k) = image.at <uint> (i-1,j,k);
+ else
+ new_image.at <uint> (i,j, k) = image.at<uint> (i,j,k);
+ }
+ }
+ }
+
+ // writing to scilab memory
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, new_image, 1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+/* ==================================================================== */
+}
+
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;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_ForegroundDetector.cpp b/sci_gateway1/cpp/opencv_ForegroundDetector.cpp
new file mode 100644
index 0000000..cd5bc9f
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_ForegroundDetector.cpp
@@ -0,0 +1,415 @@
+/***************************************************
+Author : Shashank Shekhar
+**************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <opencv2/video/background_segm.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"
+ //#include "../common.cpp"
+
+ bool fdAdaptLearningRate;
+ double fdNumTrainingFrames=-1;
+ double fdLearningRate=-1;
+ double fdMinimumBackgroundRatio=-1;
+ double fdNumGaussians=-1;
+ int iBool;
+ bool objectStatus;
+ Ptr<BackgroundSubtractor> fdObj;
+
+ int opencv_ForegroundDetector(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int *piAddrVal = NULL;
+ int iRows=0;
+ int iCols=0;
+ int flag;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ int noOfarguments;
+ double tempLearningRate;
+ Ptr<BackgroundSubtractor> obj;
+ int val_position;
+ int iv_bool=false;
+ int argPresence[6];
+ for(int i=0;i<6;i++)
+ argPresence[i]=0;
+
+ CheckInputArgument(pvApiCtx, 0,10);
+ CheckOutputArgument(pvApiCtx,1,5);
+
+ noOfarguments = *getNbInputArgument(pvApiCtx);
+
+ if(noOfarguments%2!=0)
+ {
+ Scierror(999," Invalid No of Arguments \n");
+ return 0;
+ }
+
+//----------------------------------------------------------------- Retrieving Arguments -------------------------------------------------------------------------------
+
+ for(int i=1;i<=noOfarguments;i+=2)
+ {
+
+ // first get the property
+ sciErr = getVarAddressFromPosition(pvApiCtx,i,&piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isStringType(pvApiCtx, piAddr))
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ //first call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j = 0 ; j < iRows * iCols ; j++)
+ {
+ pstData[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ currentArg = pstData[0];
+
+ if(strcmp(currentArg, "AdaptLearningRate")==0)
+ {
+ val_position = i+1;
+
+ if(argPresence[0]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isBooleanType(pvApiCtx, piAddrVal))
+ {
+ Scierror(999,"Invalid Value for AdaptLearningRate. A boolean value expected.\n");
+ return 0;
+ }
+
+ if(!isScalar(pvApiCtx, piAddrVal))
+ {
+ Scierror(999,"Invalid Value for AdaptLearningRate. A boolean value expected.\n");
+ return 0;
+ }
+ getScalarBoolean(pvApiCtx, piAddrVal, &iBool);
+ if(iBool == 0)
+ fdAdaptLearningRate = false;
+ else
+ fdAdaptLearningRate = true;
+
+ argPresence[0]=1;
+
+ }
+ else if(strcmp(currentArg, "NumTrainingFrames")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[1]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for NumTrainingFrames.\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &fdNumTrainingFrames);
+
+ if(fdNumTrainingFrames<0)
+ {
+ Scierror(999," Invalid Value for NumTrainingFrames. Enter a positive value\n");
+ return 0;
+ }
+ argPresence[1]=1;
+ }
+ else if(strcmp(currentArg, "LearningRate")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[2]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for LearningRate.\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &tempLearningRate);
+
+ if(tempLearningRate <0)
+ {
+ Scierror(999," Invalid Value for LearningRate. Enter a positive value\n");
+ return 0;
+ }
+ argPresence[2]=1;
+ }
+ else if(strcmp(currentArg, "MinimumBackgroundRatio")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[3]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for MinimumBackgroundRatio.\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &fdMinimumBackgroundRatio);
+
+ if(fdMinimumBackgroundRatio<0)
+ {
+ Scierror(999," Invalid Value for MinimumBackgroundRatio. Enter a positive value\n");
+ return 0;
+ }
+ argPresence[3]=1;
+
+ }
+ else if(strcmp(currentArg, "NumGaussians")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[4]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for NumGaussians.\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &fdNumGaussians);
+
+ if(fdNumGaussians<0)
+ {
+ Scierror(999," Invalid Value for NumGaussians. Enter a positive value\n");
+ return 0;
+ }
+ argPresence[4]=1;
+
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument %s\n", currentArg);
+ return 0;
+ }
+ }
+// --------------------------------------------- End of OIA --------------------------------------------------------
+ if(argPresence[1]==0)
+ fdNumTrainingFrames = 150;
+ if(argPresence[2]==0)
+ fdLearningRate = 0.005;
+ if(argPresence[3]==0)
+ fdMinimumBackgroundRatio = 0.7;
+ if(argPresence[4]==0)
+ fdNumGaussians = 5;
+
+ fdObj = new BackgroundSubtractorMOG(fdNumTrainingFrames,fdNumGaussians,fdMinimumBackgroundRatio);
+ objectStatus = true;
+// ------------------------------------------------------------------------------------------------------------------
+ if(fdAdaptLearningRate==true)
+ createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx)+1, 1);
+ else
+ createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx)+1, 0);
+
+ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+2, fdNumTrainingFrames);
+ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+3, fdMinimumBackgroundRatio);
+ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+4, fdNumGaussians);
+ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+5, fdLearningRate);
+
+ for(int i=1;i<=5;i++)
+ {
+ AssignOutputVariable(pvApiCtx, i) = nbInputArgument(pvApiCtx) + i;
+ }
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+ int opencv_readForegroundMask(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int *outList = NULL;
+ unsigned char *red = NULL;
+ unsigned char *green = NULL;
+ unsigned char *blue = NULL;
+
+ if(!objectStatus)
+ {
+ Scierror(999,"Set up Foreground Detection properties through Foreground Detector first.\n");
+ return 0;
+ }
+ CheckInputArgument(pvApiCtx, 1,1);
+ CheckOutputArgument(pvApiCtx,1,1);
+ Mat frame;
+ Mat foregoundMask;
+ retrieveImage(frame,1);
+ fdObj->operator()(frame, foregoundMask, fdLearningRate);
+
+ if(foregoundMask.channels()==1)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ red = (unsigned char *)malloc(sizeof(unsigned char)*foregoundMask.rows*foregoundMask.cols);
+
+ for(int k=0;k<foregoundMask.rows;k++)
+ for(int p=0;p<foregoundMask.cols;p++)
+ red[k+foregoundMask.rows*p]=foregoundMask.at<uchar>(k, p);
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, foregoundMask.rows, foregoundMask.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ }
+ else
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red = (unsigned char *)malloc(sizeof(unsigned char)*foregoundMask.rows*foregoundMask.cols);
+ green = (unsigned char *)malloc(sizeof(unsigned char)*foregoundMask.rows*foregoundMask.cols);
+ blue = (unsigned char *)malloc(sizeof(unsigned char)*foregoundMask.rows*foregoundMask.cols);
+
+ for(int k=0;k<foregoundMask.rows;k++)
+ {
+ for(int p=0;p<foregoundMask.cols;p++)
+ {
+ Vec3b intensity = foregoundMask.at<Vec3b>(k, p);
+ red[k+foregoundMask.rows*p]=intensity.val[2];
+ green[k+foregoundMask.rows*p]=intensity.val[1];
+ blue[k+foregoundMask.rows*p]=intensity.val[0];
+ }
+ }
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, foregoundMask.rows, foregoundMask.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 2, foregoundMask.rows, foregoundMask.cols, green);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 3, foregoundMask.rows, foregoundMask.cols, blue);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ free(green);
+ free(blue);
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_GeometricShearer.cpp b/sci_gateway1/cpp/opencv_GeometricShearer.cpp
new file mode 100644
index 0000000..382de19
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_GeometricShearer.cpp
@@ -0,0 +1,178 @@
+/********************************************************
+Author: Diwakar Bhardwaj
+*********************************************************
+Usage :return_image=GeometricShearer(input_image,'direction',value)
+value is the amount want to shear the image in given direction
+********************************************************/
+
+#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_GeometricShearer(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piLen = NULL;
+ char **direction = NULL;
+ int i,j,k;
+ double alpha, beta,x,n,value;
+
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx,3,3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ Mat image,new_image;
+
+ retrieveImage(image, 1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,2, &piAddr2);
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ direction = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ direction[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, direction);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&value);
+ if(intErr)
+ return intErr;
+
+ int r1, c1; // tranformed point
+ int rows, cols; // original image rows and columns
+ rows = image.rows;
+ cols = image.cols;
+ if(strcmp(direction[0], "Horizontal") == 0)
+ {
+ double Bx = value;
+ double By = 0;
+
+ int maxXOffset = abs(cols * Bx);
+ int maxYOffset = abs(rows * By);
+
+ Mat out = Mat::ones(image.rows+maxYOffset, image.cols+maxXOffset, image.type());
+
+ for(int r = 0; r < out.rows; r++)
+ {
+ for(int c = 0; c < out.cols; c++)
+ {
+ r1 = r + c * By - maxYOffset;
+ c1 = r * Bx + c - maxXOffset;
+
+ if(r1 >= 0 && r1 <= rows && c1 >= 0 && c1 <= cols)
+ {
+ out.at<uchar>(r, c) = image.at<uchar>(r1, c1);
+ }
+
+ }
+ }
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(out.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,out,1);
+ free(checker);
+ }
+ else if(strcmp(direction[0], "Vertical") == 0)
+ {
+ double Bx = 0;
+ double By = value;
+
+ int maxXOffset = abs(cols * Bx);
+ int maxYOffset = abs(rows * By);
+
+ Mat out = Mat::ones(image.rows+maxYOffset, image.cols+maxXOffset, image.type());
+
+ for(int r = 0; r < out.rows; r++)
+ {
+ for(int c = 0; c < out.cols; c++)
+ {
+ r1 = r + c * By - maxYOffset;
+ c1 = r * Bx + c - maxXOffset;
+
+ if(r1 >= 0 && r1 <= rows && c1 >= 0 && c1 <= cols)
+ {
+ out.at<uchar>(r, c) = image.at<uchar>(r1, c1);
+ }
+
+ }
+ }
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(out.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,out,1);
+ free(checker);
+
+ }
+ else
+ {
+ sciprint("Not valid 2nd argument");
+ }
+
+
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_HistogramBasedTracker.cpp b/sci_gateway1/cpp/opencv_HistogramBasedTracker.cpp
new file mode 100644
index 0000000..6d67886
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_HistogramBasedTracker.cpp
@@ -0,0 +1,257 @@
+/***************************************************
+Author : Tanmay Chaudhari
+ ***************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <bits/stdc++.h>
+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"
+//#include "../common.cpp"
+
+ Mat image;
+ bool backprojMode = false;
+ bool selectObject = false;
+ int trackObject = 0;
+ Point origin;
+ Rect selection;
+ int vmin = 10, vmax = 256, smin = 30;
+ double xcord[1<<20];
+ double ycord[1<<20];
+ double width[1<<20];
+ double height[1<<20];
+ double orientation[1<<20];
+
+ static void onMouse( int event, int x, int y, int, void* )
+ {
+ if( selectObject )
+ {
+ selection.x = MIN(x, origin.x);
+ selection.y = MIN(y, origin.y);
+ selection.width = std::abs(x - origin.x);
+ selection.height = std::abs(y - origin.y);
+
+ selection &= Rect(0, 0, image.cols, image.rows);
+ }
+
+ switch( event )
+ {
+ case EVENT_LBUTTONDOWN:
+ origin = Point(x,y);
+ selection = Rect(x,y,0,0);
+ selectObject = true;
+ break;
+ case EVENT_LBUTTONUP:
+ selectObject = false;
+ if( selection.width > 0 && selection.height > 0 )
+ trackObject = -1;
+ break;
+ }
+ }
+
+ int opencv_HistogramBasedTracker()
+ {
+ SciErr sciErr;
+ int* piAddr = NULL;
+ int iRows = 0;
+ int iter = 0;
+ int iCols = 0;
+ int iRet = 0;
+ char** pstData = NULL;
+
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 2);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ iRet = getAllocatedMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, &pstData);
+ if(iRet)
+ {
+ freeAllocatedMatrixOfString(iRows, iCols, pstData);
+ return iRet;
+ }
+ sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pstData);
+ if(sciErr.iErr)
+ {
+ freeAllocatedMatrixOfString(iRows, iCols, pstData);
+ printError(&sciErr, 0);
+ return sciErr.iErr;
+ }
+
+ VideoCapture cap(pstData[0]);
+ Rect trackWindow;
+ int hsize = 16;
+ float hranges[] = {0,180};
+ const float* phranges = hranges;
+ namedWindow( "Video Player", 0 );
+ setMouseCallback( "Video Player", onMouse, 0 );
+
+ Mat frame, hsv, hue, mask, hist, histimg = Mat::zeros(200, 320, CV_8UC3), backproj;
+ bool paused = false;
+
+ for(;;)
+ {
+ if( !paused)
+ {
+ cap >> frame;
+ if( frame.empty() )
+ break;
+ }
+
+ frame.copyTo(image);
+
+ if( !paused )
+ {
+ cvtColor(image, hsv, COLOR_BGR2HSV);
+
+ if( trackObject )
+ {
+ int _vmin = vmin, _vmax = vmax;
+
+ inRange(hsv, Scalar(0, smin, MIN(_vmin,_vmax)),
+ Scalar(180, 256, MAX(_vmin, _vmax)), mask);
+ int ch[] = {0, 0};
+ hue.create(hsv.size(), hsv.depth());
+ mixChannels(&hsv, 1, &hue, 1, ch, 1);
+
+ if( trackObject < 0 )
+ {
+ Mat roi(hue, selection), maskroi(mask, selection);
+ calcHist(&roi, 1, 0, maskroi, hist, 1, &hsize, &phranges);
+ normalize(hist, hist, 0, 255, NORM_MINMAX);
+
+ trackWindow = selection;
+ trackObject = 1;
+
+ histimg = Scalar::all(0);
+ int binW = histimg.cols / hsize;
+ Mat buf(1, hsize, CV_8UC3);
+ for( int i = 0; i < hsize; i++ )
+ buf.at<Vec3b>(i) = Vec3b(saturate_cast<uchar>(i*180./hsize), 255, 255);
+ cvtColor(buf, buf, COLOR_HSV2BGR);
+
+ for( int i = 0; i < hsize; i++ )
+ {
+ int val = saturate_cast<int>(hist.at<float>(i)*histimg.rows/255);
+ rectangle( histimg, Point(i*binW,histimg.rows),
+ Point((i+1)*binW,histimg.rows - val),
+ Scalar(buf.at<Vec3b>(i)), -1, 8 );
+ }
+ }
+
+ calcBackProject(&hue, 1, 0, hist, backproj, &phranges);
+ backproj &= mask;
+ RotatedRect trackBox = CamShift(backproj, trackWindow,
+ TermCriteria( TermCriteria::EPS | TermCriteria::COUNT, 10, 1 ));
+ if( trackWindow.area() <= 1 )
+ {
+ int cols = backproj.cols, rows = backproj.rows, r = (MIN(cols, rows) + 5)/6;
+ trackWindow = Rect(trackWindow.x - r, trackWindow.y - r,
+ trackWindow.x + r, trackWindow.y + r) &
+ Rect(0, 0, cols, rows);
+ }
+
+ if( backprojMode )
+ cvtColor( backproj, image, COLOR_GRAY2BGR );
+ ellipse( image, trackBox, Scalar(0,0,255), 3, 16 );
+ xcord[iter] = trackBox.center.x;
+ ycord[iter] = trackBox.center.y;
+ width[iter] = trackBox.size.width;
+ height[iter] = trackBox.size.height;
+ orientation[iter] = trackBox.angle;
+ iter++;
+ }
+
+ }
+ else if( trackObject < 0 )
+ paused = false;
+
+ if( selectObject && selection.width > 0 && selection.height > 0 )
+ {
+ Mat roi(image, selection);
+ bitwise_not(roi, roi);
+ }
+ imshow( "Video Player", image );
+ char c = (char)waitKey(20);
+ if( c == 27 )
+ break;
+ else if(c == 32)
+ paused = !paused;
+ else;
+ waitKey(20);
+ }
+ destroyAllWindows();
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, 1, iter, xcord);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 2, 1, iter, ycord);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 3, 1, iter, width);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 4, 1, iter, height);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, piAddr, 1, 1, iter, orientation);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ ReturnArguments(pvApiCtx);
+ backprojMode = false;
+ selectObject = false;
+ trackObject = 0;
+ return 0;
+ }
+ /* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_IDCT.cpp b/sci_gateway1/cpp/opencv_IDCT.cpp
new file mode 100644
index 0000000..a690982
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_IDCT.cpp
@@ -0,0 +1,72 @@
+/********************************************************
+Author: Suraj Prakash
+return_image = IDCT(source_image)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+using namespace cv;
+using namespace std;
+
+extern "C"{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+
+ int opencv_IDCT(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j;
+
+ int flags = 0;
+
+ /// checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ if(image.channels() != 1){
+ Scierror(999, "%s: Image should be single channel\n");
+ return 0;
+ }
+ /// even sized rows and columns required
+ if(image.rows%2 != 0 or image.cols%2 != 0){
+ Scierror(999, "%s: Either of rows size or column size is odd\n");
+ return 0;
+ }
+
+ /// transformed_idct stores the transformed image
+ Mat transformed_idct(image.rows, image.cols, image.type());
+ idct(image, transformed_idct, flags);
+
+ string tempstring = type2str(transformed_idct.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, transformed_idct, 1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
+
diff --git a/sci_gateway1/cpp/opencv_IFFT.cpp b/sci_gateway1/cpp/opencv_IFFT.cpp
new file mode 100644
index 0000000..6bbbcbc
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_IFFT.cpp
@@ -0,0 +1,69 @@
+/********************************************************
+Author: Diwakar
+return_image = IFFT(source_image)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+using namespace cv;
+using namespace std;
+
+extern "C"{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+
+ int opencv_IFFT(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j;
+
+
+ /// checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+
+ Mat img;
+ retrieveImage(img, 1);
+
+ if(img.channels()>2){
+ Scierror(999, "Input should be single or double channel\n");
+ return 0;
+ }
+ Mat planes[] = {Mat_<float>(img), Mat::zeros(img.size(), CV_32F)};
+ Mat complexI;
+ merge(planes, 2, complexI);
+ dft(complexI, complexI);
+ Mat invDFT, invDFTcvt;
+ idft(complexI, invDFT, DFT_SCALE | DFT_REAL_OUTPUT );
+ invDFT.convertTo(invDFTcvt, CV_8U);
+
+ string tempstring = type2str(invDFTcvt.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,invDFTcvt, 1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
+
diff --git a/sci_gateway1/cpp/opencv_KalmanFilter.cpp b/sci_gateway1/cpp/opencv_KalmanFilter.cpp
new file mode 100644
index 0000000..4d1e317
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_KalmanFilter.cpp
@@ -0,0 +1,690 @@
+/********************************************************************************************************
+ Author : Kevin George
+
+-> Syntax : KalmanFilter("FileName(string)",..,"dynamParams(int)",..,"measureParams(int)",..,
+ "controlParams(int)",..,"type(int)",..,"colour(string)",..)
+
+source-http://www.robot-home.it/blog/en/software/ball-tracker-con-filtro-di-kalman/
+*******************************************************************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <opencv2/video/background_segm.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"
+ //#include "../common.cpp"
+
+ int opencv_KalmanFilter(char *fname, unsigned long fname_len)
+ {
+
+ //Error variables
+ SciErr sciErr;
+ int intErr = 0;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+ //int *piAddr2 = NULL;
+
+ //-> Local variables
+ int num_InputArgs; //-> gives total number of arguments
+ int iRows, iCols;
+ int *piLen = NULL;
+ char **pstData = NULL; //-> why double pointer?? and what is it
+ char *currentArg = NULL; //-> Stores current string representing 'name' of name,value pair arguments
+ bool *providedArgs = NULL; //-> Used to check that optional argument is not entered more than once
+ //-> Name,Value Pair Variables
+ int dynamParams,measureParams;
+ int controlParams,type;
+ //char *colour = NULL;
+ string colour;
+ char *filename;
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ //-> Checks number of input and output arguments
+ CheckInputArgument(pvApiCtx, 0, 6);
+ CheckOutputArgument(pvApiCtx, 1, 6);
+
+ //-> Count number of input arguments
+ num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ providedArgs = (bool*) malloc(sizeof(bool) * 6);
+
+ //-> Based on number of input arguments
+
+ for(int iter = 1; iter<= num_InputArgs; iter++)
+ {
+ //-> Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Extracting name of next argument takes three calls to getMatrixOfString
+ //-> First call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ //-> Third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+//****************************************************** Name,Value - Filename *****************************************************************
+ if(strcmp(currentArg, "FileName")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[5])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Extracting name of next argument takes three calls to getMatrixOfString
+ //-> First call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ //-> Third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ filename = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+ providedArgs[5] = 1;
+ }
+
+ else if(providedArgs[5]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+ }
+//****************************************************** Name,Value - dynamParams *****************************************************************
+
+
+ if(strcmp(currentArg, "dynamParams")==0)
+ {
+
+ if(iter+1<= num_InputArgs && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &dynamParams);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if( dynamParams < 0)
+ {
+ Scierror(999," Invalid Value for dynamParams. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[0] = 1;
+ }
+
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+//****************************************************** Name,Value - measureParams *****************************************************************
+ else if(strcmp(currentArg, "measureParams")==0)
+ {
+
+ if(iter+1<= num_InputArgs && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &measureParams);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if( measureParams < 0)
+ {
+ Scierror(999," Invalid Value for measureParams. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[1] = 1;
+ }
+
+ else if(providedArgs[1]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+//****************************************************** Name,Value - controlParams *****************************************************************
+
+ else if(strcmp(currentArg, "controlParams")==0)
+ {
+
+ if(iter+1<= num_InputArgs && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &controlParams);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if( controlParams < 0)
+ {
+ Scierror(999," Invalid Value for controlParams. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[2] = 1;
+ }
+
+ else if(providedArgs[2]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+//****************************************************** Name,Value - type *****************************************************************
+
+ else if(strcmp(currentArg, "type")==0)
+ {
+
+ if(iter+1<= num_InputArgs && !providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &type);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ providedArgs[3] = 1;
+ }
+
+ else if(providedArgs[3]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+
+//****************************************************** Name,Value - colour *****************************************************************
+
+
+ else if(strcmp(currentArg, "colour")==0)
+ {
+
+ if(iter+1<= num_InputArgs && !providedArgs[4])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Extracting name of next argument takes three calls to getMatrixOfString
+ //-> First call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ //-> Third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ colour = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+ providedArgs[4] = 1;
+ }
+
+ else if(providedArgs[4]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+
+ }//-> Braces of big for loop
+
+//******************************************************** Giving Default Arguments *******************************************************************
+
+ if(providedArgs[0] == 0)
+ {
+ dynamParams = 6;
+ }
+
+
+ if(providedArgs[1] == 0)
+ {
+ measureParams = 4;
+ }
+
+ if(providedArgs[2] == 0)
+ {
+ controlParams = 0;
+ }
+
+ if(providedArgs[3] == 0)
+ {
+ type = CV_32F;
+ }
+
+ if(providedArgs[4] == 0)
+ {
+ colour = "red";
+ }
+
+//**************************************************************Actual Processing*******************************************************************************
+
+ //objectStatus2 = true;
+
+ //SciErr sciErr;
+ //int *piAddr = NULL;
+ //int *outList = NULL;
+ //unsigned char *red = NULL;
+ //unsigned char *green = NULL;
+ //unsigned char *blue = NULL;
+
+ KalmanFilter kf(dynamParams, measureParams, controlParams, type);
+
+ Mat state(dynamParams, 1, type); // [x,y,v_x,v_y,w,h]
+ Mat meas(measureParams, 1, type); // [z_x,z_y,z_w,z_h]
+
+ setIdentity(kf.transitionMatrix);
+
+ kf.measurementMatrix = cv::Mat::zeros(measureParams, dynamParams, type);
+ kf.measurementMatrix.at<float>(0) = 1.0f;
+ kf.measurementMatrix.at<float>(7) = 1.0f;
+ kf.measurementMatrix.at<float>(16) = 1.0f;
+ kf.measurementMatrix.at<float>(23) = 1.0f;
+
+
+ kf.processNoiseCov.at<float>(0) = 1e-2;
+ kf.processNoiseCov.at<float>(7) = 1e-2;
+ kf.processNoiseCov.at<float>(14) = 5.0f;
+ kf.processNoiseCov.at<float>(21) = 5.0f;
+ kf.processNoiseCov.at<float>(28) = 1e-2;
+ kf.processNoiseCov.at<float>(35) = 1e-2;
+
+ // Measures Noise Covariance Matrix R
+ setIdentity(kf.measurementNoiseCov, cv::Scalar(1e-1));
+ // <<<< Kalman Filter
+
+ VideoCapture cap(filename);
+ cap.set(CV_CAP_PROP_FRAME_WIDTH, 1024);
+ cap.set(CV_CAP_PROP_FRAME_HEIGHT, 768);
+
+ Mat frame;
+ //retrieveImage(frame,1);
+
+
+ char ch = 0;
+ double ticks = 0;
+ bool found = false;
+
+ int notFoundCount = 0;
+
+ //double precTick = ticks;
+ //-> measures a function execution time
+ //-> counting number of ticks after certain event
+ //ticks = (double) cv::getTickCount();
+
+ //double dT = (ticks - precTick) / cv::getTickFrequency(); //seconds
+
+ //Mat res;
+ //frame.copyTo( res );
+
+ while (ch != 'q' && ch != 'Q')
+ {
+ double precTick = ticks;
+ ticks = (double) cv::getTickCount();
+
+ double dT = (ticks - precTick) / cv::getTickFrequency(); //seconds
+
+ // Frame acquisition
+ cap >> frame;
+
+ cv::Mat res;
+ frame.copyTo( res );
+
+ if (found)
+ {
+ // >>>> Matrix A
+ kf.transitionMatrix.at<float>(2) = dT;
+ kf.transitionMatrix.at<float>(9) = dT;
+ // <<<< Matrix A
+
+ state = kf.predict();
+
+ Rect predRect;
+ predRect.width = state.at<float>(4);
+ predRect.height = state.at<float>(5);
+ predRect.x = state.at<float>(0) - predRect.width / 2;
+ predRect.y = state.at<float>(1) - predRect.height / 2;
+
+ Point center;
+ center.x = state.at<float>(0);
+ center.y = state.at<float>(1);
+ circle(res, center, 2, CV_RGB(255,0,0), -1);
+
+ rectangle(res, predRect, CV_RGB(255,0,0), 2);
+ }
+
+ // >>>>> Noise smoothing
+ Mat blur;
+ GaussianBlur(frame, blur, cv::Size(5, 5), 3.0, 3.0);
+ // <<<<< Noise smoothing
+
+ // >>>>> HSV conversion
+ Mat frmHsv;
+ cvtColor(blur, frmHsv, CV_BGR2HSV);
+ // <<<<< HSV conversion
+
+ // >>>>> Color Thresholding
+ // Note: change parameters for different colors
+ Mat rangeRes = cv::Mat::zeros(frame.size(), CV_8UC1);
+
+//************************** Tracks object with range of RGB values *******************************************************************
+
+ if(colour == "red")
+ { cv::inRange(frmHsv, cv::Scalar(0, 153, 127),
+ cv::Scalar(4, 230, 179), rangeRes);
+ }
+
+ else if(colour == "green")
+ {
+ cv::inRange(frmHsv, cv::Scalar(30,0,0),
+ cv::Scalar(100,255,255), rangeRes);
+ }
+
+ else if(colour == "white")
+ {
+ cv::inRange(frmHsv, cv::Scalar(0,0,80),
+ cv::Scalar(255,50,120), rangeRes);
+ }
+
+ else if(colour == "orange" || colour == "yellow")
+ {
+ cv::inRange(frmHsv, cv::Scalar(15, 204, 204),
+ cv::Scalar(20, 255, 255), rangeRes);
+ }
+
+
+
+ // <<<<< Color Thresholding
+
+ // >>>>> Improving the result
+ erode(rangeRes, rangeRes, cv::Mat(), cv::Point(-1, -1), 2);
+ dilate(rangeRes, rangeRes, cv::Mat(), cv::Point(-1, -1), 2);
+ // <<<<< Improving the result
+
+ // Thresholding viewing
+ ///cv::imshow("Threshold", rangeRes);
+
+ // >>>>> Contours detection
+ vector<vector<cv::Point> > contours;
+ findContours(rangeRes, contours, CV_RETR_EXTERNAL,
+ CV_CHAIN_APPROX_NONE);
+ // <<<<< Contours detection
+
+ // >>>>> Filtering
+ vector<vector<cv::Point> > balls;
+ vector<cv::Rect> ballsBox;
+
+ for (size_t i = 0; i < contours.size(); i++)
+ {
+ Rect bBox;
+ bBox = cv::boundingRect(contours[i]);
+
+ float ratio = (float) bBox.width / (float) bBox.height;
+ if (ratio > 1.0f)
+ ratio = 1.0f / ratio;
+
+ // Searching for a bBox almost square
+ if (ratio > 0.75 && bBox.area() >= 400)
+ {
+ balls.push_back(contours[i]);
+ ballsBox.push_back(bBox);
+ }
+ }
+ // <<<<< Filtering
+
+ // >>>>> Detection result
+ for (size_t i = 0; i < balls.size(); i++)
+ {
+ drawContours(res, balls, i, CV_RGB(20,150,20), 1);
+ rectangle(res, ballsBox[i], CV_RGB(0,255,0), 2);
+
+ Point center;
+ center.x = ballsBox[i].x + ballsBox[i].width / 2;
+ center.y = ballsBox[i].y + ballsBox[i].height / 2;
+ circle(res, center, 2, CV_RGB(20,150,20), -1);
+
+ stringstream sstr;
+ sstr << "(" << center.x << "," << center.y << ")";
+ putText(res, sstr.str(),
+ cv::Point(center.x + 3, center.y - 3),
+ cv::FONT_HERSHEY_SIMPLEX, 0.5, CV_RGB(20,150,20), 2);
+ }
+ // <<<<< Detection result
+
+ // >>>>> Kalman Update
+ if (balls.size() == 0)
+ {
+ notFoundCount++;
+ if( notFoundCount >= 100 )
+ {
+ found = false;
+ }
+ /*else
+ kf.statePost = state;*/
+ }
+ else
+ {
+ notFoundCount = 0;
+
+ meas.at<float>(0) = ballsBox[0].x + ballsBox[0].width / 2;
+ meas.at<float>(1) = ballsBox[0].y + ballsBox[0].height / 2;
+ meas.at<float>(2) = (float)ballsBox[0].width;
+ meas.at<float>(3) = (float)ballsBox[0].height;
+
+ if (!found) // First detection!
+ {
+ // >>>> Initialization
+ kf.errorCovPre.at<float>(0) = 1; // px
+ kf.errorCovPre.at<float>(7) = 1; // px
+ kf.errorCovPre.at<float>(14) = 1;
+ kf.errorCovPre.at<float>(21) = 1;
+ kf.errorCovPre.at<float>(28) = 1; // px
+ kf.errorCovPre.at<float>(35) = 1; // px
+
+ state.at<float>(0) = meas.at<float>(0);
+ state.at<float>(1) = meas.at<float>(1);
+ state.at<float>(2) = 0;
+ state.at<float>(3) = 0;
+ state.at<float>(4) = meas.at<float>(2);
+ state.at<float>(5) = meas.at<float>(3);
+ // <<<< Initialization
+
+ found = true;
+ }
+ else
+ kf.correct(meas); // Kalman Correction
+
+ }
+ // <<<<< Kalman Update
+ // Final result
+ cv::imshow("Tracking", res);
+ ch = cv::waitKey(1);
+
+ }
+ //AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_SURFPoints.cpp b/sci_gateway1/cpp/opencv_SURFPoints.cpp
new file mode 100644
index 0000000..93bd6c2
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_SURFPoints.cpp
@@ -0,0 +1,123 @@
+/***************************************************
+Author : Shashank Shekhar
+***************************************************/
+
+#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_SURFPoints(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int *piChild = NULL;
+ int iType = 0;
+ int iRows, iCols = 0;
+ double *matData = NULL;
+
+ double *OrientationData = NULL;
+ double *MetricData = NULL;
+ int *LaplacianData = NULL;
+ double *ScaleData = NULL;
+
+ CheckInputArgument(pvApiCtx, 1,1);
+ CheckOutputArgument(pvApiCtx,1,6);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix || isVarComplex(pvApiCtx, piAddr))
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &matData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iCols!=2)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ OrientationData = (double *)malloc(sizeof(double)*iRows);
+ MetricData = (double *)malloc(sizeof(double)*iRows);
+ LaplacianData = (int *)malloc(sizeof(int)*iRows);
+ ScaleData = (double *)malloc(sizeof(double)*iRows);
+
+ for(int i = 0 ; i<iRows; i++)
+ {
+ OrientationData[i] = 0;
+ MetricData[i] = 0;
+ LaplacianData[i] = 0;
+ ScaleData[i] = 1.6;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows,2, matData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, iRows,1, OrientationData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, iRows,1, MetricData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 4, iRows,1, LaplacianData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, iRows,1, ScaleData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ createScalarInteger32(pvApiCtx,nbInputArgument(pvApiCtx) + 6, iRows);
+
+ for(int i=1;i<=6;i++)
+ {
+ AssignOutputVariable(pvApiCtx, i) = nbInputArgument(pvApiCtx) + i;
+ }
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_TemplateMatcher.cpp b/sci_gateway1/cpp/opencv_TemplateMatcher.cpp
new file mode 100644
index 0000000..674abcb
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_TemplateMatcher.cpp
@@ -0,0 +1,146 @@
+/********************************************************
+Author: Suraj Prakash
+return_image = TemplateMatcher(InputArray image, InputArray templage_image, int method)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+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_TemplateMatcher(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j;
+
+ int iRows = 0;
+ int iCols = 0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+
+ char **method = NULL;
+
+
+ /// checking input argument
+ CheckInputArgument(pvApiCtx, 2, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ Mat image, template_image;
+ retrieveImage(image, 1);
+ retrieveImage(template_image, 2);
+
+ /// if there is inconsistency in data type of image and template image
+ if(type2str(image.type()) != type2str(template_image.type())){
+ Scierror(999, "%s: Image and template image are not of same type\n");
+ return 0;
+ }
+
+ if(template_image.rows > image.rows or template_image.cols > image.cols){
+ Scierror(999, "%s: Dimensions of template image is greater then image\n");
+ return 0;
+ }
+
+ /// generated image is (W - w + 1) * (H - h + 1) and it must be 32 bit floating number with single channel
+
+ Mat new_image(image.rows, image.cols, image.type());
+
+
+ int nbInputArguments = *getNbInputArgument(pvApiCtx);
+ if(nbInputArguments > 2){
+ /// variable address
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /// Retrieve string from input parameter. (requires 3 calls)
+ /// first to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ method = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ method[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, method);
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp(method[0], "CV_TM_SQDIFF") == 0)
+ matchTemplate(image, template_image, new_image, CV_TM_SQDIFF);
+ else if(strcmp(method[0], "CV_TM_SQDIFF_NORMED") == 0)
+ matchTemplate(image, template_image, new_image, CV_TM_SQDIFF_NORMED);
+ else if(strcmp(method[0], "CV_TM_CCORR") == 0)
+ matchTemplate(image, template_image, new_image, CV_TM_CCORR);
+ else if(strcmp(method[0], "CV_TM_CCORR_NORMED") == 0)
+ matchTemplate(image, template_image, new_image, CV_TM_CCORR_NORMED);
+ else if(strcmp(method[0], "CV_TM_CCOEFF") == 0)
+ matchTemplate(image, template_image, new_image, CV_TM_CCOEFF);
+ else if(strcmp(method[0], "CV_TM_CCOEFF_NORMED") == 0)
+ matchTemplate(image, template_image, new_image, CV_TM_CCOEFF_NORMED);
+ else{
+ matchTemplate(image, template_image, new_image, CV_TM_SQDIFF);
+ sciprint("Wrong method given, using CV_TM_SQDIFF instead");
+ }
+ }
+
+ else{
+ matchTemplate(image, template_image, new_image, CV_TM_SQDIFF);
+ }
+
+
+
+
+
+
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, new_image, 1);
+ free(checker);
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_VideoPlayer.cpp b/sci_gateway1/cpp/opencv_VideoPlayer.cpp
new file mode 100644
index 0000000..74b7405
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_VideoPlayer.cpp
@@ -0,0 +1,78 @@
+/***************************************************
+Author : Tanmay Chaudhari
+**************************************************/
+
+#include "opencv2/video/tracking.hpp"
+#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"
+ //#include "../common.cpp"
+
+ int opencv_VideoPlayer()
+ {
+ SciErr sciErr;
+ int* piAddr = NULL;
+ int iRows = 0;
+ int iCols = 0;
+ int iRet = 0;
+ char** pstData = NULL;
+
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ iRet = getAllocatedMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, &pstData);
+ if(iRet)
+ {
+ freeAllocatedMatrixOfString(iRows, iCols, pstData);
+ return iRet;
+ }
+ sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pstData);
+ if(sciErr.iErr)
+ {
+ freeAllocatedMatrixOfString(iRows, iCols, pstData);
+ printError(&sciErr, 0);
+ return sciErr.iErr;
+ }
+ VideoCapture cap(pstData[0]);
+ namedWindow("Video Player", 0 );
+ Mat frame;
+ bool paused = false;
+ for(;;)
+ {
+ if( !paused )
+ {
+ cap >> frame;
+ if(frame.empty())
+ break;
+ }
+ imshow("Video Player", frame );
+ char c = (char)waitKey(20);
+ if(c==27)
+ break;
+ else if(c==32)
+ paused=!paused;
+ else;
+ }
+ destroyAllWindows();
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
+
diff --git a/sci_gateway1/cpp/opencv_VideoReader.cpp b/sci_gateway1/cpp/opencv_VideoReader.cpp
new file mode 100644
index 0000000..51207bf
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_VideoReader.cpp
@@ -0,0 +1,389 @@
+/***************************************************
+Author : Tanmay Chaudhari, Shashank Shekhar
+**************************************************/
+
+#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"
+ //#include "../common.cpp"
+
+ Ptr<VideoCapture> capture;
+ double videoCurrentTime = 0;
+ double videoDuration = 0;
+ int videoFPS;
+ char *videoFileName = NULL;
+ bool videoObjectSt = false;
+ int opencv_VideoReader(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int *piAddrVal = NULL;
+ int *piLen = NULL;
+ int iRows, iCols = 0;
+ char ** pstData1 = NULL;
+ char ** pstData2 = NULL;
+ double frames;
+ double width;
+ double height;
+ double CT;
+ char full_path[PATH_MAX];
+ bool stillLeft = false;
+ CheckInputArgument(pvApiCtx,1,3);
+ CheckOutputArgument(pvApiCtx,1,10);
+ int noOfarguments = *getNbInputArgument(pvApiCtx);
+ if(noOfarguments==2)
+ {
+ Scierror(999,"Invalid number of Arguments\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isStringType(pvApiCtx, piAddr))
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+ //first call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData1 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j = 0 ; j < iRows * iCols ; j++)
+ {
+ pstData1[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(noOfarguments>1)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isStringType(pvApiCtx, piAddr))
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+ //first call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData2 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j = 0 ; j < iRows * iCols ; j++)
+ {
+ pstData2[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp(pstData2[0], "CurrentTime")==0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+
+ Scierror(999," Invalid Value for Current Time.\n");
+ return 0;
+ }
+ getScalarDouble(pvApiCtx, piAddrVal, &CT);
+ if(CT<0)
+ {
+ Scierror(999,"Invalid Input for CurrentTime.\n");
+ return 0;
+ }
+ CT*=1000;
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+ }
+
+ if(videoObjectSt==true && strcmp(videoFileName, pstData1[0])==0)
+ {
+ if(int(videoCurrentTime) >= int(videoDuration))
+ {
+ stillLeft = false;
+ }
+ else if(int(videoCurrentTime) < int(videoDuration))
+ stillLeft = true;
+ }
+
+ if(!stillLeft)
+ {
+ capture = new VideoCapture(pstData1[0]);
+ if(!capture->isOpened())
+ {
+ Scierror(999,"Could not open file\n");
+ return 0;
+ }
+ }
+
+ videoFileName = pstData1[0];
+ videoFPS = capture->get(CV_CAP_PROP_FPS);
+ frames = capture->get(CV_CAP_PROP_FRAME_COUNT);
+
+ if(noOfarguments!=1)
+ {
+ if(int(CT) >= int(videoDuration))
+ {
+ Scierror(999,"Current Time should be less than Video Duration\n");
+ return 0;
+ }
+ capture->set(CV_CAP_PROP_POS_MSEC, CT);
+ }
+
+ videoObjectSt = true;
+ videoCurrentTime = capture->get(CV_CAP_PROP_POS_MSEC);
+ videoDuration = (1000/double(videoFPS))*double(frames);
+ width = capture->get(CV_CAP_PROP_FRAME_WIDTH);
+ height = capture->get(CV_CAP_PROP_FRAME_HEIGHT);
+ realpath(pstData1[0], full_path);
+
+ createSingleString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, pstData1[0]);
+ createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx) + 2, videoDuration);
+ createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx) + 3, videoFPS);
+ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx)+4, videoCurrentTime);
+ createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx) + 5, frames);
+ createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx) + 6, width);
+ createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx) + 7, height);
+ createSingleString(pvApiCtx, nbInputArgument(pvApiCtx)+8, full_path);
+
+ for(int i=0;i<=8;i++)
+ {
+ AssignOutputVariable(pvApiCtx, i) = nbInputArgument(pvApiCtx) + i;
+ }
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+ int has_frame(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+
+ if(videoFileName==NULL)
+ {
+ Scierror(999,"No video has been read yet.\n");
+ return 0;
+ }
+
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ int iRows, iCols = 0;
+ char ** pstData = NULL;
+
+ CheckInputArgument(pvApiCtx,0,0);
+ CheckOutputArgument(pvApiCtx,0,1);
+
+ if(videoObjectSt == false)
+ {
+ Scierror(999,"Invalid Video File. You need to read the video using VideoReader.\n");
+ return 0;
+ }
+
+ if(videoCurrentTime>videoDuration)
+ createScalarBoolean(pvApiCtx,nbInputArgument(pvApiCtx) + 1, false);
+ else if(int(videoCurrentTime) == int(videoDuration))
+ createScalarBoolean(pvApiCtx,nbInputArgument(pvApiCtx) + 1, false);
+ else
+ createScalarBoolean(pvApiCtx,nbInputArgument(pvApiCtx) + 1, true);
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+ int read_frame(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+
+ if(videoFileName==NULL)
+ {
+ Scierror(999,"No video has been read yet.\n");
+ return 0;
+ }
+
+ if(int(videoCurrentTime)>=int(videoDuration))
+ {
+ Scierror(999,"No more frames left to be read\n");
+ return 0;
+ }
+ //sciprint("Current Time of the Video is : %f\n", videoCurrentTime);
+
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ int iRows, iCols = 0;
+ char ** pstData = NULL;
+ int *singleFrameList = NULL;
+ unsigned char *red = NULL;
+ unsigned char *green = NULL;
+ unsigned char *blue = NULL;
+
+ CheckInputArgument(pvApiCtx,0,0);
+ CheckOutputArgument(pvApiCtx,0,1);
+
+ if(videoObjectSt == false)
+ {
+ Scierror(999,"Invalid Video File. You need to read the video using VideoReader.\n");
+ return 0;
+ }
+
+//--------------------------------------- Processing Frame at the particular frame -----------------------------------
+
+ Mat frame;
+ capture->set(CV_CAP_PROP_POS_MSEC, videoCurrentTime);
+ if(!capture->read(frame))
+ {
+ Scierror(999, "Can't read Frame");
+ return 0;
+ }
+//--------------------------------------------------------------------------------------------------------------------
+
+ if(frame.channels()==1)
+ {
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &singleFrameList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red = (unsigned char *)malloc(sizeof(unsigned char)*frame.rows*frame.cols);
+
+ for(int k=0;k<frame.rows;k++)
+ for(int p=0;p<frame.cols;p++)
+ red[k+frame.rows*p]=frame.at<uchar>(k, p);
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, singleFrameList, 1, frame.rows, frame.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ free(red);
+ }
+ else
+ {
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &singleFrameList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red = (unsigned char *)malloc(sizeof(unsigned char)*frame.rows*frame.cols);
+ green = (unsigned char *)malloc(sizeof(unsigned char)*frame.rows*frame.cols);
+ blue = (unsigned char *)malloc(sizeof(unsigned char)*frame.rows*frame.cols);
+
+ for(int k=0;k<frame.rows;k++)
+ {
+ for(int p=0;p<frame.cols;p++)
+ {
+ Vec3b intensity = frame.at<Vec3b>(k, p);
+ red[k+frame.rows*p]=intensity.val[2];
+ green[k+frame.rows*p]=intensity.val[1];
+ blue[k+frame.rows*p]=intensity.val[0];
+ }
+ }
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, singleFrameList, 1, frame.rows, frame.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, singleFrameList, 2, frame.rows, frame.cols, green);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, singleFrameList, 3, frame.rows, frame.cols, blue);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ free(red);
+ free(green);
+ free(blue);
+ }
+
+ videoCurrentTime+=(1000/double(videoFPS));
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+}
+
+
+
diff --git a/sci_gateway1/cpp/opencv_arrowedline.cpp b/sci_gateway1/cpp/opencv_arrowedline.cpp
new file mode 100644
index 0000000..0e1643a
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_arrowedline.cpp
@@ -0,0 +1,221 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ return_image = arrowedline(image , x1 , y1 , x2,y2,r_value,g_value,b_value,thickness,linetype,shift,tiplength);
+********************************************************/
+
+#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_arrowedline(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int *piAddr9 = NULL;
+ int *piAddr10 = NULL;
+ int *piAddr11 = NULL;
+ int *piAddr12 = NULL;
+ int i,j,k;
+ double thickness=1 , linetype=8,shift =0 ,tiplength=0.1;
+ double x1,y1,x2,y2,r_value,g_value,b_value;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 8, 12);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat src;
+ retrieveImage(src,1);
+
+ //for value of x coordinate of first point
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2 ,&x1);
+ if(intErr)
+ return intErr;
+
+ //for value of y coordinate of first point
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&y1);
+ if(intErr)
+ return intErr;
+
+ //for value of x coordinate of second point
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4 ,&x2);
+ if(intErr)
+ return intErr;
+
+ ///for value of y coordinate of second point
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&y2);
+ if(intErr)
+ return intErr;
+
+ //for value of R value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6,&r_value);
+ if(intErr)
+ return intErr;
+
+ // for G value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7,&g_value);
+ if(intErr)
+ return intErr;
+
+ // for B value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr8,&b_value);
+ if(intErr)
+ return intErr;
+
+ // for thickness of circle default: 1
+ sciErr = getVarAddressFromPosition(pvApiCtx,9,&piAddr9);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr9 ,&thickness);
+ if(intErr)
+ return intErr;
+
+ //for line type of circle default: 8
+ sciErr = getVarAddressFromPosition(pvApiCtx,10,&piAddr10);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr10,&linetype);
+ if(intErr)
+ return intErr;
+
+ // for shift in line defulat : 0
+ sciErr = getVarAddressFromPosition(pvApiCtx,11,&piAddr11);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Syntax: sciErr = getMatrixOfInteger8(pvApiCtx, piAddr8, &iRows8, &iCols8, &pcData);
+ intErr = getScalarDouble(pvApiCtx, piAddr11 ,&shift);
+ if(intErr)
+ return intErr;
+
+ // for tiplength of arrow default : 0.1
+ sciErr = getVarAddressFromPosition(pvApiCtx,12,&piAddr12);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Syntax: sciErr = getMatrixOfInteger8(pvApiCtx, piAddr8, &iRows8, &iCols8, &pcData);
+ intErr = getScalarDouble(pvApiCtx, piAddr12,&tiplength);
+ if(intErr)
+ return intErr;
+ //temporary pt variable, to use in function as centre
+ Point pt1(x1,y1);
+ Point pt2(x2,y2);
+
+
+ /// checking the parmeters for correct values
+ if( r_value <0 || r_value >255)
+ {
+ r_value=0;
+ sciprint(" r value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( g_value <0 || g_value >255)
+ {
+ g_value=0;
+ sciprint(" g value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( b_value <0 || b_value >255)
+ {
+ b_value=0;
+ sciprint(" b value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if ((linetype!=0) && (linetype!=4)&& (linetype!=8))
+ {
+ linetype=8;
+ sciprint("Only 0/4/8 allowed , using 8 instead");
+ }
+ //calling the opencv function
+ arrowedLine( src, pt1, pt2, Scalar(b_value,g_value,r_value), thickness, linetype, shift, tiplength);
+
+ string tempstring = type2str(src.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,src,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_bagOfFeatures.cpp b/sci_gateway1/cpp/opencv_bagOfFeatures.cpp
new file mode 100644
index 0000000..e87c40c
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_bagOfFeatures.cpp
@@ -0,0 +1,550 @@
+/****************************************************************************************************
+* Author: Umang Agrawal *
+* Code: bagOfFeatues.cpp *
+* Function Format: bag = bagOfFeatures(imageSet, Oprional Arguments Name, Value) *
+* Arguments: Name Value *
+* 1. VocabularySize any integer value greater than 0 *
+* 2. StrongestFeatures pecentage of best features to be Selected *
+* 3. Upright Bool 0 or 1 *
+* 4. Verbose Bool 0 or 1 *
+****************************************************************************************************/
+
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+
+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"
+
+ bool response_comparator(const KeyPoint& p1, const KeyPoint& p2) {
+ return p1.response > p2.response;
+ }
+
+ int opencv_bagOfFeatures(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+
+ int inp_params = 0;
+
+ int *piAddr = NULL;
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piLen = NULL;
+ int *piChild = NULL;
+ char **pstData = NULL;
+ int iRows, iCols;
+ char **arg = NULL;
+ int count_ver = 0, count_up = 0, count_strength = 0, count_vocab = 0;
+
+ int descriptionCount;
+ char *objectType = "bagOfFeatures";
+ char **description = NULL;
+ int *count = NULL;
+ double vocab_size = 500, verbose = 1, upright = 1, strength = 1;
+ char ***location = NULL;
+ char **filepath = NULL;
+ char *file = "Bag-Of-Features.yml";
+ int key_size=0, v_key_size=0;
+
+ Mat image;
+ vector<KeyPoint> keypoints;
+ vector<KeyPoint> valid_key;
+ Mat feature_des;
+ Mat dictionary;
+ Mat featuresUnclustered;
+
+ CheckInputArgument(pvApiCtx, 1, 9); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 1); //Check on Number of Output Arguments
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr1))
+ {
+ Scierror(999, "Error: Invalid first argument. List Expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"imageSet")==0))
+ {
+ Scierror(999, "Error: The input argument is not of type imageSet.\n");
+ return 0;
+ }
+
+ // Extracting Description attribute of input argument
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ description = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ description[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, piLen, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ descriptionCount = iRows;
+
+ // Extracting Count attribute of input argument
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr1, 3, &iRows, &iCols, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ location = (char***) malloc(sizeof(char**) * descriptionCount);
+ sciErr = getListItemAddress(pvApiCtx, piAddr1, 4, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int iter = 1; iter<=descriptionCount; iter++)
+ {
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ location[iter-1] = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int colIter = 0 ; colIter < iRows * iCols ; colIter++)
+ {
+ location[iter-1][colIter] = (char*)malloc(sizeof(char) * (piLen[colIter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, location[iter-1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ /*sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !isStringType(pvApiCtx, piAddr2))
+ {
+ Scierror(999, "%s: Wrong type of argument for Location. A string is expected.\n", fname);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ return 0;
+ }
+ filepath = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ filepath[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));
+ }
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, filepath);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ free(filepath);
+ return 0;
+ }*/
+
+ inp_params = *getNbInputArgument(pvApiCtx);
+ for(int i=2; i<=inp_params; i++)
+ {
+ if( inp_params%2 == 0)
+ {
+ Scierror(999,"Either Argument Name or its Value missing\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr3))
+ {
+ Scierror(999, "%s: Wrong type of argument for Name of Optional Argument. A string is expected.\n", fname);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));
+ }
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ free(arg);
+ return 0;
+ }
+
+ if(strcmp(arg[0],"VocabularySize") == 0)
+ {
+ if( count_vocab != 0)
+ {
+ Scierror(999,"Voabulary Size has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr4)))
+ {
+ Scierror(999,"Not a valid type of value for VocabularySize.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ if(getScalarDouble(pvApiCtx, piAddr4, &vocab_size))
+ {
+ Scierror(999,"Not a valid type of value for VocabularySize.\n");
+ return 0;
+ }
+ if(vocab_size < 0)
+ {
+ Scierror(999,"Enter a valid value for Vacabulary Size\n");
+ return 0;
+ }
+ i++;
+ count_vocab += 1;
+ }
+ else if(strcmp(arg[0],"StrongestFeatures") == 0)
+ {
+ if( count_strength != 0)
+ {
+ Scierror(999,"Strength Features has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !isDoubleType(pvApiCtx, piAddr4) )
+ {
+ Scierror(999,"Not a valid type of value for StrongestFeatures.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ if(getScalarDouble(pvApiCtx, piAddr4, &strength))
+ {
+ Scierror(999,"Not a valid type of value for StrongestFeatures.\n");
+ return 0;
+ }
+ if( strength<0 || strength>=1 )
+ {
+ Scierror(999,"Enter a valid value for Strongest Features (between 0 and 1)\n");
+ return 0;
+ }
+ i++;
+ count_strength += 1;
+ }
+ else if(strcmp(arg[0],"Verbose") == 0)
+ {
+ if( count_ver != 0)
+ {
+ Scierror(999,"Verbose has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr4)))
+ {
+ Scierror(999,"Not a valid type of value for Verbose.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ if(getScalarDouble(pvApiCtx, piAddr4, &verbose))
+ {
+ Scierror(999,"Not a valid type of value for Verbose.\n");
+ return 0;
+ }
+ if( !(verbose == 1|| verbose == 0) )
+ {
+ Scierror(999,"Enter a valid value for Verbose (Either 0 or 1)\n");
+ return 0;
+ }
+ i++;
+ count_ver += 1;
+ }
+ else if(strcmp(arg[0],"Upright") == 0)
+ {
+ if( count_up != 0)
+ {
+ Scierror(999,"Upright has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr4)))
+ {
+ Scierror(999,"Not a valid type of value for Upright.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ if(getScalarDouble(pvApiCtx, piAddr4, &upright))
+ {
+ Scierror(999,"Not a valid type of value for Upright.\n");
+ return 0;
+ }
+ if(!(upright == 1 || upright == 0))
+ {
+ Scierror(999,"Enter a valid value for Upright (Either 0 or 1)\n");
+ return 0;
+ }
+ i++;
+ count_up += 1;
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument Name\n");
+ return 0;
+ }
+ }
+
+ filepath = (char**)malloc(sizeof(char*)*1*1);
+ filepath[0] = (char*)malloc(sizeof(char)*20);
+ strcpy(filepath[0],file);
+ /*int flag=1;
+ for(int i=0; location[0][0][i]; i++)
+ {
+ common = location[0][0][i];
+ for(int j=0; j<descriptionCount; j++)
+ {
+ if(location[j][0][i] != common)
+ flag = 0;
+ }
+ if(flag == 0)
+ {
+ common_len = i;
+ break;
+ }
+ }
+ strncpy(filepath[0], location[0][0], common_len);
+ strcat(filepath[0], file);
+ */
+
+ SurfFeatureDetector detector(1, 4, 2, 1, int(upright));
+ Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor(1, 4, 2, 1, int(upright));
+ if(int(verbose))
+ {
+ sciprint("Creating Bag-Of-Features from %d image sets.\n\n",descriptionCount);
+ for(int i=0; i<descriptionCount; i++)
+ sciprint("Image set %d: %s\n",i+1,description[i]);
+ sciprint("\nExtracting SURF Features from each image set.\n\n");
+ }
+
+ for( int i=0; i<descriptionCount; i++)
+ {
+ if(int(verbose))
+ sciprint("Extracting features from %d images in image set %d ...",count[i],i+1);
+ key_size = 0;
+ v_key_size = 0;
+ for( int j=0; j<count[i]; j++)
+ {
+ valid_key.clear();
+ keypoints.clear();
+ image = imread(location[i][j],0);
+ detector.detect(image, keypoints);
+ sort(keypoints.begin(), keypoints.end(), response_comparator);
+ for( int k=0; k<(keypoints.size()*strength); k++)
+ {
+ valid_key.push_back(keypoints[k]);
+ }
+ extractor->compute(image, valid_key, feature_des);
+ featuresUnclustered.push_back(feature_des);
+ key_size += keypoints.size();
+ v_key_size += valid_key.size();
+ }
+ if(int(verbose))
+ {
+ sciprint("done. Extracted %d features.\n",key_size);
+ sciprint("Keeping %f percent of the strongest features.\n",(strength)*100);
+ sciprint("Net Extracted features : %d\n\n",v_key_size);
+ }
+ }
+
+ if(vocab_size > featuresUnclustered.rows)
+ vocab_size = featuresUnclustered.rows;
+ TermCriteria tc(CV_TERMCRIT_ITER, 100, 0.001);
+ int retries = 3;
+ BOWKMeansTrainer bowTrainer(int(vocab_size), tc, retries, KMEANS_PP_CENTERS);
+
+ if(int(verbose))
+ {
+ sciprint("Using K-Means Clustering to create a %d word visual vocabulary.\n",int(vocab_size));
+ sciprint("Number of Features : %d\n",featuresUnclustered.rows);
+ sciprint("Number of Clusters : %d\n\n",int(vocab_size));
+ }
+
+ dictionary = bowTrainer.cluster(featuresUnclustered);
+
+ if(int(verbose))
+ sciprint("Finished creating Bag-Of-Features\n");
+
+ FileStorage fs(filepath[0], FileStorage::WRITE);
+ fs<<"dictionary"<<dictionary;
+ fs.release();
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 5, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, 1, 1, &objectType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 2, 1, 1, filepath);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 3, 1, 1, &vocab_size);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 4, 1, 1, &strength);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 5, 1, 1, &upright);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_bbox2points.cpp b/sci_gateway1/cpp/opencv_bbox2points.cpp
new file mode 100644
index 0000000..975fc00
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_bbox2points.cpp
@@ -0,0 +1,117 @@
+/***************************************************
+Author : Tanmay Chaudhari
+***************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <bits/stdc++.h>
+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"
+ // #include "../common.cpp"
+
+int opencv_bbox2points()
+{
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int i;
+ int iComplex = 0;
+ int iType = 0;
+ int iRows = 0;
+ int iCols = 0;
+ int *piAddr = NULL;
+ double *pdblReal = NULL;
+ double *points;
+
+ //Check input output arguments
+ checkInputArgument(pvApiCtx, 1, 1);
+ checkOutputArgument(pvApiCtx, 1, 1);
+
+ //Get variable address of the first input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr || iCols != 4 || iRows == 0)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for( i = 0; i < iRows; i++) //Rows in box
+ {
+ points = (double*)malloc(sizeof(double) * 8);
+ memset(points, 0, sizeof(points));
+
+ //Upper-left
+ points[0] = pdblReal[i];
+ points[4] = pdblReal[i + iRows];
+
+ //Upper-right
+ points[1] = pdblReal[i] + pdblReal[i + 2 * iRows];
+ points[5] = pdblReal[i + iRows];
+
+ //Lower-right
+ points[2] = pdblReal[i] + pdblReal[i + 2 * iRows];
+ points[6] = pdblReal[i + iRows] + pdblReal[i+ 3 * iRows];
+
+ //Lower-left
+ points[3] = pdblReal[i];
+ points[7] = pdblReal[i + iRows] + pdblReal[i + 3 * iRows];
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, i + 1, 4, 2, points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ //Return output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_bboxOverlapRatio.cpp b/sci_gateway1/cpp/opencv_bboxOverlapRatio.cpp
new file mode 100644
index 0000000..e43cb12
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_bboxOverlapRatio.cpp
@@ -0,0 +1,275 @@
+/***************************************************
+Author : Tanmay Chaudhari
+ ***************************************************/
+
+#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"
+ // #include "../common.cpp"
+
+ int opencv_bboxOverlapRatio(char *fname, unsigned long fname_len)
+ {
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int i, j;
+ int nbInputArguments = 0;
+ int iComplex = 0;
+ int iType = 0;
+ int iRows = 0;
+ int iCols = 0;
+ int rowsOfBboxA = 0;
+ int colsOfBboxA = 0;
+ int rowsOfBboxB = 0;
+ int colsOfBboxB = 0;
+ int unionOrMin = 0; //if 0 then union else min
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ char **ratioType = NULL;
+ double x1 = 0;
+ double x2 = 0;
+ double y1 = 0;
+ double y2 = 0;
+ double w = 0;
+ double h = 0;
+ double intersectAB = 0;
+ double *overlapRatio = 0;
+ double *bboxA = NULL;
+ double *bboxB = NULL;
+ double *x1BboxA = NULL;
+ double *x2BboxA = NULL;
+ double *y1BboxA = NULL;
+ double *y2BboxA = NULL;
+ double *x1BboxB = NULL;
+ double *x2BboxB = NULL;
+ double *y1BboxB = NULL;
+ double *y2BboxB = NULL;
+ double *areaA = NULL;
+ double *areaB = NULL;
+
+ //Check input output arguments
+ checkInputArgument(pvApiCtx, 2, 3);
+ checkOutputArgument(pvApiCtx, 1, 1);
+
+ //Get number of input arguments
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ for( i = 1; i <= nbInputArguments; i++)
+ {
+ //Get variable address of the input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(i != 3)
+ {
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ if(i == 1)
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfBboxA, &colsOfBboxA, &bboxA);
+ else
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfBboxB, &colsOfBboxB, &bboxB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if((i == 1) && ((rowsOfBboxA == 0) || (colsOfBboxA !=4)))
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if((i == 2) && ((rowsOfBboxB == 0) || (colsOfBboxB != 4)))
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr || iRows != 1 || iCols != 1)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ratioType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i=0;i< iRows * iCols; i++)
+ {
+ ratioType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1)); //+1 for NULL character
+ }
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, ratioType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(piLen[0] != 5 && piLen[0] != 3)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(piLen[0] == 5 && ratioType[0][0] == 'U' && ratioType[0][1] == 'n' && ratioType[0][2] == 'i' && ratioType[0][3] == 'o' && ratioType[0][4] == 'n')
+ unionOrMin = 0;
+ else if(piLen[0] == 3 && ratioType[0][0] == 'M' && ratioType[0][1] == 'i' && ratioType[0][2] == 'n')
+ unionOrMin = 1;
+ else
+ {
+ Scierror(999, "%s: Wrong type for input argument: Union or Min is expected.\n");
+ return 0;
+ }
+ free(piLen);
+ free(ratioType);
+ }
+ }
+
+ x1BboxA = (double*)malloc(sizeof(double) * rowsOfBboxA);
+ x2BboxA = (double*)malloc(sizeof(double) * rowsOfBboxA);
+ y1BboxA = (double*)malloc(sizeof(double) * rowsOfBboxA);
+ y2BboxA = (double*)malloc(sizeof(double) * rowsOfBboxA);
+
+ x1BboxB = (double*)malloc(sizeof(double) * rowsOfBboxB);
+ x2BboxB = (double*)malloc(sizeof(double) * rowsOfBboxB);
+ y1BboxB = (double*)malloc(sizeof(double) * rowsOfBboxB);
+ y2BboxB = (double*)malloc(sizeof(double) * rowsOfBboxB);
+
+ areaA = (double*)malloc(sizeof(double) * rowsOfBboxA);
+ areaB = (double*)malloc(sizeof(double) * rowsOfBboxB);
+
+ overlapRatio = (double*)malloc(sizeof(double) * rowsOfBboxA * rowsOfBboxB);
+
+ for( i = 0; i < rowsOfBboxA; i++)
+ {
+ //Left top corner
+ x1BboxA[i] = bboxA[i];
+ y1BboxA[i] = bboxA[rowsOfBboxA + i];
+
+ //right bottom corner
+ x2BboxA[i] = x1BboxA[i] + bboxA[2 * rowsOfBboxA + i];
+ y2BboxA[i] = y1BboxA[i] + bboxA[3 * rowsOfBboxA + i];
+ }
+
+ for( i = 0; i < rowsOfBboxB; i++)
+ {
+ //Left top corner
+ x1BboxB[i] = bboxB[i];
+ y1BboxB[i] = bboxB[rowsOfBboxB + i];
+
+ //right bottom corner
+ x2BboxB[i] = x1BboxB[i] + bboxB[2 * rowsOfBboxB + i];
+ y2BboxB[i] = y1BboxB[i] + bboxB[3 * rowsOfBboxB + i];
+ }
+
+ //Computing area for each rectangle in bboxA
+ for( i = 0; i < rowsOfBboxA; i++)
+ areaA[i] = bboxA[2 * rowsOfBboxA + i] * bboxA[3 * rowsOfBboxA + i];
+
+ //Computing area for each rectangle in bboxB
+ for( i = 0 ; i < rowsOfBboxB; i++)
+ areaB[i] = bboxB[2 * rowsOfBboxB + i] * bboxB[3 * rowsOfBboxB + i];
+
+ for( i = 0; i < rowsOfBboxA * rowsOfBboxB; i++)
+ overlapRatio[i] = 0;
+
+ for( i = 0; i < rowsOfBboxA; i++)
+ {
+ for( j = 0; j < rowsOfBboxB; j++)
+ {
+ //Computing the corners of the intersect
+ x1 = (x1BboxA[i] > x1BboxB[j])?x1BboxA[i]:x1BboxB[j];
+ y1 = (y1BboxA[i] > y1BboxB[j])?y1BboxA[i]:y1BboxB[j];
+ x2 = (x2BboxA[i] < x2BboxB[j])?x2BboxA[i]:x2BboxB[j];
+ y2 = (y2BboxA[i] < y2BboxB[j])?y2BboxA[i]:y2BboxB[j];
+
+ w = x2 - x1;
+ if(w <= 0) //Skip if no intersection
+ continue;
+
+ h = y2 - y1;
+ if(h <= 0) //Skip if no intersection
+ continue;
+
+ intersectAB = w * h;
+
+ if(nbInputArguments == 2)
+ overlapRatio[j * rowsOfBboxA + i] = intersectAB/(areaA[i] + areaB[j] - intersectAB);
+ else
+ {
+ if(unionOrMin == 0)
+ overlapRatio[j * rowsOfBboxA + i] = intersectAB/(areaA[i] + areaB[j] - intersectAB);
+ else
+ overlapRatio[j * rowsOfBboxA + i] = intersectAB/((areaA[i] < areaB[j])?areaA[i]:areaB[j]);
+ }
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, rowsOfBboxA, rowsOfBboxB, overlapRatio);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Return Output Argument
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_blobAnalysis.cpp b/sci_gateway1/cpp/opencv_blobAnalysis.cpp
new file mode 100644
index 0000000..4b23607
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_blobAnalysis.cpp
@@ -0,0 +1,381 @@
+/********************************************************
+Author : Deepshikha
+[key_value] : blobAnalysis(source_image)
+
+// 1 :image
+Optional arguments :-
+// 2 : filterByArea
+// 3 : filterByThreshold
+// 4 : filterByCircularity
+// 5 : filterByConvexity
+
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/features2d/features2d.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_blobAnalysis(char *fname, unsigned long fname_len){
+
+ // Error management variable
+ SciErr sciErr;
+
+ //Variables
+ int i, j;
+ int intErr;
+ int iRows1 = 0;
+ int iCols1 = 0;
+
+ int iRows = 0;
+ int iCols = 0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+
+ double *area = NULL;
+ double *threshold = NULL;
+ double *circularity = NULL;
+ double *convexity = NULL;
+
+ double *key_value = NULL;
+
+ // checking input argument
+ // 1 : image
+ // 2 : filterByArea
+ // 3 : filterByThreshold
+ // 4 : filterByCircularity
+ // 5 : filterByConvexity
+ CheckInputArgument(pvApiCtx, 1, 9);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // retrieve image
+ Mat image;
+ retrieveImage(image, 1);
+
+ // For the optional arguments
+ int nbInputArguments = *getNbInputArgument(pvApiCtx);
+ //sciprint("%d\n",nbInputArguments);
+
+ if((nbInputArguments%2) == 0)
+ {
+ Scierror(999, "%d: The number of arguments must be odd\n");
+ return 0;
+ }
+
+ providedArgs = (bool*) malloc(sizeof(bool) * 4);
+ memset(providedArgs, 0, 4);
+
+ for(int iter = 2; iter <= nbInputArguments; ++iter)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /// Three calls to getMatrixOfString
+ //First Call
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Second call to get length of string
+ piLen = (int*) malloc(sizeof(int) * iRows1 * iCols1);
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows1, &iCols1, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // third call
+ pstData = (char**) malloc(sizeof(char*) * iRows1 * iCols1);
+ for(int k = 0; k < iRows1 * iCols1; ++k)
+ {
+ pstData[k] = (char*) malloc(sizeof(char) * piLen[k] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows1, &iCols1, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ currentArg = pstData[0];
+
+ // getting filterbyArea
+ if(strcmp(currentArg, "filterByArea") == 0)
+ {
+ if(iter + 1 <= nbInputArguments and !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows1, &iCols1, &area);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows1 != 1 or iCols1 != 2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument .\n");
+ return 0;
+ }
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ /// filterbyThreshold
+ else if(strcmp(currentArg, "filterByThreshold") == 0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows1, &iCols1, &threshold);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows1 != 1 or iCols1 != 2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument .\n");
+ return 0;
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[1] = 1;
+ }
+ else if(providedArgs[1]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ /// filterbycircularity
+ else if(strcmp(currentArg, "filterByCircularity") == 0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows1, &iCols1, &circularity);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows1 != 1 or iCols1 != 2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument .\n");
+ return 0;
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[2] = 1;
+ }
+ else if(providedArgs[2]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ /// filterbyConvexity
+ else if(strcmp(currentArg, "filterByConvexity") == 0)
+ {
+ if(iter + 1 <= nbInputArguments and !providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows1, &iCols1, &convexity);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows1 != 1 or iCols1 != 2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument .\n");
+ return 0;
+ }
+
+ providedArgs[3] = 1;
+ }
+ else if(providedArgs[3]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ else
+ {
+ Scierror(9,"Invalid argument passed");
+ return 0;
+ }
+ }
+ /// End of error check and input get;
+
+ /// params for holding the parameters values;
+ SimpleBlobDetector::Params params;
+
+ /// if area is provided
+ if(providedArgs[0] == 1){
+ params.filterByArea = true;
+ params.minArea = area[0];
+ params.maxArea = area[1];
+ }
+
+ /// if threshold is provided
+ if(providedArgs[1] == 1){
+ params.minThreshold = threshold[0];
+ params.maxThreshold = threshold[1];
+ }
+
+ /// if Circularity is provided
+ if(providedArgs[2] == 1){
+ params.filterByCircularity = true;
+ params.minCircularity = circularity[0];
+ params.maxCircularity = circularity[1];
+ }
+
+ /// if convexity is provided
+ if(providedArgs[3] == 1){
+ params.filterByConvexity = true;
+ params.minConvexity = convexity[0];
+ params.maxConvexity = convexity[1];
+ }
+
+
+ SimpleBlobDetector detector( params );
+
+ /// to store the keypoints of blobs detected
+ vector<KeyPoint> keyPoints;
+
+ /// fuction to detect blob in the image
+ detector.detect(image, keyPoints);
+
+ //sciprint("%d", keyPoints.size());
+
+ key_value = (double*)malloc(sizeof(double) * (int)keyPoints.size() * 2);
+
+ double *size_value = NULL;
+
+ size_value = (double*)malloc(sizeof(double) * (int)keyPoints.size() * 1);
+
+ int total_keypoints = (int)keyPoints.size();
+
+ vector< KeyPoint >::iterator it;
+
+ for(it = keyPoints.begin(); it != keyPoints.end(); ++it)
+ {
+ KeyPoint temp = keyPoints[i];
+
+ // x coordinate
+ key_value[i + 0 * total_keypoints] = it->pt.x;
+
+ // y coordinate
+ key_value[i + 1 * total_keypoints] = it->pt.y;
+
+ // size
+ size_value[i + 0 * total_keypoints] = it->size;
+
+ //area
+ //key_value[i + 3 * total_keypoints] = it->Area;
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, total_keypoints, 2, key_value);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 2, total_keypoints, 1, size_value);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_blur.cpp b/sci_gateway1/cpp/opencv_blur.cpp
new file mode 100644
index 0000000..3db34ca
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_blur.cpp
@@ -0,0 +1,134 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+#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_blur(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ double ksize_width,ksize_height,anchorX,anchorY;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of ksize_height
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &ksize_height);
+ if(intErr)
+ return intErr;
+
+ //for value of ksize_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&ksize_width);
+ if(intErr)
+ return intErr;
+
+ //for value of anchorX
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &anchorX);
+ if(intErr)
+ return intErr;
+
+ //for value of anchorY
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &anchorY);
+ if(intErr)
+ return intErr;
+
+ //applying checks on input parameters
+ Mat new_image(image.rows,image.cols,image.type());
+
+ //error checks
+ if(ksize_height<0)
+ {
+ sciprint("Positive Value Required for Height. 1 value was used instead");
+ ksize_height=1;
+ }
+ if(ksize_width<0)
+ {
+ sciprint("Positive Value Required for Width. 1 value was used instead");
+ ksize_width=1;
+ }
+ if(ksize_width != ksize_height)
+ {
+ sciprint("Blurring Kernel Size not equal. Value of ksize_height used for ksize_width as well");
+ ksize_width = ksize_height;
+ }
+ if(anchorX >= ksize_height || anchorY >= ksize_width)
+ {
+ sciprint("Invalid anchor points. Default point (-1,-1) used instead");
+ anchorY=-1;
+ anchorX=-1;
+ }
+
+ //defining temporary size and point type variables to use in the function
+ Size sz(ksize_height,ksize_width);
+ Point pt(anchorX,anchorY);
+
+ //void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT )
+ blur(image,new_image,sz,pt);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_boundingRect.cpp b/sci_gateway1/cpp/opencv_boundingRect.cpp
new file mode 100644
index 0000000..5bf8707
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_boundingRect.cpp
@@ -0,0 +1,82 @@
+/********************************************************
+ Author: Sukul Bagai
+*********************************************************
+ rectangle_dimensions_arry(height, width, x, y) = boundingRect ( vector<point> )
+********************************************************/
+
+#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_boundingRect(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr1 = NULL;
+ int *piAddrNew = NULL;
+ int i,j,k ;
+ double *points;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+//retreive the points
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols,&points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ vector<Point> actualPoints;
+ for(int i=0;i<iRows;i++)
+ {
+ actualPoints.push_back(Point(*(points + i),*(points + iRows + i)));
+ }
+
+ Rect returnRect;
+ returnRect = boundingRect(actualPoints);
+
+ double arr[4];
+ arr[0]=returnRect.height;
+ arr[1]=returnRect.width;
+ arr[2]=returnRect.x;
+ arr[3]=returnRect.y;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 4, arr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_bundleAdjustment.cpp b/sci_gateway1/cpp/opencv_bundleAdjustment.cpp
new file mode 100644
index 0000000..1d54615
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_bundleAdjustment.cpp
@@ -0,0 +1,382 @@
+/********************************************************
+Author: Suraj Prakash
+[xyxrefinedPoints] = bundleAdjustment(3dpoints, imagepoints, visibility, cameramatrix, rotation, translation, distcoeffs);
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+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_bundleAdjustment(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j;
+
+ int iRows = 0;
+ int iCols = 0;
+ int iRows1 = 0;
+ int iCols1 = 0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ int *piChild = NULL;
+ int *piAddrNew = NULL;
+ int iItem = 0;
+ double *pdblReal = NULL;
+
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+
+ double *cameraMatrix = NULL;
+ double *rotationMatrix = NULL;
+ double *translationMatrix = NULL;
+ double *newCameraMatrix = NULL;
+ double *distCoeffs = NULL;
+
+ /// checking input argument
+
+ CheckInputArgument(pvApiCtx, 7, 7);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // cv::LevMarqSparse::bundleAdjust ( vector< Point3d > & points,
+ // const vector< vector< Point2d > > & imagePoints,
+ // const vector< vector< input > > & visibility,
+ // vector< Mat > & cameraMatrix,
+ // vector< Mat > & R,
+ // vector< Mat > & T,
+ // vector< Mat > & distCoeffs,
+ // const TermCriteria & criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON),
+ // BundleAdjustCallback cb = 0,
+ // void * user_data = 0
+ // )
+
+ /////////// getting the 3d points
+ vector< Point3d > points;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(i=0; i<iRows; i++)
+ {
+ points.push_back(Point3d(pdblReal[i + 0 * iRows], pdblReal[i + 1 * iRows], pdblReal[i + 2 * iRows]));
+ }
+
+ /// getting image points M * N * 2
+
+ double *pstDatax = NULL;
+ double *pstDatay = NULL;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //retrive the matrix of the x coordinates
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDatax);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the y coordinates
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDatay);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ vector< vector< Point2d > > imagePoints;
+
+ imagePoints.resize(iRows);
+
+ for(i=0; i<iRows; ++i){
+ for(j=0; j<iCols; ++j){
+ imagePoints[i].push_back(Point2d(pstDatax[i + iRows * j], pstDatay[i + iRows * j]));
+ }
+ }
+
+
+ /// getting the visibility matrix
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3 , &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ vector< vector < int> > visibility(iRows, vector< int >(iCols, 0));
+
+ for(i=0; i<iRows; ++i){
+ for(j=0; j<iCols; ++j)
+ visibility[i][j] = pdblReal[i + j * iRows];
+ }
+
+
+
+
+ /// M * 3 * 3 camera matrix
+ vector< Mat > camera;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getListItemNumber(pvApiCtx, piAddr, &iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(int item = 0; item<iItem; ++item){
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //retrive the matrix of the camera values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, item + 1, &iRows, &iCols, &cameraMatrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ Mat temp(3, 3, CV_64F);
+
+ for(i=0; i<3; ++i)
+ for(j=0; j<3; ++j)
+ temp.at<double>(i, j) = cameraMatrix[i + j * 3];
+
+ camera.push_back(temp);
+
+ }
+
+ /// M * 3 * 3 rotation matrix
+ vector< Mat > rotation;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getListItemNumber(pvApiCtx, piAddr, &iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(int item = 0; item<iItem; ++item){
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //retrive the matrix of the camera values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, item + 1, &iRows, &iCols, &rotationMatrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ Mat temp(3, 3, CV_64F);
+
+ for(i=0; i<iRows; ++i)
+ for(j=0; j<iCols; ++j)
+ temp.at<double>(i, j) = rotationMatrix[i + j * iRows];
+
+ rotation.push_back(temp);
+
+ }
+
+
+ /// M * 3 * 1 translation matrix
+ vector< Mat > translation;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getListItemNumber(pvApiCtx, piAddr, &iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(int item = 0; item<iItem; ++item){
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //retrive the matrix of the camera values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, item + 1, &iRows, &iCols, &translationMatrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ Mat temp(3, 1, CV_64F);
+
+ for(i=0; i<3; ++i)
+ for(j=0; j<1; ++j)
+ temp.at<double>(i, j) = translationMatrix[i + j * 3];
+
+ translation.push_back(temp);
+
+ }
+
+
+ /// M * (4, 5, 8) * 1 distCoefficients matrix
+ vector< Mat > distCoefficients;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getListItemNumber(pvApiCtx, piAddr, &iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(int item = 0; item<iItem; ++item){
+ sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //retrive the matrix of the camera values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, item + 1, &iRows, &iCols, &distCoeffs);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ Mat temp(iRows, iCols, CV_64F);
+
+ for(i=0; i<iRows; ++i)
+ for(j=0; j<iCols; ++j)
+ temp.at<double>(i, j) = distCoeffs[i + j * iRows];
+
+ distCoefficients.push_back(temp);
+
+ }
+
+ // cv::LevMarqSparse::bundleAdjust ( vector< Point3d > & points,
+ // const vector< vector< Point2d > > & imagePoints,
+ // const vector< vector< input > > & visibility,
+ // vector< Mat > & cameraMatrix,
+ // vector< Mat > & R,
+ // vector< Mat > & T,
+ // vector< Mat > & distCoeffs,
+ // const TermCriteria & criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON),
+ // BundleAdjustCallback cb = 0,
+ // void * user_data = 0
+ // )
+
+ /// TermCriteria
+
+ TermCriteria criteria(CV_TERMCRIT_ITER + CV_TERMCRIT_EPS, 30, DBL_EPSILON);
+
+ LevMarqSparse lms;
+ lms.bundleAdjust(points, imagePoints, visibility, camera, rotation, translation, distCoefficients, criteria);
+
+
+ double *ans = NULL;
+
+ ans = (double*)malloc(sizeof(double) * points.size() * 3);
+
+ for(i = 0; i < points.size(); ++i){
+ ans[i + 0 * points.size()] = points[i].x;
+ ans[i + 1 * points.size()] = points[i].y;
+ ans[i + 2 * points.size()] = points[i].z;
+ }
+
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, points.size(), 3 , ans);
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_cameraMatrix.cpp b/sci_gateway1/cpp/opencv_cameraMatrix.cpp
new file mode 100644
index 0000000..3110017
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_cameraMatrix.cpp
@@ -0,0 +1,186 @@
+/***************************************************
+Author : Tanmay Chaudhari
+ **************************************************/
+
+#include <numeric>
+#include <iostream>
+using namespace std;
+extern "C"
+{
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "BOOL.h"
+#include <localization.h>
+#include "sciprint.h"
+
+ int opencv_cameraMatrix(char *fname, unsigned long fname_len)
+ {
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int iComplex = 0;
+ int iType = 0;
+ int iRows = 0;
+ int iCols = 0;
+ int *piAddr = NULL;
+ double *instrinsicMatrix = NULL;
+ double *rotationMatrix = NULL;
+ double *translationVector = NULL;
+ double *camMatrix = NULL;
+ double *tempMatrix = NULL;
+
+ //Check input output arguments
+ checkInputArgument(pvApiCtx, 3, 3);
+ checkOutputArgument(pvApiCtx, 1, 1);
+
+ //Get variable address of the first input argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &instrinsicMatrix);
+ if(sciErr.iErr || iCols != 3 || iRows != 3)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get variable address of the second input argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &rotationMatrix);
+ if(sciErr.iErr || iCols != 3 || iRows != 3)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get variable address of the first third argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &translationVector);
+ if(sciErr.iErr || iCols != 3 || iRows != 1)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ tempMatrix = (double*)malloc(sizeof(double) * 12);
+
+ for(int i = 0; i < 4; i++)
+ {
+ for(int j = 0; j < 3; j++)
+ {
+ if(i == 3)
+ tempMatrix[j * 4 + i] = translationVector[j];
+ else
+ tempMatrix[j * 4 + i] = rotationMatrix[j * 3 + i];
+ }
+ }
+
+ camMatrix = (double*)malloc(sizeof(double) * 12);
+ for(int i = 0; i < 12; i++)
+ camMatrix[i] = 0;
+
+ for(int i = 0; i < 4; i++)
+ {
+ for(int j = 0; j < 3; j++)
+ {
+ for(int k = 0; k < 3; k++)
+ {
+ camMatrix[j * 4 + i] += (tempMatrix[k * 4 + i] * instrinsicMatrix[j * 3 + k]);
+ }
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, 4, 3, camMatrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Return output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
+
+
+
diff --git a/sci_gateway1/cpp/opencv_canny.cpp b/sci_gateway1/cpp/opencv_canny.cpp
new file mode 100644
index 0000000..010d634
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_canny.cpp
@@ -0,0 +1,121 @@
+/********************************************************
+Authors: Sukul Bagai, Abhilasha Sancheti, Shubheksha Jalan
+********************************************************/
+
+#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_canny(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int i,j,k;
+ double aperture, threshold1, threshold2, gradient;
+ bool L2gradient = false;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+ Mat image;
+ retrieveImage(image, 1);
+ cvtColor( image, image, CV_BGR2GRAY );
+
+ //for value of threshold1
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &threshold1);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //for value of threshold2
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &threshold2);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //for value of aperture
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &aperture);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //for value of gradient as an integer and convert to bool accordingly
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &gradient);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if ( gradient == 1){
+ L2gradient = true;
+ }
+ Mat new_image;
+ Canny(image, new_image, threshold1, threshold2, aperture, L2gradient);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_circle.cpp b/sci_gateway1/cpp/opencv_circle.cpp
new file mode 100644
index 0000000..928c251
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_circle.cpp
@@ -0,0 +1,203 @@
+/********************************************************
+ Author: Abhilasha Sancheti
+*********************************************************
+ return_image = circle(input_image , x_coordinate_of_centre , y_coordinate_centre , radius, r_value,g_value,b_value,thickness,linetype,shift);
+********************************************************/
+
+#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_circle(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int *piAddr9 = NULL;
+ int *piAddr10 = NULL;
+ int i,j,k;
+ double thickness=1 , linetype=8,shift =0 ,centre_x ,centre_y,radius,r_value,g_value,b_value;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 10, 10);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat src;
+ retrieveImage(src,1);
+
+ //for value of x coordinate of centre
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2,&centre_x);
+ if(intErr)
+ return intErr;
+
+
+ //for value of y coordinate of centre
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&centre_y);
+ if(intErr)
+ return intErr;
+
+ //for value of radius
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&radius);
+ if(intErr)
+ return intErr;
+
+ //for value of R value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&r_value);
+ if(intErr)
+ return intErr;
+
+ //for value of G value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6 ,&g_value);
+ if(intErr)
+ return intErr;
+
+ // for B value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7,&b_value);
+ if(intErr)
+ return intErr;
+
+ // for thickness of circle default: 1
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr8,&thickness);
+ if(intErr)
+ return intErr;
+
+ //for line type of circle default: 8
+ sciErr = getVarAddressFromPosition(pvApiCtx,9,&piAddr9);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr9,&linetype);
+ if(intErr)
+ return intErr;
+
+ // for shift in circle defulat : 0
+ sciErr = getVarAddressFromPosition(pvApiCtx,10,&piAddr10);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Syntax: sciErr = getMatrixOfInteger8(pvApiCtx, piAddr8, &iRows8, &iCols8, &pcData);
+ intErr = getScalarDouble(pvApiCtx, piAddr10,&shift);
+ if(intErr)
+ return intErr;
+
+ // checking radius parameter
+ if (radius <0)
+ {
+ radius=3;
+ sciprint("Radius should be positive , 3 value was used instead\n");
+ }
+ // checking the parmeters for correct values
+ if( r_value <0 || r_value >255)
+ {
+ r_value=0;
+ sciprint(" r value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( g_value <0 || g_value >255)
+ {
+ g_value=0;
+ sciprint(" g value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( b_value <0 || b_value >255)
+ {
+ b_value=0;
+ sciprint(" b value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if ((linetype!=0) && (linetype!=4)&& (linetype!=8))
+ {
+ linetype=8;
+ sciprint("Only 0/4/8 allowed , using 8 instead\n");
+ }
+ //temporary pt variable, to use in function as centre
+ Point pt(centre_x,centre_y);
+ /// Draw the circles detected
+
+ circle( src, pt, radius, Scalar(r_value,g_value,b_value), thickness, linetype, shift);
+
+//// sending the image
+ string tempstring = type2str(src.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,src,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_clipline.cpp b/sci_gateway1/cpp/opencv_clipline.cpp
new file mode 100644
index 0000000..2e13412
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_clipline.cpp
@@ -0,0 +1,149 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ return_image = clipline( width, height, x1 , y1 , x2,y2 )
+********************************************************/
+
+#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_clipline(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int i,j,k;
+ double x1,y1,x2,y2,width,height;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 6, 6);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ //for width of the rectangle
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr1 ,&width);
+ if(intErr)
+ return intErr;
+
+ // for height of the rectangle
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2,&height);
+ if(intErr)
+ return intErr;
+
+ //for value of x coordinate of first point
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &x1);
+ if(intErr)
+ return intErr;
+
+ //for value of y coordinate of first point
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&y1);
+ if(intErr)
+ return intErr;
+
+ //for value of x coordinate of second point
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5,&x2);
+ if(intErr)
+ return intErr;
+
+ ///for value of y coordinate of second point
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6 ,&y2);
+ if(intErr)
+ return intErr;
+
+
+ if(height<0)
+ {
+ sciprint("Positive Value Required for Height. 1 value was used instead");
+ height=1;
+ }
+ if(width<0)
+ {
+ sciprint("Positive Value Required for Width. 1 value was used instead");
+ width=1;
+ }
+ //temporary pt1 variable, to use in function as first line point
+ Point pt1(x1,y1);
+ //temporary pt2 variable, to use in function as second line point
+ Point pt2(x2,y2);
+ // image size
+ Size sz(width,height);
+ Rect r(0,0,width,height);
+ //// calling open cv clipLine function
+
+ bool ans = clipLine( sz , pt1, pt2);
+ int actualans=(int)ans;
+
+ // returning the result to the scilab environment
+ // Syntax: SciErr createMatrixOfBoolean(void* _pvCtx, int _iVar, int _iRows, int _iCols, const int* _piBool)
+ intErr= createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, actualans);
+ if(intErr)
+ return intErr;
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_convexhull.cpp b/sci_gateway1/cpp/opencv_convexhull.cpp
new file mode 100644
index 0000000..934fa20
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_convexhull.cpp
@@ -0,0 +1,140 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ hull = convexhull ( contour(vector<point>), clockwise(1/0) , returnpoints(1/0) )
+********************************************************/
+
+#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_convexhull(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr1 = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ double *pstData = NULL;
+ int i,j,k ;
+ double clkwise;
+ double returnpoints;
+
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+//retreive the contour parameter
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols,&pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //cout<<*(pstData + 0*2 + 0)<<" "<<*(pstData + 0*2 + 1)<<endl;
+ //cout<<*(pstData + 1*2 + 2)<<" "<<*(pstData + 1*2 + 3);
+///// store values in a contour
+ int rows = iRows;
+ vector<Point> cont1;
+ for ( i = 0 ; i < iRows ; i++)
+ {
+ Point pt(*(pstData + 0*iRows + i),*(pstData + 1*iRows + i));
+ cont1.push_back(pt);
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2 ,&clkwise);
+ if(intErr)
+ return intErr;
+
+
+
+//// to retreive the value of returnpoint
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&returnpoints);
+ if(intErr)
+ return intErr;
+
+
+ bool clkWise, returnPoint;
+/// setting clkwise parameter of function
+ if ( clkwise ==1)
+ clkWise = true;
+ else if (clkwise == 0)
+ clkWise = false;
+ else
+ {
+ clkWise = false;
+ sciprint("only 0/1 acceptable , taking 0 instead");
+ }
+///// setting returnpoint parameter of function
+ if ( returnpoints ==1)
+ returnPoint = true;
+ else if (returnpoints == 0)
+ returnPoint = false;
+ else
+ {
+ returnPoint = true;
+ sciprint("only 0/1 acceptable , taking 1 instead");
+ }
+
+ vector<Point> hull;
+ convexHull(Mat(cont1), hull , clkWise , returnPoint);
+ int row = hull.size();
+ double *cor = (double *)malloc(row*2*sizeof(double));
+ for (int i=0;i<row;i++)
+ {
+ *(cor + i*2 +0)=hull[i].x;
+ cout<<hull[i].x<<" "<<hull[i].y;
+ *(cor + i*2 +1)=hull[i].y;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, row, 2, cor);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_convolver.cpp b/sci_gateway1/cpp/opencv_convolver.cpp
new file mode 100644
index 0000000..8ffc67b
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_convolver.cpp
@@ -0,0 +1,243 @@
+/******************************************************************************************
+*Author : Kevin George
+*
+*-> To execute, Image = convolver(I1, size, values,scalar)
+* where 'I1' is image to be convoluted,
+* where 'size' is size of kernel i.e size x size gives total no. of values in kernel,
+* where 'values' contains the values of the kernel
+* where 'scalar' is a float value
+*
+*******************************************************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include <iostream>
+#include <math.h>
+#include <vector>
+
+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"
+ // # include "../common.cpp"
+
+ int opencv_convolver(char *fname, unsigned long fname_len)
+ {
+ //-> Error Management variables
+ SciErr sciErr;
+ int intErr=0;
+
+ //-> Mat containers for images
+ Mat image_1;
+ Mat image_2;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+
+ //-> Local Variables
+ double *values1 = NULL;
+ float *values2 =NULL;
+ double size;
+ double scalar;
+ int iRows = 0;
+ int iCols = 0;
+ int *outList = NULL;
+ unsigned char *red = NULL;
+ unsigned char *green = NULL;
+ unsigned char *blue = NULL;
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ CheckInputArgument(pvApiCtx, 1, 5); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 5); //Check on Number of Output Arguments
+
+ //-> Read Image
+ retrieveImage( image_1, 1);
+ //retrieveImage(image_2, 2);
+
+ //-> Count number of input arguments
+ //num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ //-> Based on number of input arguments
+
+//***************************************************** Actual Processing *************************************************************
+
+ //-> Taking in size of kernel
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //intErr = getScalarInteger32(pvApiCtx, piAddr, &size);
+ intErr = getScalarDouble(pvApiCtx, piAddr, &size);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if( size > 5)
+ {
+ Scierror(999," Invalid Value size. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ //-> Taking the kernel values
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &values1);
+ //sciErr = getMatrixOfInteger32(pvApiCtx, piAddr, &iRows, &iCols, &values);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows*iCols!=9 && iRows*iCols!=16 && iRows*iCols!=25 )
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ values2 = (float*)malloc(sizeof(float)*size*size);
+ for(int i=0; i<size*size; i++)
+ {
+ values2[i] = (float)values1[i];
+ }
+
+
+ //-> Taking scalar values
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr, &scalar);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if( scalar == 0)
+ {
+ Scierror(999," Invalid scalar value. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ //float kdata[] = {1, 4, 6, -1, 3, 5, -1, -2, 2};
+ Mat kernel(size,size,CV_32F, values2);
+
+ Mat kernel2 = kernel/ (float)(scalar);
+
+ Point anchor;
+ double delta;
+ int ddepth;
+
+ anchor = Point( -1, -1 );
+ delta = 0;
+ ddepth = -1;
+
+ //filter2D(image_1, image_2, CV_32F, kernel);
+ filter2D(image_1, image_2, ddepth,kernel2,anchor,delta, BORDER_DEFAULT);
+
+ //imshow("Convoluted Image",image_2);
+ //waitKey(0);
+
+ if( image_2.channels() == 1)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ red = (unsigned char *)malloc(sizeof(unsigned char)*image_2.rows*image_2.cols);
+
+ for(int k=0;k<image_2.rows;k++)
+ for(int p=0;p<image_2.cols;p++)
+ red[k+image_2.rows*p]=image_2.at<uchar>(k, p);
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, image_2.rows, image_2.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ }
+
+ else
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red = (unsigned char *)malloc(sizeof(unsigned char)*image_2.rows*image_2.cols);
+ green = (unsigned char *)malloc(sizeof(unsigned char)*image_2.rows*image_2.cols);
+ blue = (unsigned char *)malloc(sizeof(unsigned char)*image_2.rows*image_2.cols);
+
+ for(int k=0;k<image_2.rows;k++)
+ {
+ for(int p=0;p<image_2.cols;p++)
+ {
+ Vec3b intensity = image_2.at<Vec3b>(k, p);
+ red[k+image_2.rows*p]=intensity.val[2];
+ green[k+image_2.rows*p]=intensity.val[1];
+ blue[k+image_2.rows*p]=intensity.val[0];
+ }
+ }
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, image_2.rows, image_2.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 2, image_2.rows, image_2.cols, green);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 3, image_2.rows, image_2.cols, blue);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ free(green);
+ free(blue);
+
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_copymakeborder.cpp b/sci_gateway1/cpp/opencv_copymakeborder.cpp
new file mode 100644
index 0000000..51175fb
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_copymakeborder.cpp
@@ -0,0 +1,195 @@
+/********************************************************
+ Author: Shubheksha Jalan
+*********************************************************
+ void copyMakeBorder(InputArray image, int top, int bottom, int left, int right, int borderType, const Scalar& value=Scalar() )
+********************************************************/
+// for BORDER_CONSTANT, enter a 4 element array as Scalar. For any other border type, pass 0.
+
+
+#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_copymakeborder(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int i,j,k;
+ char **borderType;
+ double top, bottom, right, left;
+ double *value = NULL;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 6, 7);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for top
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &top);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for bottom
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &bottom);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for left
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &left);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for bottom
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &right);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr6, &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, piAddr6, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr6, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for array of Scalar object
+ sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr7, &iRows, &iCols ,&value);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ Mat new_image(Size(image.cols+left+right, image.rows+top+bottom), image.type());
+
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0 && iCols == 4 )
+ copyMakeBorder(image, new_image, top, bottom, left, right, BORDER_CONSTANT, Scalar(value[0], value[1], value[2], value[3]));
+ else if(strcmp(borderType[0], "BORDER_CONSTANT") == 0 && iCols == 3)
+ copyMakeBorder(image, new_image, top, bottom, left, right, BORDER_CONSTANT, Scalar(value[0], value[1], value[2]));
+ else if(strcmp(borderType[0], "BORDER_DEFAULT") == 0)
+ copyMakeBorder(image, new_image, top, bottom, left, right, BORDER_DEFAULT);
+ else if(strcmp(borderType[0], "BORDER_REPLICATE") == 0)
+ copyMakeBorder(image, new_image, top, bottom, left, right, BORDER_REPLICATE);
+ else if(strcmp(borderType[0], "BORDER_REFLECT") == 0)
+ copyMakeBorder(image, new_image, top, bottom, left, right, BORDER_REFLECT);
+ else if(strcmp(borderType[0], "BORDER_REFLECT_101") == 0)
+ copyMakeBorder(image, new_image, top, bottom, left, right, BORDER_REFLECT_101);
+ else if(strcmp(borderType[0], "BORDER_WRAP") == 0)
+ copyMakeBorder(image, new_image, top, bottom, left, right, BORDER_WRAP);
+
+ // namedWindow ("window", 1);
+ // imshow("window", new_image);
+ // waitKey(0);
+ // destroyWindow("window");
+
+free(borderType);
+
+string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_corner.cpp b/sci_gateway1/cpp/opencv_corner.cpp
new file mode 100644
index 0000000..96c1f4c
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_corner.cpp
@@ -0,0 +1,469 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include <iostream>
+#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 "sciprint.h"
+ #include "../common.h"
+
+ /*Calling syntax: corner(I) or corner(I, Name, Value)
+ which uses additional options specified by one or more Name, Value pair arguments.
+ Arguments Allowed: MinQuality, FilterSize, ROI, SensitivityFactor
+ MinQuality : The minimum accepted quality of corners represents a fraction of the
+ maximum corner metric value in the image. Larger values can be used
+ to remove erroneous corners.
+ FilterSize : Gaussian filter dimension
+ ROI : Rectangular region for corner detection
+ SensitivityFactor : A scalar value, K, where 0 < K < 0.25, specifying the sensitivity
+ factor used in the Harris detection algorithm.
+ Method : Whether to use 'Harris' or 'MinimumEigenValue' technique */
+
+ int opencv_corner(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+ int intErr;
+
+ //------Local variables------//
+ int *location = NULL;
+ double *metric = NULL;
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ int nbInputArguments;
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+ double *matrixOfRoi; // ROI[xStart, yStart, width, height]
+ int iRows, iCols;
+ Mat sourceImage, dst, dstThresholded, ucharDstThresholded, extended;
+ vector<vector<Point> > contours;
+ char *method;
+ double filterSize = 5, minQuality = 0.01, sensitivityFactor = 0.04, blockSize = 2, maxDst, localMax;
+ bool *included = NULL;
+ int pointCount = 0, localMaxPos;
+ double tempForSwapping;
+ int coordinateMin, coordinatePos;
+
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 1, 11);
+ CheckOutputArgument(pvApiCtx, 1, 3);
+
+ //------Get input arguments------//
+ retrieveImage(sourceImage, 1);
+ if(sourceImage.channels() != 1)
+ {
+ Scierror(999, "The input image is not a grayscale image.");
+ return 0;
+ }
+ matrixOfRoi = (double*) malloc(sizeof(double) * 4);
+ providedArgs = (bool*) malloc(sizeof(bool) * 5);
+ memset(providedArgs, 0, 5);
+ method = "Harris";
+ matrixOfRoi[0] = 0;
+ matrixOfRoi[1] = 0;
+ matrixOfRoi[2] = sourceImage.cols;
+ matrixOfRoi[3] = sourceImage.rows;
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ // The following loop is for checking if optional arguments have been provided
+ for(int iter=2; iter <= nbInputArguments; iter++)
+ {
+ // Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ // providedArgs[] makes sure that no optional argument is provided more than once
+ if(strcmp(currentArg, "MinQuality")==0)
+ {
+ if(iter+1<=nbInputArguments && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &minQuality);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(minQuality < 0 || minQuality > 1)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible range is [0, 1].\n", currentArg);
+ return 0;
+ }
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "FilterSize")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &filterSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+ providedArgs[1] = 1;
+ if(filterSize!=1 && filterSize!=3 && filterSize!=5 && filterSize!=7)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are {1, 3, 5, 7}.\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[1])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "ROI")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, iter);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &matrixOfRoi);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1 || iCols!=4)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument ROI.\n");
+ return 0;
+ }
+ providedArgs[2] = 1;
+ if(matrixOfRoi[0] < 0 || matrixOfRoi[0] > sourceImage.cols || matrixOfRoi[1] < 0 ||
+ matrixOfRoi[1] > sourceImage.rows || matrixOfRoi[2] < 0 || matrixOfRoi[0] + matrixOfRoi[2] > sourceImage.cols
+ || matrixOfRoi[3] < 0 || matrixOfRoi[1] + matrixOfRoi[3] > sourceImage.rows)
+ {
+ Scierror(999, "Error: Please provide proper values for \"%s\".\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[2])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "SensitivityFactor")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &sensitivityFactor);
+ if(intErr)
+ {
+ return intErr;
+ }
+ providedArgs[3] = 1;
+ if(sensitivityFactor < 0 || sensitivityFactor > 0.25)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are [0, 0.25].\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[3])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "Method")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[4])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ method = pstData[0];
+ providedArgs[4] = 1;
+ if(strcmp(method, "Harris") !=0 && strcmp(method, "MinimumEigenValue") !=0)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are [\"Harris\" , \"MinimumEigenValue\"].\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[4])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999, "Error: \"%s\" name for input argument is not valid.\n", currentArg);
+ return 0;
+ }
+ }
+
+ //------Actual processing------//
+ if(strcmp(method, "Harris") == 0)
+ {
+ cornerHarris(sourceImage(Rect(matrixOfRoi[0], matrixOfRoi[1], matrixOfRoi[2], matrixOfRoi[3])), dst, blockSize, filterSize, sensitivityFactor, BORDER_DEFAULT);
+ }
+ else
+ {
+ cornerMinEigenVal(sourceImage(Rect(matrixOfRoi[0], matrixOfRoi[1], matrixOfRoi[2], matrixOfRoi[3])), dst, blockSize, filterSize, BORDER_DEFAULT);
+ }
+ // Finding the maximum value at a pixel in dst
+ maxDst = 0;
+ for(int rowIter=0; rowIter < dst.rows; rowIter++)
+ {
+ for(int colIter=0; colIter < dst.cols; colIter++)
+ {
+ if(dst.at<float>(rowIter, colIter) > maxDst)
+ {
+ maxDst = dst.at<float>(rowIter, colIter);
+ }
+ }
+ }
+
+ /* First, we threshold dst according to the minQuality expected by the user.
+ We then find contours in the thresholded image and check each pixel's value
+ to compute the local maxima. A extended mat is created because contours
+ having edges on the boundaries of the images are not considered by
+ findContours */
+ threshold(dst, dstThresholded, maxDst*minQuality, 255, THRESH_BINARY);
+ dstThresholded.convertTo(ucharDstThresholded, CV_8UC1);
+ extended = Mat(dst.rows+2, dst.cols+2, CV_8UC1);
+ for(int rowIter = 0; rowIter < extended.rows; rowIter++)
+ {
+ for(int colIter = 0; colIter < extended.cols; colIter++)
+ {
+ if(rowIter == 0 || rowIter == extended.rows - 1
+ || colIter == 0 || colIter == extended.cols - 1)
+ {
+ extended.at<uchar>(rowIter, colIter) = 0;
+ }
+ else
+ {
+ extended.at<uchar>(rowIter, colIter) = ucharDstThresholded.at<uchar>(rowIter-1, colIter-1);
+ }
+ }
+ }
+
+ findContours(extended, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
+ pointCount = contours.size();
+ location = (int*) malloc(sizeof(int) * pointCount * 2);
+ metric = (double*) malloc(sizeof(double)*pointCount);
+ for(int rowIter = 0; rowIter < contours.size(); rowIter++)
+ {
+ localMax = 0;
+ localMaxPos = 0;
+ for(int colIter=0; colIter<contours[rowIter].size(); colIter++)
+ {
+ if(dst.at<float>(contours[rowIter][colIter].y-1, contours[rowIter][colIter].x-1)>localMax)
+ {
+ localMax = dst.at<float>(contours[rowIter][colIter].y-1, contours[rowIter][colIter].x-1);
+ localMaxPos = colIter;
+ }
+ }
+ if(localMax > maxDst*minQuality)
+ {
+ location[rowIter] = contours[rowIter][localMaxPos].x-1 + matrixOfRoi[0];
+ location[pointCount + rowIter] = contours[rowIter][localMaxPos].y-1 + matrixOfRoi[1];
+ metric[rowIter] = dst.at<float>(location[pointCount + rowIter], location[rowIter]);
+ }
+ }
+
+ // To return coordinates in order
+ for(int iter1 = 0; iter1 < pointCount - 1; iter1++)
+ {
+ coordinateMin = location[iter1];
+ coordinatePos = iter1;
+ for(int iter2 = iter1 + 1; iter2 < pointCount; iter2++)
+ {
+ if(location[iter2] < coordinateMin)
+ {
+ coordinateMin = location[iter2];
+ coordinatePos = iter2;
+ }
+ else if(location[iter2] == coordinateMin)
+ {
+ if(location[pointCount + iter2] < location[pointCount + coordinatePos])
+ {
+ coordinateMin = location[iter2];
+ coordinatePos = iter2;
+ }
+ }
+ }
+ // Swapping x coordinate
+ tempForSwapping = location[coordinatePos];
+ location[coordinatePos] = location[iter1];
+ location[iter1] = tempForSwapping;
+ // Swapping y coordinate
+ tempForSwapping = location[pointCount + coordinatePos];
+ location[pointCount + coordinatePos] = location[pointCount + iter1];
+ location[pointCount + iter1] = tempForSwapping;
+ // Swapping metric
+ tempForSwapping = metric[coordinatePos];
+ metric[coordinatePos] = metric[iter1];
+ metric[iter1] = tempForSwapping;
+ }
+
+ //------Create output arguments------//
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+1, pointCount, 2, location);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx)+2, pointCount, 1, metric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+3, 1, 1, &pointCount);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx)+2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx)+3;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_cornerEigenValsAndVecs.cpp b/sci_gateway1/cpp/opencv_cornerEigenValsAndVecs.cpp
new file mode 100644
index 0000000..205759d
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_cornerEigenValsAndVecs.cpp
@@ -0,0 +1,127 @@
+/********************************************************
+Author: Shubheksha Jalan
+********************************************************/
+
+#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 "../common.h"
+
+
+ int opencv_cornerEigenValsAndVecs(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int i,j,k;
+ double blockSize, ksize;
+ char **borderType;
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+ cvtColor(image,image,CV_BGR2GRAY);
+
+ //for block size
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &blockSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for ksize
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &ksize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for border type
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &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, piAddr4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ Mat new_image;
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0){
+ cornerEigenValsAndVecs(image, new_image, blockSize, ksize, BORDER_CONSTANT);
+ }
+ else if(strcmp(borderType[0], "BORDER_DEFAULT") == 0)
+ cornerEigenValsAndVecs(image, new_image, blockSize, ksize, BORDER_DEFAULT);
+ free(borderType);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_cornerHarris.cpp b/sci_gateway1/cpp/opencv_cornerHarris.cpp
new file mode 100644
index 0000000..d517eec
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_cornerHarris.cpp
@@ -0,0 +1,144 @@
+/********************************************************
+Author: Shubheksha Jalan
+********************************************************/
+
+#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 "../common.h"
+
+
+ int opencv_cornerHarris(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int i,j;
+ double blockSize, ksize, k;
+ char **borderType;
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+ cvtColor(image,image,CV_BGR2GRAY);
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &blockSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for ksize
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &ksize);
+ if(intErr)
+ {
+ return intErr;
+ }
+//for value of k
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &k);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for border type
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr5, &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, piAddr5, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr5, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ cout<<"String\n";
+
+ Mat new_image(image.rows, image.cols, CV_32FC1);
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0){
+ cornerHarris(image, new_image, blockSize, ksize, k, BORDER_CONSTANT);
+ }
+ else if(strcmp(borderType[0], "BORDER_DEFAULT") == 0)
+ cornerHarris(image, new_image, blockSize, ksize, k, BORDER_DEFAULT);
+
+ namedWindow ("window", 1);
+ imshow("window", new_image);
+ waitKey(0);
+ destroyWindow("window");
+
+ new_image.convertTo(new_image, CV_32FC1, 1.0/255.0);
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_cornerMinEigenVal.cpp b/sci_gateway1/cpp/opencv_cornerMinEigenVal.cpp
new file mode 100644
index 0000000..19123e5
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_cornerMinEigenVal.cpp
@@ -0,0 +1,125 @@
+/********************************************************
+Author: Shubheksha Jalan
+********************************************************/
+
+#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 "../common.h"
+
+
+ int opencv_cornerMinEigenVal(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int i,j,k;
+ double blockSize, ksize;
+ char **borderType;
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+ cvtColor(image,image,CV_BGR2GRAY);
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &blockSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for ksize
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &ksize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for border type
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &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, piAddr4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ cout<<"String\n";
+
+ Mat new_image;
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0){
+ cornerMinEigenVal(image, new_image, blockSize, ksize, BORDER_CONSTANT);
+ }
+ else if(strcmp(borderType[0], "BORDER_DEFAULT") == 0)
+ cornerMinEigenVal(image, new_image, blockSize, ksize, BORDER_DEFAULT);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_cvtColor.cpp b/sci_gateway1/cpp/opencv_cvtColor.cpp
new file mode 100644
index 0000000..2959dda
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_cvtColor.cpp
@@ -0,0 +1,183 @@
+/********************************************************
+ Author: Shubheksha Jalan
+*********************************************************
+ void cvtColor(InputArray src, int code, int dstCn=0 )
+********************************************************/
+// number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code
+
+
+#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 "sciprint.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+
+ int opencv_cvtColor(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piLen = NULL;
+ double dstCn;
+ int code;
+ char **codeString = NULL;
+ int i, j, k;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 3);
+ CheckOutputArgument(pvApiCtx, 1,1) ;
+
+
+ Mat src;
+ retrieveImage(src,1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ codeString = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ codeString[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, codeString);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &dstCn);
+ if(intErr){
+ return intErr;
+ }
+
+ Mat dst;
+
+ if(strcmp(codeString[0], "CV_BGR2GRAY") == 0)
+ code = CV_BGR2GRAY;
+ else if(strcmp(codeString[0], "CV_RGB2GRAY") == 0)
+ code = CV_RGB2GRAY;
+ else if(strcmp(codeString[0], "CV_GRAY2BGR") == 0)
+ code = CV_GRAY2BGR;
+ else if(strcmp(codeString[0], "CV_GRAY2RGB") == 0)
+ code = CV_GRAY2RGB;
+ else if(strcmp(codeString[0], "CV_BGR2XYZ") == 0)
+ code = CV_BGR2XYZ;
+ else if(strcmp(codeString[0], "CV_RGB2XYZ") == 0)
+ code = CV_RGB2XYZ;
+ else if(strcmp(codeString[0], "CV_XYZ2BGR") == 0)
+ code = CV_XYZ2BGR;
+ else if(strcmp(codeString[0], "CV_XYZ2RGB") == 0)
+ code = CV_XYZ2RGB;
+ else if(strcmp(codeString[0], "CV_BGR2YCrCb") == 0)
+ code = CV_BGR2YCrCb;
+ else if(strcmp(codeString[0], "CV_RGB2YCrCb") == 0)
+ code = CV_RGB2YCrCb;
+ else if(strcmp(codeString[0], "CV_YCrCb2BGR") == 0)
+ code = CV_YCrCb2BGR;
+ else if(strcmp(codeString[0], "CV_YCrCb2RGB") == 0)
+ code = CV_YCrCb2RGB;
+ else if(strcmp(codeString[0], "CV_BGR2HSV") == 0)
+ code = CV_BGR2HSV;
+ else if(strcmp(codeString[0], "CV_RGB2HSV") == 0)
+ code = CV_RGB2HSV;
+ else if(strcmp(codeString[0], "CV_HSV2BGR") == 0)
+ code = CV_HSV2BGR;
+ else if(strcmp(codeString[0], "CV_HSV2RGB") == 0)
+ code = CV_HSV2RGB;
+ else if(strcmp(codeString[0], "CV_BGR2HLS") == 0)
+ code = CV_BGR2HLS;
+ else if(strcmp(codeString[0], "CV_RGB2HLS") == 0)
+ code = CV_RGB2HLS;
+ else if(strcmp(codeString[0], "CV_HLS2BGR") == 0)
+ code = CV_HLS2BGR;
+ else if(strcmp(codeString[0], "CV_HLS2RGB") == 0)
+ code = CV_HLS2RGB;
+ else if(strcmp(codeString[0], "CV_BGR2Lab") == 0)
+ code = CV_BGR2Lab;
+ else if(strcmp(codeString[0], "CV_RGB2Lab") == 0)
+ code = CV_RGB2Lab;
+ else if(strcmp(codeString[0], "CV_Lab2BGR") == 0)
+ code = CV_Lab2BGR;
+ else if(strcmp(codeString[0], "CV_Lab2RGB") == 0)
+ code = CV_Lab2RGB;
+ else if(strcmp(codeString[0], "CV_BGR2Luv") == 0)
+ code = CV_BGR2Luv;
+ else if(strcmp(codeString[0], "CV_RGB2Luv") == 0)
+ code = CV_RGB2Luv;
+ else if(strcmp(codeString[0], "CV_Luv2BGR") == 0)
+ code = CV_Luv2BGR;
+ else if(strcmp(codeString[0], "CV_Luv2RGB") == 0)
+ code = CV_Luv2RGB;
+ else{
+
+ sciprint("Invalid code");
+ return 0;
+ }
+
+ cvtColor(src, dst, code, dstCn);
+
+ // namedWindow ("window", 1);
+ // imshow("window", dst);
+ // waitKey(0);
+ // destroyWindow("window");
+
+
+ string tempstring = type2str(dst.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ free(checker);
+
+
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_demosaic.cpp b/sci_gateway1/cpp/opencv_demosaic.cpp
new file mode 100644
index 0000000..4c2ee4b
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_demosaic.cpp
@@ -0,0 +1,127 @@
+/********************************************************
+ Author: V Srinivas
+*********************************************************
+ void cvtColor(InputArray src, int code, int dstCn=0 )
+********************************************************/
+//Demosaicing using cvt color filter
+
+#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 "sciprint.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+
+ int opencv_demosaic(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piLen = NULL;
+ double dstCn;
+ int code;
+ char **codeString = NULL;
+ int i, j, k;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2,2);
+ CheckOutputArgument(pvApiCtx, 1,1) ;
+
+
+ Mat src;
+ retrieveImage(src,1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return -1;
+ }
+
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return -1;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return -1;
+ }
+
+ codeString = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ codeString[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, codeString);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+
+ Mat dst;
+
+ if(strcmp(codeString[0], "gbrg") == 0)
+ code = CV_BayerGR2RGB;
+ else if(strcmp(codeString[0], "bggr") == 0)
+ code = CV_BayerRG2RGB;
+ else if(strcmp(codeString[0], "rggb") == 0)
+ code = CV_BayerBG2RGB;
+ else if(strcmp(codeString[0], "grbg") == 0)
+ code = CV_BayerGB2RGB;
+ else{
+
+ sciprint("Invalid Bayer filter code");
+ return 0;
+ }
+
+ cvtColor(src, dst, code, 0);
+
+ // namedWindow ("window", 1);
+ // imshow("window", dst);
+ // waitKey(0);
+ // destroyWindow("window");
+
+
+ string tempstring = type2str(dst.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ free(checker);
+
+
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_detectBRISKFeatures.cpp b/sci_gateway1/cpp/opencv_detectBRISKFeatures.cpp
new file mode 100644
index 0000000..e6ded8e
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_detectBRISKFeatures.cpp
@@ -0,0 +1,421 @@
+/***************************************************
+Author : Shashank Shekhar
+***************************************************/
+#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_detectBRISKFeatures(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int *piAddrVal = NULL;
+ int argPresence[4];
+ for(int i=0;i<4;i++)
+ argPresence[i]=0;
+ int val_position;
+ int iRows = 0;
+ int iCols = 0;
+ int *piLen = NULL;
+ char ** pstData = NULL;
+ char *currentArg = NULL;
+
+
+// DECLARING INPUT ARGUMENTS
+
+ double *ROImat = NULL;
+ double NumOctaves = 0;
+ double MinContrast = 0;
+ double MinQuality = 0;
+
+
+// DECLARING OUTPUT ARGUMENTS
+
+ vector<KeyPoint> myPoints;
+ int *LocationList = NULL;
+ double *LocationData = NULL;
+ double *OrientationData = NULL;
+ double *ScaleData = NULL;
+ double *MetricData = NULL;
+ int size;
+
+// ARGUMENT CHECK
+
+ CheckInputArgument(pvApiCtx, 1,9);
+ CheckOutputArgument(pvApiCtx,1,5);
+
+// RETRIEVING IMAGE
+
+ Mat image;
+ retrieveImage(image,1);
+
+// GRAYSCALE VALIDATION
+
+ if(image.channels()!=1)
+ {
+ Scierror(999," Feature is not meant for RGB images\n");
+ return 0;
+ }
+
+// OBTAINING NUMBER OF ARGUMENTS
+
+ int noOfarguments = *getNbInputArgument(pvApiCtx);
+
+// ARGUMENT COUNT CHECK
+
+ if(noOfarguments%2==0)
+ {
+ Scierror(999," Invalid Number Of Arguments\n");
+ return 0;
+ }
+
+// MULTIPLE ARGUMENT HANDLING
+
+ for(int i=2;i<noOfarguments;i=i+2)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,i,&piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isStringType(pvApiCtx, piAddr))
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ //first call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j = 0 ; j < iRows * iCols ; j++)
+ {
+ pstData[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+ if(strcmp(currentArg,"MinContrast")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[0]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal))
+ {
+ Scierror(999,"Invalid Value for MinContrast. Please enter a value between 0 and 1\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &MinContrast);
+
+ if(MinContrast<0 || MinContrast>1)
+ {
+ Scierror(999,"Invalid Value for MinContrast. Please enter a value between 0 and 1\n");
+ return 0;
+ }
+
+ argPresence[0]=1;
+ }
+ else if(strcmp(currentArg,"NumOctaves")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[1]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for NumOctaves. Recommended values are between 1 and 4\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &NumOctaves);
+ if(NumOctaves<1)
+ {
+ Scierror(999," Invalid Value for NumOctaves. Recommended values are between 1 and 4\n");
+ return 0;
+ }
+ argPresence[1]=1;
+ }
+ else if(strcmp(currentArg,"MinQuality")==0)
+ {
+ val_position=i+1;
+
+
+ if(argPresence[2]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for MinQuality. Recommended values are between 0 and 1\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &MinQuality);
+
+ if(MinQuality<0 || MinQuality>1)
+ {
+ Scierror(999," Invalid Value for MinQuality. Please enter a value between 0 and 1 \n");
+ return 0;
+ }
+
+ argPresence[2]=1;
+ }
+ else if(strcmp(currentArg,"ROI")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[3]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx, piAddrVal))
+ {
+ Scierror(999,"Enter a List of 4 arguments\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddrVal, &iRows, &iCols, &ROImat);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows*iCols!=4)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ if(ROImat[0]<0 || ROImat[1]<0 || ROImat[2]<0 || ROImat[3]<0)
+ {
+ Scierror(999,"Arguments cannot be negative\n");
+ return 0;
+ }
+
+ if(ROImat[0]>image.cols || ROImat[1]>image.rows || ROImat[0]+ROImat[2]>image.cols
+ || ROImat[1]+ROImat[3]>image.rows)
+ {
+ Scierror(999,"Please make sure the arguments are within the image range\n");
+ return 0;
+ }
+
+ argPresence[3]=1;
+ }
+ else
+ {
+ Scierror(999, "Error: \"%s\" Invalid input argument.\n", currentArg);
+ return 0;
+ }
+
+ }
+
+
+// DEFAULT ARGUMENTS
+
+ if(argPresence[0]==0)
+ MinContrast=0.2;
+ if(argPresence[1]==0)
+ NumOctaves=4;
+ if(argPresence[2]==0)
+ MinQuality=0.1;
+ if(argPresence[3]==0)
+ {
+ ROImat=(double *)malloc(sizeof(double)*1*4);
+ ROImat[0]=0;
+ ROImat[1]=0;
+ ROImat[2]=image.cols;
+ ROImat[3]=image.rows;
+ }
+
+// CREATING REGION OF INTEREST
+
+ Rect masker(ROImat[0], ROImat[1], ROImat[2], ROImat[3]);
+
+ Mat mask(image.size(), CV_8UC1, Scalar::all(0));
+ mask(masker).setTo(Scalar::all(255));
+
+// PROCESSING BRISK
+
+
+ // Setting Threshold ------------------------------------------------->
+
+ double Threshold = MinContrast * 255;
+
+ // Limiting NumOctaves ----------------------------------------------->
+
+ int g = image.rows>image.cols?image.rows:image.cols;
+ int maxNumOctaves = int(floor(log2(g)));
+ if(NumOctaves>maxNumOctaves)
+ NumOctaves=maxNumOctaves;
+
+ //-----------------------------------------------------------------------
+
+ BRISK myobject(Threshold, NumOctaves);
+ myobject.operator()(image, mask, myPoints, noArray());
+
+ // Selecting Points according to MinQuality --------------------------->
+
+ size = myPoints.size();
+
+ double maxMetric = 0;
+ double minMetric = 0;
+
+ for(int i=0;i<size;i++)
+ {
+ if(myPoints[i].response>maxMetric)
+ maxMetric=myPoints[i].response;
+ }
+ minMetric = maxMetric*MinQuality;
+
+ int finalSize = 0;
+ for(int i=0;i<size;i++)
+ {
+ if(myPoints[i].response>=minMetric)
+ finalSize++;
+ }
+
+ //------------------------------------------------------------------------
+
+// LOCATION ---->
+
+ LocationData = (double *)malloc(sizeof(double)*finalSize*2);
+ MetricData = (double *)malloc(sizeof(double)*finalSize);
+ OrientationData = (double *)malloc(sizeof(double)*finalSize);
+ ScaleData = (double *)malloc(sizeof(double)*finalSize);
+ int k=0;
+ // Appending 1x2 Matrices containing the coordinates of the keypoints, as well as assiging other attributes
+ for(int i=0;i<size;i++)
+ {
+ if(myPoints[i].response>=minMetric)
+ {
+ LocationData[k++] = myPoints[i].pt.x;
+ LocationData[k++] = myPoints[i].pt.y;
+ OrientationData[i] = 0;
+ MetricData[i] = myPoints[i].response;
+ ScaleData[i] = myPoints[i].size;
+ }
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, finalSize, 2, LocationData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, finalSize, 1, OrientationData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, finalSize,1, MetricData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 4,finalSize,1, ScaleData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ createScalarInteger32(pvApiCtx,nbInputArgument(pvApiCtx) + 5, finalSize);
+
+// ASSIGNING ---->
+
+ for(int i=1;i<=5;i++)
+ {
+ AssignOutputVariable(pvApiCtx, i) = nbInputArgument(pvApiCtx) + i;
+ }
+
+ ReturnArguments(pvApiCtx);
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_detectCheckerboardPoints.cpp b/sci_gateway1/cpp/opencv_detectCheckerboardPoints.cpp
new file mode 100644
index 0000000..33c951c
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_detectCheckerboardPoints.cpp
@@ -0,0 +1,731 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/calib3d/calib3d.hpp>
+#include <iostream>
+#include <vector>
+
+using namespace std;
+using namespace cv;
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include <sciprint.h>
+ #include "../common.h"
+ //function used to retrieve image matrix from Scilab environment
+ int retrieveImageFromAddress(Mat &image,int *piAddr)
+ {
+ SciErr sciErr;
+ int iRows=0,iCols=0,i,j,k=0;
+ int *piChild = NULL;
+ int iPrec = 0,iItem = 0;
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isIntegerType(pvApiCtx, piChild))
+ {
+ //getting precision
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piChild, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8
+ {
+ if(iItem==3)
+ {
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC3);
+
+ /*Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this*/
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3b>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3b>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3b>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ unsigned char *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_8UC1);
+
+ //Assigning matrix value to pixel
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16
+ {
+ if(iItem==3)
+ {
+ short unsigned int *pstDataR = NULL;
+ short unsigned int *pstDataG = NULL;
+ short unsigned int *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ //i+iRows*j
+ }
+ }
+ }
+ else
+ {
+ short unsigned int *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16UC1);
+
+ //Assigning matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<ushort>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ case SCI_INT16: //for signed integer 16
+ {
+ if(iItem==3)
+ {
+ short int *pstDataR = NULL;
+ short int *pstDataG = NULL;
+ short int *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3s>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3s>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3s>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ short int *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfInteger16InList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_16SC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<short>(i,j)=pstDataR[i+iRows*j];
+ }
+ break;
+ }
+ }
+ }
+ else //for floating point/ double precision values
+ {
+ if(iItem==3)
+ {
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ 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 the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC3);
+
+ //Now that we have the 3 matrices(R,G,B), we need to assign those values to the pixels. The following code does this
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ image.at<Vec3d>(i,j)[2]=pstDataR[i+iRows*j];
+ image.at<Vec3d>(i,j)[1]=pstDataG[i+iRows*j];
+ image.at<Vec3d>(i,j)[0]=pstDataB[i+iRows*j];
+ }
+ }
+ }
+ else
+ {
+ double *pstDataR = NULL;
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating an image matrix with the no. of rows and columns we retrieved, and assigning it to be of the form 8-bit unsinged integers
+ image = Mat(iRows,iCols,CV_64FC1);
+
+ //Assigning image matrix values to pixels
+ k=0;
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<double>(i,j)=pstDataR[i+iRows*j];
+ }
+ }
+ return 1;
+ }
+ int opencv_detectCheckerboardPoints(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+
+ SciErr sciErr;
+
+ //------Local variables------//
+
+ int *piAddr;
+ int *piChild;
+ int *piGrandChild;
+ int iItem;
+ int iItemInner;
+ int argCount;
+ int iRows,iCols;
+ int *piLen;
+ char **pstData;
+
+ int imgCount[2]={0};
+ int returnSize[2];
+ vector<Mat> inputs;
+ Mat inp;
+ vector<vector<Point2f> > chessboardPoints;
+ vector<Size> chessboardSize;
+ vector<Point2f> v;
+ bool detected;
+ int *usedImages;
+ int ***points;
+ int count = 0,pointsPos;
+ //------Check number of parameters------//
+
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 2, 3);
+ argCount = *getNbInputArgument(pvApiCtx);
+
+ //------Get input arguments------//
+
+ for(int iter=0;iter<argCount;iter++)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,iter+1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx,piAddr))
+ {
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1)
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ imgCount[iter]=iCols;
+ }
+ else if(isListType(pvApiCtx,piAddr))
+ {
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isIntegerType(pvApiCtx,piChild) || isDoubleType(pvApiCtx,piChild))
+ {
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iItem==1 || iItem==3)
+ {
+ for(int i=1;i<=iItem;i++)
+ {
+ sciErr = getListItemAddress(pvApiCtx,piAddr,i,&piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isIntegerType(pvApiCtx,piChild) || isDoubleType(pvApiCtx,piChild))
+ {
+ continue;
+ }
+ else
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ }
+ imgCount[iter]=1;
+ }
+ else
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ }
+ else if(isListType(pvApiCtx,piChild))
+ {
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int i=1;i<=iItem;i++)
+ {
+ sciErr = getListItemAddress(pvApiCtx,piAddr,i,&piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isListType(pvApiCtx,piChild))
+ {
+ sciErr = getListItemNumber(pvApiCtx,piChild,&iItemInner);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iItemInner==1 || iItemInner==3)
+ {
+ for(int j=1;j<=iItemInner;j++)
+ {
+ sciErr = getListItemAddress(pvApiCtx,piChild,j,&piGrandChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isIntegerType(pvApiCtx,piGrandChild) || isDoubleType(pvApiCtx,piGrandChild))
+ {
+ continue;
+ }
+ else
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ }
+ }
+ else
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ }
+ imgCount[iter]=iItem;
+ }
+ else
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999, "Incorrect type of input argument(s).\n");
+ return 0;
+ }
+ }
+ if(argCount==2 && imgCount[0]!=imgCount[1])
+ {
+ Scierror(999,"For Stereo Calibration, both image sets must have same number of images.\n");
+ return 0;
+ }
+ for(int iter=0;iter<argCount;iter++)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,iter+1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx,piAddr))
+ {
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(int i=0;i<iCols;i++)
+ {
+ inp = imread(pstData[i]);
+ if(!inp.data)
+ {
+ Scierror(999,"Cannot read image \'%s\'. Aborting.\n",pstData[i]);
+ return 0;
+ }
+ inputs.push_back(inp);
+ }
+ }
+ else
+ {
+ sciErr = getListItemAddress(pvApiCtx,piAddr,1,&piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isIntegerType(pvApiCtx,piChild) || isDoubleType(pvApiCtx,piChild))
+ {
+ retrieveImageFromAddress(inp,piAddr);
+ inputs.push_back(inp);
+ }
+ else
+ {
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int i=1;i<=iItem;i++)
+ {
+ sciErr = getListItemAddress(pvApiCtx,piAddr,i,&piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ retrieveImageFromAddress(inp,piChild);
+ inputs.push_back(inp);
+ }
+ }
+ }
+ }
+
+ //------Actual processing------//
+
+ for(int iter=0;iter<inputs.size();iter++)
+ {
+ v.clear();
+ detected = 0;
+ for(int i=14;i>=3;i--)
+ {
+ for(int j=14;j>=i;j--)
+ {
+ Size boardsize(i,j);
+ detected = findChessboardCorners(inputs[iter],boardsize,v);
+ if(detected)
+ {
+ chessboardPoints.push_back(v);
+ chessboardSize.push_back(Size(i+1,j+1));
+ break;
+ }
+ }
+ if(detected)
+ break;
+ }
+ if(!detected)
+ {
+ chessboardPoints.push_back(v);
+ }
+ }
+ if(chessboardSize.size()==0)
+ {
+ Scierror(999, "No chessboards detected. Aborting.");
+ return 0;
+ }
+ Size compare = chessboardSize[0];
+ for(int i=1;i<chessboardSize.size();i++)
+ {
+ if(compare.height!=chessboardSize[i].height || compare.width!=chessboardSize[i].width)
+ {
+ Scierror(999, "Chessboards of different sizes detected. Aborting.");
+ return 0;
+ }
+ }
+ usedImages= (int*) malloc(sizeof(int)*imgCount[0]);
+ for(int i=0;i<imgCount[0];i++)
+ {
+ if(chessboardPoints[i].size() == 0)
+ {
+ usedImages[i] = 0;
+ }
+ else
+ {
+ usedImages[i] = 1;
+ }
+ }
+ if(argCount==2)
+ {
+ for(int i=0;i<imgCount[0];i++)
+ {
+ if(chessboardPoints[i+imgCount[0]].size() == 0)
+ {
+ usedImages[i] = 0;
+ }
+ }
+ }
+ for(int i=0;i<imgCount[0];i++)
+ {
+ if(usedImages[i]==1)
+ {
+ count++;
+ }
+ }
+ points = (int***) malloc(sizeof(int**)*argCount);
+ for(int i=0;i<argCount;i++)
+ {
+ points[i] = (int**) malloc(sizeof(int*)*count);
+ }
+ pointsPos = 0;
+ for(int i=0;i<imgCount[0];i++)
+ {
+ if(usedImages[i])
+ {
+ points[0][pointsPos] = (int*) malloc(sizeof(int) * chessboardPoints[i].size() * 2);
+ if(argCount==2)
+ {
+ points[1][pointsPos] = (int*) malloc(sizeof(int) * chessboardPoints[i].size() * 2);
+ }
+ for(int j=0;j<chessboardPoints[i].size();j++)
+ {
+ points[0][pointsPos][j] = chessboardPoints[i][j].x;
+ points[0][pointsPos][chessboardPoints[i].size()+j] = chessboardPoints[i][j].y;
+ if(argCount==2)
+ {
+ points[1][pointsPos][j] = chessboardPoints[imgCount[0]+i][j].x;
+ points[1][pointsPos][chessboardPoints[i].size()+j] = chessboardPoints[imgCount[0]+i][j].y;
+ }
+ }
+ pointsPos++;
+ }
+ }
+ returnSize[0] = compare.width;
+ returnSize[1] = compare.height;
+ //------Create output arguments------//
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, argCount, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int i=0;i<argCount;i++)
+ {
+ sciErr = createListInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, i+1, pointsPos, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int j=0;j<pointsPos;j++)
+ {
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piChild, j+1, (returnSize[0]-1)*(returnSize[1]-1), 2, points[i][j]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+2, 1, 2, returnSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+3, 1, imgCount[0], usedImages);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx)+2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx)+3;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_detectFASTFeatures.cpp b/sci_gateway1/cpp/opencv_detectFASTFeatures.cpp
new file mode 100644
index 0000000..19355fd
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_detectFASTFeatures.cpp
@@ -0,0 +1,569 @@
+/*************************************************************************************************************************************************************************************************
+* Author: Umang Agrawal *
+* Code: detectFASTFeatures.cpp *
+* Function Format: detectFASTFeatures( Image, Optional Arguments... ) *
+* Requirements: Image should be a grayscale image *
+* Optional Arguments: 1. 'MinContrast' Value: Range 0 < x < 1 *
+* 2. 'MinQuality' Value: Range 0 < x < 1 *
+* 3. 'ROI' Value: [ x_cordinate, y_cordinate, width, height ] *
+*************************************************************************************************************************************************************************************************/
+
+
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+
+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"
+
+ // Function using OpenCV to detect FAST Features
+ int opencv_detectFASTFeatures(char *fname, unsigned long fname_len)
+ {
+ int *piAddr = NULL;
+
+ //Various Declarations
+ SciErr sciErr; //Error Variable
+ int sca_read; //Error Variable
+
+ int *imgAddr = NULL; //Address of the Image List Argument
+ int *piAddrChild = NULL; //Address of the Child of the Image Matrix List
+ int no_item_list; //Number of items in the list
+
+ int iPrec = 0; //Precesision of the image in the lsit
+ int iRows=0, iCols=0; //Rows & Columns in the image
+
+ int inp_params; //Number of Input Arguments
+ int *piAddr1 = NULL; //Address of Argument Head
+ int *piAddr2 = NULL; //Address of Value_1 of Argument
+ //int *piAddr3 = NULL; //Address of Value_2 of Argument
+ //int *piAddr4 = NULL; //Address of Value_3 of Argument
+ //int *piAddr5 = NULL; //Address of Value_4 of Argument
+ int Rows,Cols; //Rows & Columns of String Matrix
+ int *len = NULL; //Length of each String Element
+ char **arg; //String Argument
+ double *roi_arg = NULL; //ROI Argument Matrix Address
+ int rows,cols; //Rows and Columns of ROI value matrix
+
+ //int *point = NULL; //Points returned by the FAST Algorithm
+
+ double arg_val; //Variables for Contrast/Quality Argument
+ double x = 0, y = 0, width, height; //Variables for ROI Argument
+
+ double thresh; //Effective Threshold
+ double thresh_c = 0; //Threshold due to arguments
+ double thresh_q = 0; //Threshold due to arguments
+
+ int count_q = 0; //Count of Argument Quality Call
+ int count_c = 0; //Count of Argument Contrast Call
+ int count_r = 0; //Count of Argument ROI call
+
+ vector<KeyPoint> keypoints; //Keypoint Vector to store the points returned by FAST Algorithm
+
+ int i,j; //Iterators
+
+ double count = 0; //Count of number of Features Detected
+ double *metric = NULL;
+
+ Mat image; //Image Container
+ Mat cropped; //Image Container
+
+ //Checks on Input and Output Arguments
+ CheckInputArgument(pvApiCtx, 1, 7);
+ CheckOutputArgument(pvApiCtx, 1, 3);
+
+
+ //Image Retrieval
+ //Get Address of the Image List
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &imgAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get Number of items in the list
+ sciErr = getListItemNumber(pvApiCtx, imgAddr, &no_item_list);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check if it is a Grayscal image by checking whether 1 item is present in the list
+ if( no_item_list == 1)
+ {
+ //Address of the Grayscale Matrix
+ sciErr = getListItemAddress(pvApiCtx, imgAddr, 1, &piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check whether it is an integer Matrix or not
+ if(isIntegerType(pvApiCtx, piAddrChild))
+ {
+ //If integer matrix getting precision
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddrChild, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Based on precision Read the matrix
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8
+ {
+ unsigned char *pstDatagray = NULL;
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, imgAddr, 1, &iRows, &iCols, &pstDatagray);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ image = Mat(iRows,iCols,CV_8UC1);
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<uchar>(i,j)=pstDatagray[i+iRows*j];
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16
+ {
+ short unsigned int *pstDatagray = NULL;
+ sciErr = getMatrixOfUnsignedInteger16InList(pvApiCtx, imgAddr, 1, &iRows, &iCols, &pstDatagray);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ image = Mat(iRows,iCols,CV_16UC1);
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<ushort>(i,j)=pstDatagray[i+iRows*j];
+ break;
+ }
+ case SCI_INT32: //for unsigned integer 32
+ {
+ int *pstDatagray = NULL;
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, imgAddr, 1, &iRows, &iCols, &pstDatagray);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ image = Mat(iRows,iCols,CV_32SC1);
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<int>(i,j)=pstDatagray[i+iRows*j];
+ break;
+ }
+ }
+ }
+ else
+ {
+ //If not Integer then must be double
+ double *pstDatagray = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &imgAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, imgAddr, 1, &iRows, &iCols, &pstDatagray);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ image = Mat(iRows,iCols,CV_64FC1);
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ image.at<double>(i,j)=pstDatagray[i+iRows*j];
+ }
+ }
+ //If not single element in list than it is not a grayscale image and hence error
+ else
+ {
+ Scierror(999,"Expecting a single Matrix in grayscale format\n");
+ return 0;
+ }
+
+ //Get the Number of Arguments
+ inp_params = *getNbInputArgument(pvApiCtx);
+
+ //Based on Number of Arguments Evaluate each Argument
+ for(i=2; i<inp_params; i++)
+ {
+ //Reading the Name of the Argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr1))
+ {
+ Scierror(999, "%s: Wrong type of argument #%d. A string is expected.\n", fname, 1);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr1, &Rows, &Cols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ len = (int*)malloc(sizeof(int) * Rows * Cols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr1, &Rows, &Cols, len, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(len);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * Rows * Cols);
+ for(int j=0;j< Rows * Cols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (len[j] + 1));
+ }
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr1, &Rows, &Cols, len, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(len);
+ free(arg);
+ return 0;
+ }
+
+ //Evaluating the Read Arguments Name
+ //MinContrast Argument
+ if(strcmp(arg[0],"MinContrast") == 0)
+ {
+ if(count_c == 0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of value
+ if( !isDoubleType(pvApiCtx, piAddr2))
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sca_read = getScalarDouble(pvApiCtx, piAddr2, &arg_val);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid value.\n");
+ return 0;
+ }
+ //Check for valid range
+ if(arg_val<0 && arg_val>=1)
+ {
+ Scierror(999,"Not a valid range.Should be between 0 and 1.\n");
+ return 0;
+ }
+ //Threshold Calculation
+ else thresh_c = 256*arg_val;
+ i++; //Incrementing iterator to count for the value argument read
+ count_c += 1; //Indicating MinContrast has been called once
+ }
+ else
+ {
+ Scierror(999,"Specified MinContrast twice. Check Arguments\n");
+ return 0;
+ }
+ }
+ //MinQuality Argument
+ else if(strcmp(arg[0],"MinQuality") == 0)
+ {
+ if(count_q == 0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of Value
+ if( !isDoubleType(pvApiCtx, piAddr2))
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of argument
+ sca_read = getScalarDouble(pvApiCtx, piAddr2, &arg_val);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Cheack for valid range
+ if(arg_val<0 && arg_val>=1)
+ {
+ Scierror(999,"Not a valid range.Should be between 0 and 1.\n");
+ return 0;
+ }
+ //Threshold Calculation
+ else thresh_q = 240*arg_val;
+ i++; //Incrementing iterator to count for the value argument read
+ count_q += 1; //Indicating MinQuality has been called once
+ }
+ else
+ {
+ Scierror(999,"Specified MinQuality twice. Check Arguments\n");
+ return 0;
+ }
+ }
+ //ROI Argument
+ else if(strcmp(arg[0],"ROI") == 0)
+ {
+ if(count_r == 0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of argument
+ if( !isDoubleType(pvApiCtx, piAddr2))
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &rows, &cols, &roi_arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the elements of the list to their proper function
+ x = roi_arg[0];
+ y = roi_arg[1];
+ width = roi_arg[2];
+ height = roi_arg[3];
+
+
+ //Code for reading the value associated with ROI individually rather than in a list form
+
+ /*sca_read = getScalarDouble(pvApiCtx, piAddr2, &x);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+2, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sca_read = getScalarDouble(pvApiCtx, piAddr3, &y);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+3, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sca_read = getScalarDouble(pvApiCtx, piAddr4, &width);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+4, &piAddr5);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sca_read = getScalarDouble(pvApiCtx, piAddr5, &height);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }*/
+
+ //Checking for valid crop area
+ if(x>=image.cols || y>=image.rows || x<0 || y<0)
+ {
+ sciprint("Invalid x or y value\n");
+ return 0;
+ }
+ if(width<=0 || height<=0 || x+width > image.cols || y+height > image.rows)
+ {
+ sciprint("Invalid width or height value\n");
+ return 0;
+ }
+ //Croppint the image
+ Rect myROI(x, y, width, height);
+ Mat croppedRef(image, myROI);
+ croppedRef.copyTo(cropped);
+ i++; //Incrementing iterator to count for the value argument read
+ count_r += 1; //Indicating ROI has been called once
+ }
+ else
+ {
+ Scierror(999,"Specified ROC twice. Check Arguments\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ }
+
+ //Calculating the effective threshold by selecting the maximum threshold
+ if(thresh_c > 0 && thresh_c >= thresh_q)
+ thresh = thresh_c;
+ else if(thresh_q > 0 && thresh_q > thresh_c)
+ thresh = thresh_q;
+ else thresh = 256*0.2;
+
+ //Implementing FAST Algorithm
+ if(count_r != 0)
+ FAST(cropped, keypoints, thresh, 1);
+ else
+ FAST(image, keypoints, thresh, 1);
+
+ count = keypoints.size();
+
+ metric = (double*)malloc(sizeof(double)*keypoints.size()*1);
+ for( i=0; i<keypoints.size(); i++)
+ {
+ metric[i] = keypoints[i].response;
+ }
+
+ //Returning the obtained point co-ordinates
+ //Checking what type of Input matrix image was
+ //If input matrix was integer
+ if(isIntegerType(pvApiCtx, piAddrChild))
+ {
+ //Based on Precision of the Image given in input
+ switch(iPrec)
+ {
+ case SCI_UINT8: {
+ //Output point Matrix
+ unsigned char *point = (unsigned char *)malloc(keypoints.size()*2*sizeof(char));
+ for(i=0;i!=keypoints.size();i++)
+ {
+ point[i] = keypoints[i].pt.x + x;
+ point[keypoints.size()+i] = keypoints[i].pt.y + y;
+ }
+ sciErr = createMatrixOfUnsignedInteger8(pvApiCtx, nbInputArgument(pvApiCtx) + 1, int(keypoints.size()), 2, point);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(point);
+ break;
+ }
+ case SCI_UINT16:{
+ //Output point Matrix
+ unsigned short *point = (unsigned short *)malloc(keypoints.size()*2*sizeof(short));
+ for(i=0;i!=keypoints.size();i++)
+ {
+ point[i] = keypoints[i].pt.x + x;
+ point[keypoints.size()+i] = keypoints[i].pt.y + y;
+ }
+ sciErr = createMatrixOfUnsignedInteger16(pvApiCtx, nbInputArgument(pvApiCtx) + 1, int(keypoints.size()), 2, point);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(point);
+ break;
+ }
+ case SCI_INT32: {
+ //Output Point Matrix
+ int *point = (int *)malloc(keypoints.size()*2*sizeof(int));
+ for(i=0;i!=keypoints.size();i++)
+ {
+ point[i] = keypoints[i].pt.x + x;
+ point[keypoints.size()+i] = keypoints[i].pt.y + y;
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 1, int(keypoints.size()), 2, point);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(point);
+ break;
+ }
+ }
+ }
+ //If not Integer than must be double input image
+ else
+ {
+ //Ouput point matrix
+ double *point = (double *)malloc(keypoints.size()*2*sizeof(double));
+ for(i=0;i!=keypoints.size();i++)
+ {
+ point[i] = keypoints[i].pt.x + x;
+ point[keypoints.size()+i] = keypoints[i].pt.y + y;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, keypoints.size(), 2, point);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(point);
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, 1, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, keypoints.size(), 1, metric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Returning the Output Matrix
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_detectHarrisFeatures.cpp b/sci_gateway1/cpp/opencv_detectHarrisFeatures.cpp
new file mode 100644
index 0000000..090ba5b
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_detectHarrisFeatures.cpp
@@ -0,0 +1,402 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include <iostream>
+#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 "sciprint.h"
+ #include "../common.h"
+
+ /* Calling syntax: detectHarrisFeatures(I) or detectHarrisFeatures(I, Name, Value)
+ which uses additional options specified by one or more Name, Value pair arguments.
+ Arguments Allowed: MinQuality, FilterSize, ROI, SensitivityFactor
+ MinQuality : The minimum accepted quality of corners represents a fraction of the
+ maximum corner metric value in the image. Larger values can be used
+ to remove erroneous corners.
+ FilterSize : Gaussian filter dimension
+ ROI : Rectangular region for corner detection
+ SensitivityFactor : A scalar value, K, where 0 < K < 0.25, specifying the sensitivity
+ factor used in the Harris detection algorithm. */
+
+ int opencv_detectHarrisFeatures(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+ int intErr;
+
+ //------Local variables------//
+ int *location = NULL;
+ double *metric = NULL;
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ int nbInputArguments;
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+ double *matrixOfRoi; // ROI[xStart, yStart, width, height]
+ int iRows, iCols;
+ Mat sourceImage, dst, dstThresholded, ucharDstThresholded, extended;
+ vector<vector<Point> > contours;
+ double filterSize = 5, minQuality = 0.01, sensitivityFactor = 0.04, blockSize = 2, maxDst, localMax;
+ bool *included = NULL;
+ int pointCount = 0, localMaxPos;
+ double tempForSwapping;
+ int coordinateMin, coordinatePos;
+
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 1, 9);
+ CheckOutputArgument(pvApiCtx, 1, 3);
+
+ //------Get input arguments------//
+ retrieveImage(sourceImage, 1);
+ if(sourceImage.channels() != 1)
+ {
+ Scierror(999, "The input image is not a grayscale image.");
+ return 0;
+ }
+ matrixOfRoi = (double*) malloc(sizeof(double) * 4);
+ providedArgs = (bool*) malloc(sizeof(bool) * 4);
+ memset(providedArgs, 0, 4);
+ matrixOfRoi[0] = 0;
+ matrixOfRoi[1] = 0;
+ matrixOfRoi[2] = sourceImage.cols;
+ matrixOfRoi[3] = sourceImage.rows;
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ // The following loop is for checking if optional arguments have been provided
+ for(int iter=2; iter <= nbInputArguments; iter++)
+ {
+ // Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ // providedArgs[] makes sure that no optional argument is provided more than once
+ if(strcmp(currentArg, "MinQuality")==0)
+ {
+ if(iter+1<=nbInputArguments && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &minQuality);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(minQuality < 0 || minQuality > 1)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible range is [0, 1].\n", currentArg);
+ return 0;
+ }
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "FilterSize")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &filterSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+ providedArgs[1] = 1;
+ if(filterSize!=1 && filterSize!=3 && filterSize!=5 && filterSize!=7)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are {1, 3, 5, 7}.\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[1])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "ROI")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, iter);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &matrixOfRoi);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1 || iCols!=4)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument ROI.\n");
+ return 0;
+ }
+ providedArgs[2] = 1;
+ if(matrixOfRoi[0] < 0 || matrixOfRoi[0] > sourceImage.cols || matrixOfRoi[1] < 0 ||
+ matrixOfRoi[1] > sourceImage.rows || matrixOfRoi[2] < 0 || matrixOfRoi[0] + matrixOfRoi[2] > sourceImage.cols
+ || matrixOfRoi[3] < 0 || matrixOfRoi[1] + matrixOfRoi[3] > sourceImage.rows)
+ {
+ Scierror(999, "Error: Please provide proper values for \"%s\".\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[2])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "SensitivityFactor")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &sensitivityFactor);
+ if(intErr)
+ {
+ return intErr;
+ }
+ providedArgs[3] = 1;
+ if(sensitivityFactor < 0 || sensitivityFactor > 0.25)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are [0, 0.25].\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[3])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999, "Error: \"%s\" name for input argument is not valid.\n", currentArg);
+ return 0;
+ }
+ }
+
+ //------Actual processing------//
+ cornerHarris(sourceImage(Rect(matrixOfRoi[0], matrixOfRoi[1], matrixOfRoi[2], matrixOfRoi[3])), dst, blockSize, filterSize, sensitivityFactor, BORDER_DEFAULT);
+
+ // Finding the maximum value at a pixel in dst
+ maxDst = 0;
+ for(int rowIter=0; rowIter < dst.rows; rowIter++)
+ {
+ for(int colIter=0; colIter < dst.cols; colIter++)
+ {
+ if(dst.at<float>(rowIter, colIter) > maxDst)
+ {
+ maxDst = dst.at<float>(rowIter, colIter);
+ }
+ }
+ }
+
+ /* First, we threshold dst according to the minQuality expected by the user.
+ We then find contours in the thresholded image and check each pixel's value
+ to compute the local maxima. A extended mat is created because contours
+ having edges on the boundaries of the images are not considered by
+ findContours */
+ threshold(dst, dstThresholded, maxDst*minQuality, 255, THRESH_BINARY);
+ dstThresholded.convertTo(ucharDstThresholded, CV_8UC1);
+ extended = Mat(dst.rows+2, dst.cols+2, CV_8UC1);
+ for(int rowIter = 0; rowIter < extended.rows; rowIter++)
+ {
+ for(int colIter = 0; colIter < extended.cols; colIter++)
+ {
+ if(rowIter == 0 || rowIter == extended.rows - 1
+ || colIter == 0 || colIter == extended.cols - 1)
+ {
+ extended.at<uchar>(rowIter, colIter) = 0;
+ }
+ else
+ {
+ extended.at<uchar>(rowIter, colIter) = ucharDstThresholded.at<uchar>(rowIter-1, colIter-1);
+ }
+ }
+ }
+
+ findContours(extended, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
+ pointCount = contours.size();
+ location = (int*) malloc(sizeof(int) * pointCount * 2);
+ metric = (double*) malloc(sizeof(double)*pointCount);
+ for(int rowIter = 0; rowIter < contours.size(); rowIter++)
+ {
+ localMax = 0;
+ localMaxPos = 0;
+ for(int colIter=0; colIter<contours[rowIter].size(); colIter++)
+ {
+ if(dst.at<float>(contours[rowIter][colIter].y-1, contours[rowIter][colIter].x-1)>localMax)
+ {
+ localMax = dst.at<float>(contours[rowIter][colIter].y-1, contours[rowIter][colIter].x-1);
+ localMaxPos = colIter;
+ }
+ }
+ if(localMax > maxDst*minQuality)
+ {
+ location[rowIter] = contours[rowIter][localMaxPos].x-1 + matrixOfRoi[0];
+ location[pointCount + rowIter] = contours[rowIter][localMaxPos].y-1 + matrixOfRoi[1];
+ metric[rowIter] = dst.at<float>(location[pointCount + rowIter], location[rowIter]);
+ }
+ }
+
+ // To return coordinates in order
+ for(int iter1 = 0; iter1 < pointCount - 1; iter1++)
+ {
+ coordinateMin = location[iter1];
+ coordinatePos = iter1;
+ for(int iter2 = iter1 + 1; iter2 < pointCount; iter2++)
+ {
+ if(location[iter2] < coordinateMin)
+ {
+ coordinateMin = location[iter2];
+ coordinatePos = iter2;
+ }
+ else if(location[iter2] == coordinateMin)
+ {
+ if(location[pointCount + iter2] < location[pointCount + coordinatePos])
+ {
+ coordinateMin = location[iter2];
+ coordinatePos = iter2;
+ }
+ }
+ }
+ // Swapping x coordinate
+ tempForSwapping = location[coordinatePos];
+ location[coordinatePos] = location[iter1];
+ location[iter1] = tempForSwapping;
+ // Swapping y coordinate
+ tempForSwapping = location[pointCount + coordinatePos];
+ location[pointCount + coordinatePos] = location[pointCount + iter1];
+ location[pointCount + iter1] = tempForSwapping;
+ // Swapping metric
+ tempForSwapping = metric[coordinatePos];
+ metric[coordinatePos] = metric[iter1];
+ metric[iter1] = tempForSwapping;
+ }
+
+ //------Create output arguments------//
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+1, pointCount, 2, location);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx)+2, pointCount, 1, metric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+3, 1, 1, &pointCount);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx)+2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx)+3;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_detectMSERFeatures.cpp b/sci_gateway1/cpp/opencv_detectMSERFeatures.cpp
new file mode 100644
index 0000000..a437c16
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_detectMSERFeatures.cpp
@@ -0,0 +1,451 @@
+/********************************************************************************************************************************************************************************************************
+* Author: Umang Agrawal *
+* Code: detectMSERFeatures.cpp *
+* Function Format: [ list_pixels, ......] = detectMSERFeatures( image, Optional Arguments........) *
+* Input Arguments: 1. Image (Grayscale or RGB) *
+* 2. ThresholdDelta Value: (0:100] Expressed in Percentage *
+* 3. RegionAreaRange Value: [ Min_Area , Max_Area ] *
+* 4. MaxAreaVariation Value: Scalar Double typical range from 0.25 - 4 *
+* 5. ROI Value: [ x_cord , y_cord , width , height ] *
+* *
+* Output Argument: 1. List Of Pixels stating the Locus of all features detected *
+* 2. Count *
+* 3. Location: Centroid of each Locus *
+* 4. Axes: Major and Minor axis length of ellipse *
+* 5. Orientation: Tilt of the elliptical fit *
+* *
+********************************************************************************************************************************************************************************************************/
+
+
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+
+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_detectMSERFeatures(char *fname, unsigned long fname_len)
+ {
+ //Various Declarations
+ //Error Variables
+ SciErr sciErr;
+ int sca_read;
+
+ //Mat containers for image
+ Mat image;
+ Mat cropped;
+
+ //Address of Various Arguments
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+
+ int inp_params, out_params; //Count of Parameters
+ double arg_val; //Memory for Scalar Argument Value
+ int Rows, Cols; //Rows and Columns for Matrix Argument Value
+ double *roi_arg = NULL; //Memory for Matrix Argument Value
+ int *pilen = NULL; //For String Matrix Reading: Length of String
+ char **arg = NULL; //For String Matrix Reading: String
+ int count_area = 0, count_tres = 0, count_var = 0, count_roi = 0; //Count of all the optional Arguments
+ double x = 0, y = 0, width = 0, height = 0; //Initials of all Cropped Varaibles
+
+ int i,j; //Iterator
+
+ int delta = 5, min_area = 60, max_area = 14400, max_evolution = 200, edge_blur_size = 5; //Arguments of MSER function with default values
+ double max_variation = 0.25, min_diversity = 0.2, area_threshold = 1.01, min_margin = 0.003; //Arguments of MSER function with default values
+
+ double *pixellist = NULL; //Output Argument Pixellist
+ int count[1] ; //Output Argument Count
+ double *location = NULL; //Output Argument Location
+ double *axes = NULL; //Output Argument Axes
+ double *orientation = NULL; //Output Argument Orientation
+
+ vector< vector<Point> > mser_points; //3D vector for storing the locus of each detected feature
+ vector< RotatedRect > regions; //RotatedRect vector for storing each region associated with a feature
+
+ CheckInputArgument(pvApiCtx, 1, 9); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 5); //Check on Number of Output Arguments
+
+ //Read Image
+ retrieveImage(image, 1);
+
+ //Getting Number of Input Arguments
+ inp_params = *getNbInputArgument(pvApiCtx);
+
+ //Based on the number of Input Arguments, alter the arguments of the MSER funtion.
+ for(i=2; i<=inp_params; i++)
+ {
+ if( inp_params == 2 || inp_params == 4 || inp_params == 6 || inp_params == 8)
+ {
+ Scierror(999,"Either Argument Name or its Value missing\n");
+ return 0;
+ }
+ //Reading the Name of the Argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr2))
+ {
+ Scierror(999, "%s: Wrong type of argument #%d. A string is expected.\n", fname, 1);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &Rows, &Cols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * Rows * Cols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &Rows, &Cols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * Rows * Cols);
+ for(int j=0;j< Rows * Cols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &Rows, &Cols, pilen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(arg);
+ return 0;
+ }
+
+ if(strcmp(arg[0],"ThresholdDelta") == 0)
+ {
+ if(count_tres == 0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of value
+ if( !isDoubleType(pvApiCtx, piAddr3))
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sca_read = getScalarDouble(pvApiCtx, piAddr3, &arg_val);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid value.\n");
+ return 0;
+ }
+ //Check for valid range
+ if(arg_val <= 0 && arg_val > 100)
+ {
+ Scierror(999,"Not a valid range.Should be between 0 and 100.\n");
+ return 0;
+ }
+ delta = arg_val;
+ i++;
+ count_tres += 1;
+ }
+ else
+ {
+ Scierror(999,"ThresholdDelta has been specified twice.Check the Arguments\n");
+ return 0;
+ }
+ }
+ else if(strcmp(arg[0],"RegionAreaRange") == 0)
+ {
+ if(count_area == 0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of argument
+ if( !(isDoubleType(pvApiCtx, piAddr3) || isIntegerType(pvApiCtx, piAddr3)) )
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &Rows, &Cols, &roi_arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( Rows*Cols != 2 )
+ {
+ Scierror(999,"Only 2 values are expected.Neither less nor more\n");
+ return 0;
+ }
+ if( roi_arg[0] >= roi_arg[1] )
+ {
+ Scierror(999,"Max Area should be greater than Min Area\n");
+ return 0;
+ }
+ //Assigning the elements of the list to their proper function
+ min_area = roi_arg[0];
+ max_area = roi_arg[1];
+ i++;
+ count_area += 1;
+ }
+ else
+ {
+ Scierror(999,"RegionAreaRange has been specified twice.Check the Arguments\n");
+ return 0;
+ }
+ }
+ else if(strcmp(arg[0],"MaxAreaVariation") == 0)
+ {
+ if(count_var == 0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of value
+ if( !isDoubleType(pvApiCtx, piAddr3))
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sca_read = getScalarDouble(pvApiCtx, piAddr3, &arg_val);
+ if(sca_read)
+ {
+ Scierror(999,"Not a valid value.\n");
+ return 0;
+ }
+ max_variation = arg_val;
+ i++;
+ count_var += 1;
+ }
+ else
+ {
+ Scierror(999,"MaxAreaVariation has been specified twice.Check the Arguments\n");
+ return 0;
+ }
+ }
+ else if(strcmp(arg[0],"ROI") == 0)
+ {
+ if(count_roi == 0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of argument
+ if( !(isDoubleType(pvApiCtx, piAddr3) || isIntegerType(pvApiCtx, piAddr3)) )
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &Rows, &Cols, &roi_arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( Rows*Cols != 4 )
+ {
+ Scierror(999,"Expected 4 arguments in format [x,y,width,height]\n");
+ return 0;
+ }
+ //Assigning the elements of the list to their proper function
+ x = roi_arg[0];
+ y = roi_arg[1];
+ width = roi_arg[2];
+ height = roi_arg[3];
+ if(x>=image.cols || y>=image.rows || x<0 || y<0)
+ {
+ sciprint("Invalid x or y value\n");
+ return 0;
+ }
+ if(width<=0 || height<=0 || x+width > image.cols || y+height > image.rows)
+ {
+ sciprint("Invalid width or height value\n");
+ return 0;
+ }
+ Rect myROI(x, y, width, height);
+ Mat croppedRef(image, myROI);
+ croppedRef.copyTo(cropped);
+ i++; //Incrementing iterator to count for the value argument read
+ count_roi += 1; //Indicating ROI has been called once
+ }
+ else
+ {
+ Scierror(999,"ROI has been specified twice.Check the Arguments\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+ }
+
+ //Creating an MSER class Object with specified conditions
+ MSER img_ms = MSER(delta, min_area, max_area, max_variation, min_diversity, max_evolution, area_threshold, min_margin, edge_blur_size);
+
+ //Checking if have to operate on original image or cropped one
+ // 1st Argument: Image on which MSER features has to be detected
+ // 2nd Argument: Locus of all the points detected
+ // 3rd Argument: Mask of empty Mat container
+ if(count_roi == 0)
+ img_ms( image, mser_points, Mat());
+ else
+ img_ms( cropped, mser_points, Mat());
+
+ // Extracting Regions from the mser_points locus and approximating them to an elliptic fit
+ for(i=0; i<mser_points.size(); i++)
+ regions.push_back(fitEllipse(mser_points[i]));
+
+ //Memory Allocation for all the output parameters
+ location = (double *)malloc(sizeof(double) * mser_points.size() * 2);
+ axes = (double *)malloc(sizeof(double) * mser_points.size() * 2);
+ orientation = (double *)malloc(sizeof(double) * mser_points.size());
+
+ //Output Arguments: Pixel_list, Count, Location, Axes, Orientation
+ count[0] = mser_points.size(); //Count
+ for(i=0; i<mser_points.size(); i++)
+ {
+ location[i] = regions[i].center.x + x; //Location X co-ordinate
+ location[mser_points.size() + i] = regions[i].center.y + y; //Location Y co-ordinate
+ if( regions[i].size.width >= regions[i].size.height )
+ {
+ axes[i] = regions[i].size.width; //Axis: Major Axis of Ellipse
+ axes[mser_points.size() + i] = regions[i].size.height; //Axis: Minor Axis of Ellipse
+ }
+ else
+ {
+ axes[i] = regions[i].size.height; //Axis: Major Axis of Ellipse
+ axes[mser_points.size() + i] = regions[i].size.width; //Axis: Minor Axis of Ellipse
+ }
+ orientation[i] = regions[i].angle; //Orientation
+ }
+
+ //Reading the number of output Arguments user demands
+
+ //Assigning Pixel_List
+ out_params = *getNbOutputArgument(pvApiCtx);
+ if( out_params >= 1 )
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, mser_points.size(), &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(i = 0; i<mser_points.size(); i++)
+ {
+ pixellist = (double *)malloc(sizeof(double) * mser_points[i].size() * 2);
+ for( j=0; j<mser_points[i].size(); j++)
+ {
+ pixellist[j] = mser_points[i][j].x + x;
+ pixellist[mser_points[i].size() + j] = mser_points[i][j].y + y;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, i+1, mser_points[i].size(), 2, pixellist);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(pixellist);
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ }
+
+ //Assigning Count
+ if( out_params >= 2 )
+ {
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, 1, count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ }
+
+ //Assigning Location
+ if( out_params >= 3 )
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, mser_points.size(), 2, location);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
+ }
+
+ //Assigning Axes
+ if( out_params >= 4 )
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 4, mser_points.size(), 2, axes);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
+ }
+
+ //Assigning Orientation
+ if( out_params == 5 )
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, mser_points.size(), 1, orientation);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+ }
+
+ //Releasing all the memory Captured
+ free(location);
+ free(axes);
+ free(orientation);
+
+ //Returning the Output Arguments
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_detectMinEigenFeatures.cpp b/sci_gateway1/cpp/opencv_detectMinEigenFeatures.cpp
new file mode 100644
index 0000000..5138185
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_detectMinEigenFeatures.cpp
@@ -0,0 +1,366 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include <iostream>
+#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 "sciprint.h"
+ #include "../common.h"
+
+ /* Calling syntax: detectMinEigenFeatures(I) or detectMinEigenFeatures(I, Name, Value)
+ which uses additional options specified by one or more Name, Value pair arguments.
+ Arguments Allowed: MinQuality, FilterSize, ROI
+ MinQuality : The minimum accepted quality of corners represents a fraction of the
+ maximum corner metric value in the image. Larger values can be used
+ to remove erroneous corners.
+ FilterSize : Gaussian filter dimension
+ ROI : Rectangular region for corner detection */
+
+ int opencv_detectMinEigenFeatures(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+ int intErr;
+
+ //------Local variables------//
+ int *location = NULL;
+ double *metric = NULL;
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ int nbInputArguments;
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+ double *matrixOfRoi; // ROI[xStart, yStart, width, height]
+ int iRows, iCols;
+ Mat sourceImage, dst, dstThresholded, ucharDstThresholded, extended;
+ vector<vector<Point> > contours;
+ double filterSize = 5, minQuality = 0.01, blockSize = 2, maxDst, localMax;
+ bool *included = NULL;
+ int pointCount = 0, localMaxPos;
+ double tempForSwapping;
+ int coordinateMin, coordinatePos;
+
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 1, 7);
+ CheckOutputArgument(pvApiCtx, 1, 3);
+
+ //------Get input arguments------//
+ retrieveImage(sourceImage, 1);
+ if(sourceImage.channels() != 1)
+ {
+ Scierror(999, "The input image is not a grayscale image.");
+ return 0;
+ }
+ matrixOfRoi = (double*) malloc(sizeof(double) * 4);
+ providedArgs = (bool*) malloc(sizeof(bool) * 3);
+ memset(providedArgs, 0, 3);
+ matrixOfRoi[0] = 0;
+ matrixOfRoi[1] = 0;
+ matrixOfRoi[2] = sourceImage.cols;
+ matrixOfRoi[3] = sourceImage.rows;
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ // The following loop is for checking if optional arguments have been provided
+ for(int iter=2; iter <= nbInputArguments; iter++)
+ {
+ // Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ // providedArgs[] makes sure that no optional argument is provided more than once
+ if(strcmp(currentArg, "MinQuality")==0)
+ {
+ if(iter+1<=nbInputArguments && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &minQuality);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(minQuality < 0 || minQuality > 1)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible range is [0, 1].\n", currentArg);
+ return 0;
+ }
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "FilterSize")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &filterSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+ providedArgs[1] = 1;
+ if(filterSize!=1 && filterSize!=3 && filterSize!=5 && filterSize!=7)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are {1, 3, 5, 7}.\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[1])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "ROI")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, iter);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &matrixOfRoi);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1 || iCols!=4)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument ROI.\n");
+ return 0;
+ }
+ providedArgs[2] = 1;
+ if(matrixOfRoi[0] < 0 || matrixOfRoi[0] > sourceImage.cols || matrixOfRoi[1] < 0 ||
+ matrixOfRoi[1] > sourceImage.cols || matrixOfRoi[2] < 0 || matrixOfRoi[0] + matrixOfRoi[2] > sourceImage.cols
+ || matrixOfRoi[3] < 0 || matrixOfRoi[1] + matrixOfRoi[3] > sourceImage.rows)
+ {
+ Scierror(999, "Error: Please provide proper values for \"%s\".\n", currentArg);
+ return 0;
+ }
+ }
+ else if(providedArgs[2])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999, "Error: \"%s\" name for input argument is not valid.\n", currentArg);
+ return 0;
+ }
+ }
+
+ //------Actual processing------//
+ cornerMinEigenVal(sourceImage(Rect(matrixOfRoi[0], matrixOfRoi[1], matrixOfRoi[2], matrixOfRoi[3])), dst, blockSize, filterSize, BORDER_DEFAULT);
+
+ // Finding the maximum value at a pixel in dst
+ maxDst = 0;
+ for(int rowIter=0; rowIter < dst.rows; rowIter++)
+ {
+ for(int colIter=0; colIter < dst.cols; colIter++)
+ {
+ if(dst.at<float>(rowIter, colIter) > maxDst)
+ {
+ maxDst = dst.at<float>(rowIter, colIter);
+ }
+ }
+ }
+
+ /* First, we threshold dst according to the minQuality expected by the user.
+ We then find contours in the thresholded image and check each pixel's value
+ to compute the local maxima. A extended mat is created because contours
+ having edges on the boundaries of the images are not considered by
+ findContours */
+ threshold(dst, dstThresholded, maxDst*minQuality, 255, THRESH_BINARY);
+ dstThresholded.convertTo(ucharDstThresholded, CV_8UC1);
+ extended = Mat(dst.rows+2, dst.cols+2, CV_8UC1);
+ for(int rowIter = 0; rowIter < extended.rows; rowIter++)
+ {
+ for(int colIter = 0; colIter < extended.cols; colIter++)
+ {
+ if(rowIter == 0 || rowIter == extended.rows - 1
+ || colIter == 0 || colIter == extended.cols - 1)
+ {
+ extended.at<uchar>(rowIter, colIter) = 0;
+ }
+ else
+ {
+ extended.at<uchar>(rowIter, colIter) = ucharDstThresholded.at<uchar>(rowIter-1, colIter-1);
+ }
+ }
+ }
+
+ findContours(extended, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);
+ pointCount = contours.size();
+ location = (int*) malloc(sizeof(int) * pointCount * 2);
+ metric = (double*) malloc(sizeof(double)*pointCount);
+ for(int rowIter = 0; rowIter < contours.size(); rowIter++)
+ {
+ localMax = 0;
+ localMaxPos = 0;
+ for(int colIter=0; colIter<contours[rowIter].size(); colIter++)
+ {
+ if(dst.at<float>(contours[rowIter][colIter].y-1, contours[rowIter][colIter].x-1)>localMax)
+ {
+ localMax = dst.at<float>(contours[rowIter][colIter].y-1, contours[rowIter][colIter].x-1);
+ localMaxPos = colIter;
+ }
+ }
+ if(localMax > maxDst*minQuality)
+ {
+ location[rowIter] = contours[rowIter][localMaxPos].x-1 + matrixOfRoi[0];
+ location[pointCount + rowIter] = contours[rowIter][localMaxPos].y-1 + matrixOfRoi[1];
+ metric[rowIter] = dst.at<float>(location[pointCount + rowIter], location[rowIter]);
+ }
+ }
+
+ // To return coordinates in order
+ for(int iter1 = 0; iter1 < pointCount - 1; iter1++)
+ {
+ coordinateMin = location[iter1];
+ coordinatePos = iter1;
+ for(int iter2 = iter1 + 1; iter2 < pointCount; iter2++)
+ {
+ if(location[iter2] < coordinateMin)
+ {
+ coordinateMin = location[iter2];
+ coordinatePos = iter2;
+ }
+ else if(location[iter2] == coordinateMin)
+ {
+ if(location[pointCount + iter2] < location[pointCount + coordinatePos])
+ {
+ coordinateMin = location[iter2];
+ coordinatePos = iter2;
+ }
+ }
+ }
+ // Swapping x coordinate
+ tempForSwapping = location[coordinatePos];
+ location[coordinatePos] = location[iter1];
+ location[iter1] = tempForSwapping;
+ // Swapping y coordinate
+ tempForSwapping = location[pointCount + coordinatePos];
+ location[pointCount + coordinatePos] = location[pointCount + iter1];
+ location[pointCount + iter1] = tempForSwapping;
+ // Swapping metric
+ tempForSwapping = metric[coordinatePos];
+ metric[coordinatePos] = metric[iter1];
+ metric[iter1] = tempForSwapping;
+ }
+ //------Create output arguments------//
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+1, pointCount, 2, location);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx)+2, pointCount, 1, metric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx)+3, 1, 1, &pointCount);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx)+2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx)+3;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_detectSURFFeatures.cpp b/sci_gateway1/cpp/opencv_detectSURFFeatures.cpp
new file mode 100644
index 0000000..8a62361
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_detectSURFFeatures.cpp
@@ -0,0 +1,432 @@
+/***************************************************
+Author : Shashank Shekhar
+***************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.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"
+ //#include "../common.cpp"
+
+int opencv_detectSURFFeatures(char *fname, unsigned long fname_len)
+{
+
+ SciErr sciErr;
+
+
+ int *piAddr = NULL;
+ int *piAddrVal = NULL;
+ int val_position;
+ int *piLen = NULL;
+ int iRows, iCols = 0;
+ char ** pstData = NULL;
+ char *currentArg = NULL;
+ int valOfCA;
+ int argPresence[4];
+ for(int i=0;i<4;i++)
+ argPresence[i]=0;
+
+ vector<KeyPoint> myPoints;
+
+ int *LocationList = NULL;
+ int *OrientationList = NULL;
+ int *MetricList = NULL;
+ int *LaplacianList = NULL;
+ int *ScaleList = NULL;
+
+ double *LocationData = NULL;
+ double *OrientationData = NULL;
+ double *MetricData = NULL;
+ int *LaplacianData = NULL;
+ double *ScaleData = NULL;
+
+ int noOfarguments = *getNbInputArgument(pvApiCtx);
+
+ CheckInputArgument(pvApiCtx, 1,9);
+ CheckOutputArgument(pvApiCtx,1,6);
+
+ Mat image;
+ retrieveImage(image,1);
+
+
+ if(image.channels()!=1)
+ {
+ Scierror(999," Feature is not meant for RGB images\n");
+ return 0;
+ }
+
+//********************************************* Valid Argument Count Check *****************************************
+
+ if(noOfarguments%2==0)
+ {
+ Scierror(999," Invalid No of Arguments \n");
+ return 0;
+ }
+
+//********************************************* Optional Input Arguments *****************************************
+
+ double MetricThreshold = 0;
+ double NumOctaves = 0;
+ double NumScaleLevels = 0;
+ double *ROImat = NULL;
+
+//********************************************* Retrieval of Name, Value Argument Pair ****************************
+
+
+ for(int i=2;i<=noOfarguments;i=i+2)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,i,&piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isStringType(pvApiCtx, piAddr))
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ //first call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j = 0 ; j < iRows * iCols ; j++)
+ {
+ pstData[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));//+ 1 for null termination
+ }
+//third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+ if(strcmp(currentArg,"MetricThreshold")==0)
+ {
+
+ val_position=i+1;
+
+ if(argPresence[0]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for MetricThreshold. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &MetricThreshold);
+
+ if(MetricThreshold<0)
+ {
+ Scierror(999," Invalid Value for MetricThreshold. Please enter a non negative Double value\\n");
+ return 0;
+ }
+ argPresence[0]=1;
+ }
+ else if(strcmp(currentArg,"NumOctaves")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[1]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+
+ Scierror(999," Invalid Value for NumOctaves. Recommended Values are between 1 and 4\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &NumOctaves);
+
+ if(NumOctaves<1)
+ {
+ Scierror(999," Invalid Value for NumOctaves. Recommended Values are between 1 and 4\n");
+ return 0;
+ }
+
+ argPresence[1]=1;
+ }
+ else if(strcmp(currentArg,"NumScaleLevels")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[2]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx,piAddrVal) || !isScalar(pvApiCtx, piAddrVal))
+ {
+ Scierror(999," Invalid Value for NumScaleLevels. Recommended values are between 3 and 6\n");
+ return 0;
+ }
+
+ getScalarDouble(pvApiCtx, piAddrVal, &NumScaleLevels);
+
+ if(NumScaleLevels<3)
+ {
+ Scierror(999," Invalid Value for NumScaleLevels. Please enter an integer value greater than or equal to 3\n");
+ return 0;
+ }
+
+ argPresence[2]=1;
+ }
+ else if(strcmp(currentArg,"ROI")==0)
+ {
+ val_position=i+1;
+
+ if(argPresence[3]==1)
+ {
+ Scierror(999,"Do not enter the same parameter\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,val_position,&piAddrVal);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddrVal) || isVarComplex(pvApiCtx, piAddrVal))
+ {
+ Scierror(999,"Enter a List of 4 double arguments\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddrVal, &iRows, &iCols, &ROImat);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows*iCols!=4)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+
+ if(ROImat[0]<0 || ROImat[1]<0 || ROImat[2]<0 || ROImat[3]<0)
+ {
+ sciprint("Arguments cannot be negative\n");
+ return 0;
+ }
+
+ if(ROImat[0]>image.cols || ROImat[1]>image.rows || ROImat[0]+ROImat[2]>image.cols
+ || ROImat[1]+ROImat[3]>image.rows)
+ {
+ Scierror(999,"Please make sure the arguments are within the image range\n");
+ return 0;
+ }
+
+ argPresence[3]=1;
+ }
+ else
+ {
+ Scierror(999, "Error: \"%s\" name for input argument is not valid.\n", currentArg);
+ return 0;
+ }
+
+ }
+//********************************************* End of OIA ********************************************************
+
+int nOctaveLayers;
+
+ if(argPresence[2]==1)
+ nOctaveLayers = NumScaleLevels-2;
+
+
+ if(argPresence[0]==0)
+ MetricThreshold=1000;
+ if(argPresence[1]==0)
+ NumOctaves=3;
+ if(argPresence[2]==0)
+ nOctaveLayers = 2;
+ if(argPresence[3]==0)
+ {
+ ROImat=(double *)malloc(sizeof(double)*4);
+ ROImat[0]=0;
+ ROImat[1]=0;
+ ROImat[2]=image.cols;
+ ROImat[3]=image.rows;
+ }
+
+
+ Rect masker(ROImat[0], ROImat[1], ROImat[2], ROImat[3]);
+
+ Mat mask(image.size(), CV_8UC1, Scalar::all(0));
+ mask(masker).setTo(Scalar::all(255));
+
+
+
+ SURF my_object(MetricThreshold, NumOctaves, nOctaveLayers);
+
+ my_object.operator()(image, mask, myPoints, noArray());
+
+ int size= myPoints.size();
+
+//*************************************************************** Location ***************************************************************
+
+ ScaleData = (double *)malloc(sizeof(double)*size);
+ OrientationData = (double *)malloc(sizeof(double)*size);
+ MetricData = (double *)malloc(sizeof(double)*size);
+ LaplacianData = (int *)malloc(sizeof(int)*size);
+
+ iRows=size;
+ iCols=2;
+ int k=0;
+
+ LocationData = (double *)malloc(sizeof(double)*iRows*iCols);
+
+ for(int i=0;i<size;i++)
+ {
+
+ LocationData[k++] = myPoints[i].pt.x;
+ LocationData[k++] = myPoints[i].pt.y;
+ OrientationData[i] = 0;
+ MetricData[i] = myPoints[i].response;
+ LaplacianData[i] = myPoints[i].class_id;
+ double q=myPoints[i].size;
+// Scale = Current Filter Size * Base Filter Scale / Base Filter Size
+ q = q*1.2/9;
+ q = round(1000.0*q)/(1000.0);
+ ScaleData[i] = q;
+
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, size,2, LocationData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+//*************************************************************** Orientation ***************************************************************
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, size,1, OrientationData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+
+ //*********************************************************** Metric ********************************************************************
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, size,1, MetricData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
+
+//************************************************************ SignOfLaplacian ***********************************************************
+
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 4, size,1, LaplacianData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
+//*********************************************************** Scale *******************************************************************
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, size,1, ScaleData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+
+//*********************************************************** Size *********************************************************************
+
+ createScalarInteger32(pvApiCtx,nbInputArgument(pvApiCtx) + 6, size);
+
+ AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
+
+
+ //Returning the Output Variables as arguments to the Scilab environment
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_dilate.cpp b/sci_gateway1/cpp/opencv_dilate.cpp
new file mode 100644
index 0000000..44b26f1
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_dilate.cpp
@@ -0,0 +1,119 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#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 <sciprint.h>
+ #include "../common.h"
+
+ int opencv_dilate(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ char **type = NULL;
+ int i,j,k;
+ double anchorX,anchorY,iterations;
+ double *kernel = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for kernel
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &kernel);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr,0);
+ return 0;
+ }
+
+ double actualkernel[iRows][iCols];
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ actualkernel[i][j]=kernel[(j*iRows)+i];
+
+ Mat kernelMatrix(iRows,iCols,CV_64F,&actualkernel);
+
+ //for value of anchorX
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&anchorX);
+ if(intErr)
+ return intErr;
+
+ //for value of anchorY
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4 ,&anchorY);
+ if(intErr)
+ return intErr;
+
+ //for value of iterations
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&iterations);
+ if(intErr)
+ return intErr;
+
+ Mat new_image(image.rows,image.cols,image.type());
+ Point pt(anchorX,anchorY);
+
+ dilate(image,new_image,kernelMatrix,pt,iterations);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_ellipse.cpp b/sci_gateway1/cpp/opencv_ellipse.cpp
new file mode 100644
index 0000000..092ab78
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_ellipse.cpp
@@ -0,0 +1,278 @@
+/********************************************************
+ Author: Sukul Bagai
+*********************************************************
+ return_image = ellipse(input_image , x_coordinate_of_centre , y_coordinate_centre , first_axis, second_axis, angle, startAngle, endAngle, r_value,g_value,b_value,thickness,linetype,shift);
+********************************************************/
+
+#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_ellipse(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int *piAddr9 = NULL;
+ int *piAddr10 = NULL;
+ int *piAddr11 = NULL;
+ int *piAddr12 = NULL;
+ int *piAddr13 = NULL;
+ int *piAddr14 = NULL;
+ int i,j,k;
+ double thickness=1 , linetype=8, shift=0 ,centre_x ,centre_y,first_axis,second_axis,angle,startAngle,endAngle,r_value,g_value,b_value;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 14, 14);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat src;
+ retrieveImage(src,1);
+
+ //for value of x coordinate of centre
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2,&centre_x);
+ if(intErr)
+ return intErr;
+
+
+ //for value of y coordinate of centre
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&centre_y);
+ if(intErr)
+ return intErr;
+
+ //for value of first_axis
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&first_axis);
+ if(intErr)
+ return intErr;
+
+ //for value of second_axis
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5,&first_axis);
+ if(intErr)
+ return intErr;
+
+ //for value of angle
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6,&angle);
+ if(intErr)
+ return intErr;
+
+ //for value of startAngle
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7,&startAngle);
+ if(intErr)
+ return intErr;
+
+ //for value of endAngle
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr8,&endAngle);
+ if(intErr)
+ return intErr;
+
+ //for value of R value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,9,&piAddr9);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr9 ,&r_value);
+ if(intErr)
+ return intErr;
+
+ //for value of G value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,10,&piAddr10);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr10 ,&g_value);
+ if(intErr)
+ return intErr;
+
+ // for B value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,11,&piAddr11);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr11,&b_value);
+ if(intErr)
+ return intErr;
+
+ // for thickness of circle default: 1
+ sciErr = getVarAddressFromPosition(pvApiCtx,12,&piAddr12);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr12,&thickness);
+ if(intErr)
+ return intErr;
+
+ //for line type of circle default: 8
+ sciErr = getVarAddressFromPosition(pvApiCtx,13,&piAddr13);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr13,&linetype);
+ if(intErr)
+ return intErr;
+
+ // for shift in circle default : 0
+ sciErr = getVarAddressFromPosition(pvApiCtx,14,&piAddr14);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr14,&shift);
+ if(intErr)
+ return intErr;
+
+ // checking radius parameter
+ if (first_axis < 0)
+ {
+ first_axis=3;
+ sciprint("first_axis should be positive , 3 value was used instead\n");
+ }
+ if (second_axis < 0)
+ {
+ second_axis=3;
+ sciprint("second_axis should be positive , 3 value was used instead\n");
+ }
+ if (first_axis < second_axis)
+ {
+ double temp;
+ temp=first_axis;
+ first_axis=second_axis;
+ second_axis=temp;
+ sciprint("first_axis should be greater than second_axis. Values swapped.\n");
+ }
+ if(angle < 0 || angle > 360)
+ {
+ angle=45;
+ sciprint("Imvalid angle value used. Using 45 instead");
+ }
+ if(startAngle < 0 || startAngle > 360)
+ {
+ startAngle=45;
+ sciprint("Imvalid startAngle value used. Using 120 instead");
+ }
+ if(endAngle < 0 || endAngle > 360)
+ {
+ endAngle=45;
+ sciprint("Imvalid endAngle value used. Using 120 instead");
+ }
+ // checking the parmeters for correct values
+ if( r_value <0 || r_value >255)
+ {
+ r_value=0;
+ sciprint(" r value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( g_value <0 || g_value >255)
+ {
+ g_value=0;
+ sciprint(" g value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( b_value <0 || b_value >255)
+ {
+ b_value=0;
+ sciprint(" b value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if ((linetype!=0) && (linetype!=4)&& (linetype!=8))
+ {
+ linetype=8;
+ sciprint("Only 0/4/8 allowed , using 8 instead\n");
+ }
+ //temporary pt variable, to use in function as centre
+ Point pt(centre_x,centre_y);
+ Size sz(first_axis,second_axis);
+ /// Draw the circles detected
+
+ ellipse( src, pt, sz, angle, startAngle, endAngle, Scalar(r_value,g_value,b_value), thickness, linetype, shift);
+
+//// sending the image
+ string tempstring = type2str(src.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,src,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_ellipse2poly.cpp b/sci_gateway1/cpp/opencv_ellipse2poly.cpp
new file mode 100644
index 0000000..e7edef4
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_ellipse2poly.cpp
@@ -0,0 +1,171 @@
+/********************************************************
+ Author: Abhilasha Sancheti
+*********************************************************
+ pts = ellipse2Poly(double center_x,double center_y,double width,double height,int angle, int arcStart, int arcEnd, int delta)
+********************************************************/
+
+#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_ellipse2poly(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr1 = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ double *pstData = NULL;
+ int i,j,k ;
+ double center_x,center_y,width,height,arcstart,arcend,delta,angle;
+
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 8, 8);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+//// to retreive the value of x coordinate of center
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr1 ,&center_x);
+ if(intErr)
+ return intErr;
+
+
+
+//// to retreive the value of y coordinate of center
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2,&center_y);
+ if(intErr)
+ return intErr;
+
+//// to retreive the value of width
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&width);
+ if(intErr)
+ return intErr;
+
+//// to retreive the value of height
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&height);
+ if(intErr)
+ return intErr;
+
+//// to retreive the value of angle parameter
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5,&angle);
+ if(intErr)
+ return intErr;
+
+//// to retreive the value of arcstart parameter
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6,&arcstart);
+ if(intErr)
+ return intErr;
+
+//// to retreive the value of arcend parameter
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7,&arcend);
+ if(intErr)
+ return intErr;
+
+//// to retreive the value of delta parameter
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr8,&delta);
+ if(intErr)
+ return intErr;
+
+
+ vector<Point> pts;
+ Point center(center_x,center_y);
+ Size axes(width,height);
+ ellipse2Poly(center, axes, angle, arcstart, arcend,delta, pts);
+
+ int row = pts.size();
+ double *cor = (double *)malloc(row*2*sizeof(double));
+ for (int i=0;i<row;i++)
+ {
+ *(cor + i*2 +0)=pts[i].x;
+ // cout<<pts[i].x<<" "<<pts[i].y;
+ *(cor + i*2 +1)=pts[i].y;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, row, 2, cor);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_epipolarlines.cpp b/sci_gateway1/cpp/opencv_epipolarlines.cpp
new file mode 100644
index 0000000..369d7d8
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_epipolarlines.cpp
@@ -0,0 +1,321 @@
+/*********************************************************************************
+*Author : Kevin George
+*
+*-> To execute, epipolarlines(I1,I2)
+* where I1.1 & I2 are images
+*
+* This will display the matched points and the epipolar lines.
+*********************************************************************************/
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/calib3d/calib3d.hpp>
+#include <opencv2/imgproc/imgproc.hpp>
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include <stdio.h>
+#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"
+ //# include "../common.cpp"
+
+ int opencv_epipolarlines(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr=0;
+
+ //-> Mat containers for images
+ Mat img_1;
+ Mat img_2;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+
+ //-> Local variables
+ int *outList = NULL;
+ unsigned char *red = NULL;
+ unsigned char *green = NULL;
+ unsigned char *blue = NULL;
+
+ int *outList2 = NULL;
+ unsigned char *red2 = NULL;
+ unsigned char *green2 = NULL;
+ unsigned char *blue2 = NULL;
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ CheckInputArgument(pvApiCtx, 1, 5); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 5); //Check on Number of Output Arguments
+
+ //-> Read Image
+ retrieveImage( img_1, 1);
+ retrieveImage(img_2, 2);
+
+ //-> Count number of input arguments
+ //num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ //-> Based on number of input arguments
+
+//***************************************************** Actual Processing *************************************************************
+
+ //Mat img_1 = imread( "left.jpg", CV_LOAD_IMAGE_GRAYSCALE );
+ //Mat img_2 = imread( "right.jpg", CV_LOAD_IMAGE_GRAYSCALE );
+
+ cvtColor(img_1, img_1, CV_BGR2GRAY);
+ cvtColor(img_2, img_2,CV_BGR2GRAY);
+
+ //-- Step 1: Detect the keypoints using SURF Detector
+ int minHessian = 400;
+
+ SurfFeatureDetector detector( minHessian );
+
+ std::vector<KeyPoint> keypoints_1, keypoints_2;
+
+ detector.detect( img_1, keypoints_1 );
+ detector.detect( img_2, keypoints_2 );
+
+ //-- Step 2: Calculate descriptors (feature vectors)
+ SurfDescriptorExtractor extractor;
+
+ Mat descriptors_1, descriptors_2;
+
+ extractor.compute( img_1, keypoints_1, descriptors_1 );
+ extractor.compute( img_2, keypoints_2, descriptors_2 );
+
+ //-- Step 3: Matching descriptor vectors using FLANN matcher
+ FlannBasedMatcher matcher;
+ std::vector< DMatch > matches;
+ matcher.match( descriptors_1, descriptors_2, matches );
+
+ double max_dist = 0; double min_dist = 100;
+
+ //-- Quick calculation of max and min distances between keypoints
+ for( int i = 0; i < descriptors_1.rows; i++ )
+ { double dist = matches[i].distance;
+ if( dist < min_dist ) min_dist = dist;
+ if( dist > max_dist ) max_dist = dist;
+ }
+
+ std::vector< DMatch > good_matches;
+ vector<Point2f> points1,points2;
+
+ for( int i = 0; i < descriptors_1.rows; i++ )
+ { //if( matches[i].distance <= max(2*min_dist, 0.02) )
+ if( matches[i].distance <= max(3*min_dist, 0.02) )
+ {
+ good_matches.push_back( matches[i]);
+ points2.push_back( keypoints_2[matches[i].trainIdx].pt );
+ points1.push_back( keypoints_1[matches[i].queryIdx].pt );
+ }
+
+ }
+
+ //***************** Finding Fundamental Matrix **************************
+
+ vector<uchar> states;
+ Mat f = findFundamentalMat(points1, points2, FM_RANSAC, 3, 0.99, states);
+ //Mat F = findFundamentalMat(points1, points2, FM_LMEDS, 3, 0.99, states);
+ string window = "epipolarlines";
+ //drawEpipolarLines(window, fundamental_matrix, img_1, img_2, points1, points2);
+
+
+ vector<Vec<float,3> > epilines1, epilines2;
+ computeCorrespondEpilines(points1, 1, f, epilines1); //Index starts with 1
+ computeCorrespondEpilines(points2, 2, f, epilines2);
+
+ cvtColor(img_1,img_1,COLOR_GRAY2BGR);
+ cvtColor(img_2,img_2,COLOR_GRAY2BGR);
+ int inlierDistance = -1;
+ // cout<<points1.size()<<endl<<points2.size( );
+ cv::RNG rng(0);
+ for(int i=0; i<points1.size(); i++)
+ {
+ /*if(inlierDistance > 0)
+ {
+ if(distancePointLine(points1[i], epilines2[i]) > inlierDistance ||
+ distancePointLine(points2[i], epilines1[i]) > inlierDistance)
+ {
+ //The point match is no inlier
+ continue;
+ }
+ } */
+
+ //Mat outImg(img1.rows, img1.cols*2, CV_8UC3);
+ //Rect rect1(0,0, img1.cols, img1.rows);
+
+//************************************************************* Draw epipolar lines function ********************************************************
+ cv::Scalar color(rng(256),rng(256),rng(256));
+ line(img_1, Point(0,-epilines1[i][2]/epilines1[i][1]), Point(img_1.cols,-(epilines1[i][2]+epilines1[i][0]*img_1.cols)/epilines1[i][1]),color);
+ circle(img_1, points1[i], 3, color, -1, CV_AA);
+
+ line(img_2, Point(0,-epilines1[i][2]/epilines1[i][1]), Point(img_2.cols,-(epilines1[i][2]+epilines1[i][0]*img_2.cols)/epilines1[i][1]),color);
+ circle(img_2, points2[i], 3, color, -1, CV_AA);
+ }
+
+//************************************************ Returning first image **************************************************
+
+ if( img_1.channels() == 1)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ red = (unsigned char *)malloc(sizeof(unsigned char)*img_1.rows*img_1.cols);
+
+ for(int k=0;k<img_1.rows;k++)
+ for(int p=0;p<img_1.cols;p++)
+ red[k+img_1.rows*p]=img_1.at<uchar>(k, p);
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, img_1.rows, img_1.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ }
+
+ else
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red = (unsigned char *)malloc(sizeof(unsigned char)*img_1.rows*img_1.cols);
+ green = (unsigned char *)malloc(sizeof(unsigned char)*img_1.rows*img_1.cols);
+ blue = (unsigned char *)malloc(sizeof(unsigned char)*img_1.rows*img_1.cols);
+
+ for(int k=0;k<img_1.rows;k++)
+ {
+ for(int p=0;p<img_1.cols;p++)
+ {
+ Vec3b intensity = img_1.at<Vec3b>(k, p);
+ red[k+img_1.rows*p]=intensity.val[2];
+ green[k+img_1.rows*p]=intensity.val[1];
+ blue[k+img_1.rows*p]=intensity.val[0];
+ }
+ }
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, img_1.rows, img_1.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 2, img_1.rows, img_1.cols, green);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 3, img_1.rows, img_1.cols, blue);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ free(green);
+ free(blue);
+
+ }
+
+
+ /*imshow("title", img_1);
+ waitKey(0);
+ imshow("title2", img_2);
+ waitKey(0);*/
+
+ if( img_2.channels() == 1)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, &outList2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ red2 = (unsigned char *)malloc(sizeof(unsigned char)*img_2.rows*img_2.cols);
+
+ for(int k=0;k<img_2.rows;k++)
+ for(int p=0;p<img_2.cols;p++)
+ red2[k+img_2.rows*p]=img_2.at<uchar>(k, p);
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, outList2, 1, img_2.rows, img_2.cols, red2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red2);
+ }
+
+ else
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 3, &outList2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red2 = (unsigned char *)malloc(sizeof(unsigned char)*img_2.rows*img_2.cols);
+ green2 = (unsigned char *)malloc(sizeof(unsigned char)*img_2.rows*img_2.cols);
+ blue2 = (unsigned char *)malloc(sizeof(unsigned char)*img_2.rows*img_2.cols);
+
+ for(int k=0;k<img_2.rows;k++)
+ {
+ for(int p=0;p<img_2.cols;p++)
+ {
+ Vec3b intensity2 = img_2.at<Vec3b>(k, p);
+ red2[k+img_2.rows*p]=intensity2.val[2];
+ green2[k+img_2.rows*p]=intensity2.val[1];
+ blue2[k+img_2.rows*p]=intensity2.val[0];
+ }
+ }
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, outList2, 1, img_2.rows, img_2.cols, red2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, outList2, 2, img_2.rows, img_2.cols, green2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, outList2, 3, img_2.rows, img_2.cols, blue2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red2);
+ free(green2);
+ free(blue2);
+
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_erode.cpp b/sci_gateway1/cpp/opencv_erode.cpp
new file mode 100644
index 0000000..fd12082
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_erode.cpp
@@ -0,0 +1,117 @@
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#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 <sciprint.h>
+ #include "../common.h"
+
+ int opencv_erode(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ char **type = NULL;
+ int i,j,k;
+ double anchorX,anchorY,iterations;
+ double *kernel;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for kernel
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &kernel);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr,0);
+ return 0;
+ }
+
+ double actualkernel[iRows][iCols];
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ actualkernel[i][j]=kernel[(j*iRows)+i];
+
+ Mat kernelMatrix(iRows,iCols,CV_64F,&actualkernel);
+
+ //for value of anchorX
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&anchorX);
+ if(intErr)
+ return intErr;
+
+ //for value of anchorY
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4 ,&anchorY);
+ if(intErr)
+ return intErr;
+
+ //for value of iterations
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&iterations);
+ if(intErr)
+ return intErr;
+
+ Mat new_image(image.rows,image.cols,image.type());
+ Point pt(anchorX,anchorY);
+
+ erode(image,new_image,kernelMatrix,pt,iterations);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_estimateFundamentalMatrix.cpp b/sci_gateway1/cpp/opencv_estimateFundamentalMatrix.cpp
new file mode 100644
index 0000000..4a2cec2
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_estimateFundamentalMatrix.cpp
@@ -0,0 +1,318 @@
+/****************************************************************************************************
+estimateFundamentalMatrix(InputArray1,InputArray2,'method','RANSAC','param1',2,'param2',0.99);
+
+possible methods are 7POINT,8POINT,RANSAC,LMEDS
+param1- It indiacates maximum distance from a point to an epipolar line in pixels
+param2- It specifies a desirable level of confidence
+********************************************************* ***********************************************/
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/calib3d/calib3d.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_estimateFundamentalMat(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iComplex = 0;
+ int iType = 0;
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ int iRows,iCols;
+ int iA1Rows=0,iA1Cols=0,iA2Rows=0,iA2Cols=0;
+ int method=FM_RANSAC;
+ int nbInputArguments,iter,i,j;
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+ double* pdblReal = NULL;
+ double *iArray1=NULL,*iArray2=NULL;
+ double param1=3,param2=0.99;
+
+ vector<Point2f> point1,point2;
+
+ CheckInputArgument(pvApiCtx, 2, 8);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+ providedArgs = (bool*) malloc(sizeof(bool) * 3);
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iA1Rows, &iA1Cols, &iArray1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iA2Rows, &iA2Cols, &iArray2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iA1Rows != iA2Rows)
+ {
+ Scierror(999, "There must be the same number of points in both input arrays\n");
+ return 0;
+ }
+
+ for(i=0;i<iA1Rows;i++){
+ point1.push_back(Point2f(iArray1[i],iArray1[iA1Rows+i]));
+ point2.push_back(Point2f(iArray2[i],iArray2[iA2Rows+i]));
+ }
+ for(iter=3; iter<= nbInputArguments; iter++)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ if(strcmp(currentArg, "method")==0)
+ {
+ //sciprint("in if\tcurrentArg:%s\n",currentArg);
+ if(iter+1<=nbInputArguments && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ currentArg=pstData[0];
+ // Checking if values are in proper range. Same for all optional arguments
+ //sciprint("in if\tcurrentArg:%s\n",currentArg);
+ if(strcmp(currentArg,"7POINT")==0)
+ method = FM_7POINT;
+ else if (strcmp(currentArg,"8POINT")==0)
+ method= FM_8POINT;
+ else if (strcmp(currentArg,"RANSAC")==0)
+ method= FM_RANSAC;
+ else if (strcmp(currentArg,"LMEDS")==0)
+ method= FM_LMEDS;
+ else
+ {
+ sciprint("Invalid method given. RANSAC was used instead");
+ method= FM_RANSAC;
+ }
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "param1")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &param1);
+ if(intErr)
+ {
+ return intErr;
+ }
+ providedArgs[1] = 1;
+ }
+ else if(providedArgs[1])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "param2")==0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &param2);
+ if(intErr)
+ {
+ return intErr;
+ }
+ providedArgs[2] = 1;
+ }
+ else if(providedArgs[2])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999, "Error: \"%s\" name for input argument is not valid.\n", currentArg);
+ return 0;
+ }
+ }
+
+ if (method==FM_7POINT && point1.size()!=7){
+ Scierror(999, "Error: For FM_7POINT method number of points in each array must be 7\n");
+ return 0;
+ }
+ if (method!=FM_7POINT && point1.size()<8 ){
+ Scierror(999, "Error: Number of points in each array must be greater than or equal to 8\n");
+ return 0;
+ }
+
+ Mat fm=cv::findFundamentalMat(point1, point2, method, param1, param2);
+ pdblReal = (double*) malloc(sizeof(double) * fm.rows *3);
+ for(i = 0 ; i < fm.rows ; i++)
+ {
+ for(j = 0 ; j < 3 ; j++)
+ {
+ pdblReal[i + fm.rows * j] = fm.at<double>(i,j);
+ }
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, fm.rows , 3, pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_estimateGeometricTransform.cpp b/sci_gateway1/cpp/opencv_estimateGeometricTransform.cpp
new file mode 100644
index 0000000..2a4ec4b
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_estimateGeometricTransform.cpp
@@ -0,0 +1,164 @@
+/*********************************************************************************
+*Author : Kevin George
+*
+*-> To execute, estimateGeometricTransform(I1,I2)
+* where I1 & I2 are images
+*
+*This program only gives an affine transformation matrix
+*********************************************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include <iostream>
+#include <math.h>
+#include <vector>
+
+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"
+ // # include "../common.cpp"
+
+ int opencv_estimateGeometricTransform(char *fname, unsigned long fname_len)
+ {
+
+ //-> Error Management variables
+ SciErr sciErr;
+ int intErr=0;
+
+ //-> Mat containers for images
+ Mat image_1;
+ Mat image_2;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+
+ //-> Local variables
+ int minHessian = 400; //-> For SURF algorithm
+ int num_InputArgs;
+ //-> KeyPoint is data structure to store a point feature
+ // detected by a keypoint detector(OpenCV)
+ vector<KeyPoint> keypoints_1;
+ vector<KeyPoint> keypoints_2;
+ Mat descriptors_1, descriptors_2;
+ Mat img_matches;
+ vector< DMatch > good_matches;
+ vector< DMatch > matches;
+ vector<Point2f> a,b;
+ double max_dist = 0; double min_dist = 100;
+ /*double *indexPairs = NULL;
+ double *matchMetric = NULL;
+ double size=1;
+ int iRows, iCols; */
+
+ //KeyPoint *X = new KeyPoint; //-> Remember to free this Kevin
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ CheckInputArgument(pvApiCtx, 1, 5); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 5); //Check on Number of Output Arguments
+
+ //-> Read Image
+ retrieveImage( image_1, 1);
+ retrieveImage(image_2, 2);
+
+ //-> Count number of input arguments
+ //num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ //-> Based on number of input arguments
+
+//***************************************************** Actual Processing *************************************************************
+
+ //-- Step 1: Calculate keypoints
+ SurfFeatureDetector detector( minHessian );
+ detector.detect( image_1, keypoints_1 );
+ detector.detect( image_2, keypoints_2 );
+
+ //-- Step 2: Calculate descriptors (feature vectors)
+ SurfDescriptorExtractor extractor;
+ extractor.compute( image_1, keypoints_1, descriptors_1 );
+ extractor.compute( image_2, keypoints_2, descriptors_2 );
+
+ //-- Step 3: Matching descriptor vectors using FLANN matcher
+ FlannBasedMatcher matcher;
+ matcher.match( descriptors_1, descriptors_2, matches );
+
+ //-- Quick calculation of max and min distances between keypoints
+ for( int i = 0; i < descriptors_1.rows; i++ )
+ {
+ double dist = matches[i].distance;
+ if( dist < min_dist ) min_dist = dist;
+ if( dist > max_dist ) max_dist = dist;
+ }
+
+ for( int i = 0; i < descriptors_1.rows; i++ )
+ {
+ if( matches[i].distance <= max(2*min_dist, 0.02) )
+ { good_matches.push_back( matches[i]); }
+ }
+
+ //queryidx- keypoints1
+ //traindidx- keypoints2
+
+
+ for(int i=0;i<3;i++)
+ {
+ a.push_back( keypoints_1[good_matches[i].queryIdx].pt );
+ b.push_back( keypoints_2[good_matches[i].trainIdx].pt );
+ }
+
+
+ Mat M = getAffineTransform( Mat(a), Mat(b) );
+
+ /* double output[M.rows][M.cols];
+
+ for(int i=0; i<M.rows; ++i)
+ {
+ const double* Mi = M.ptr<double>(i);
+ for (int j = 0; j < M.cols; j++)
+ {
+ output[i][j] = Mi[j];
+ }
+ } */
+ double *output = NULL;
+ output = (double *)malloc(sizeof(double)*M.rows*M.cols);
+
+ //-> Accessing elements of Mat object M
+ for(int i=0; i<M.rows; ++i)
+ {
+ const double* Mi = M.ptr<double>(i);
+ for (int j = 0; j < M.cols; j++)
+ {
+ output[i+j] = Mi[j];
+ }
+ }
+
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx)+1, M.rows, M.cols, output);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Returning Output
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_estimateUncalibratedRectification.cpp b/sci_gateway1/cpp/opencv_estimateUncalibratedRectification.cpp
new file mode 100644
index 0000000..c0078bd
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_estimateUncalibratedRectification.cpp
@@ -0,0 +1,201 @@
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/calib3d/calib3d.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_estimateUncalibratedRectification(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr=0;
+ int iComplex = 0;
+ int iType = 0;
+ int *piAddr = NULL;
+ int i,j;
+ int iA1Rows=0,iA1Cols=0,iA2Rows=0,iA2Cols=0;
+ int fmRows=0,fmCols=0,imageRows=0,imageCols=0;
+ double *fm=NULL,*iArray1=NULL,*iArray2=NULL,*imageSize=NULL;
+ double *oArray1=NULL,*oArray2=NULL;
+ Mat fundamentalMatrix(3,3,CV_64F);
+ int imagesize[2];
+ vector<Point2f> points1,points2;
+
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 2, 2) ;
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &fmRows, &fmCols, &fm);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iA1Rows, &iA1Cols, &iArray1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iA2Rows, &iA2Cols, &iArray2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &imageRows, &imageCols, &imageSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(fmRows!=3 || fmCols!=3)
+ {
+ Scierror(999, "Fudamental matrix must be of size 3*3\n");
+ return 0;
+ }
+ if(iA1Rows != iA2Rows)
+ {
+ Scierror(999, "There must be the same number of points in both input arrays\n");
+ return 0;
+ }
+ if(imageRows!=1 || (imageCols!=2 && imageCols!=3))
+ {
+ Scierror(999, "Image size must be of vector of with 2 or 3 elements\n");
+ return 0;
+ }
+ for(i = 0 ; i < 3 ; i++)
+ {
+ for(j = 0 ; j < 3 ; j++)
+ {
+ fundamentalMatrix.at<double>(i,j) = fm[i+3*j];
+ }
+ }
+ for(i=0;i<iA1Rows;i++)
+ {
+ points1.push_back(Point2f(iArray1[i],iArray1[iA1Rows+i]));
+ points2.push_back(Point2f(iArray2[i],iArray2[iA2Rows+i]));
+ }
+ Mat H1,H2;
+ if (imageCols==2)
+ stereoRectifyUncalibrated(points1, points2, fundamentalMatrix,Size(imageSize[0],imageSize[1]), H1, H2);
+ else if (imageCols==3)
+ stereoRectifyUncalibrated(points1, points2, fundamentalMatrix,Size(imageSize[0],imageSize[1],imageSize[2]), H1, H2);
+ oArray1 = (double*) malloc(sizeof(double) * 3 *3);
+ oArray2 = (double*) malloc(sizeof(double) * 3 *3);
+ for(i = 0 ; i < 3 ; i++)
+ {
+ for(j = 0 ; j < 3 ; j++)
+ {
+ oArray1[i + 3 * j] = H1.at<double>(i,j);
+ oArray2[i + 3 * j] = H2.at<double>(i,j);
+ }
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3 , 3, oArray1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 3 , 3, oArray2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_evaluate.cpp b/sci_gateway1/cpp/opencv_evaluate.cpp
new file mode 100644
index 0000000..2794b90
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_evaluate.cpp
@@ -0,0 +1,417 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <iostream>
+#include <opencv2/opencv.hpp>
+#include <opencv2/nonfree/nonfree.hpp>
+#include <opencv2/ml/ml.hpp>
+
+using namespace std;
+using namespace cv;
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+ int opencv_evaluate(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+
+ //------Local variables------//
+ int upright = 1;
+ Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
+ Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor(1, 4, 2, 1, int(upright));
+ BOWImgDescriptorExtractor bowDE(extractor, matcher);
+ SurfFeatureDetector detector(1, 4, 2, 1, int(upright));
+ char *classifierLocation = NULL;
+ Mat dictionary,inp,features;
+ double response;
+ vector<KeyPoint> keyPoints;
+ CvSVM svm;
+ int dictionarySize;
+ int *piAddr = NULL;
+ int *piChild = NULL;
+ int iRows, iCols;
+ char **pstData = NULL;
+ int *piLen = NULL;
+ int *count = NULL;
+ char **classifierDescription = NULL;
+ int classifierDescriptionCount;
+ char **description = NULL;
+ char ***location = NULL;
+ char *bagOfFeaturesLocation = NULL;
+ int descriptionCount;
+ double *confMatrix = NULL;
+ char *fileName = NULL;
+ double avgAccuracy = 0;
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ //------Get input arguments------//
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr))
+ {
+ Scierror(999, "Error: The input argument #1 is not of type classifier.\n");
+ return 0;
+ }
+
+ // Extracting object type and checking if type is classifier
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"classifier")==0))
+ {
+ Scierror(999, "Error: The input argument #1 is not of type classifier.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=1 || iCols!=1)
+ {
+ Scierror(999, "1x1 Matrix expected for classifier argument.");
+ return 0;
+ }
+ classifierLocation = pstData[0];
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 3, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 3, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 3, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=1 || iCols!=1)
+ {
+ Scierror(999, "1x1 Matrix expected for bagOfFeatures argument.");
+ return 0;
+ }
+ bagOfFeaturesLocation = pstData[0];
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 4, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 4, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ classifierDescription = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ classifierDescription[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 4, &iRows, &iCols, piLen, classifierDescription);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ classifierDescriptionCount = iRows;
+ // Second Argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr))
+ {
+ Scierror(999, "Error: The input argument #2 is not of type imageSet.\n");
+ return 0;
+ }
+
+ // Extracting object type and checking if type is imageSet
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"imageSet")==0))
+ {
+ Scierror(999, "Error: The input argument #2 is not of type imageSet.\n");
+ return 0;
+ }
+
+ // Extracting Description attribute of input argument
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ description = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ description[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ descriptionCount = iRows;
+
+ // Extracting Count attribute of input argument
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ location = (char***) malloc(sizeof(char**) * descriptionCount);
+ sciErr = getListItemAddress(pvApiCtx, piAddr, 4, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int iter = 1; iter<=descriptionCount; iter++)
+ {
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ location[iter-1] = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int colIter = 0 ; colIter < iRows * iCols ; colIter++)
+ {
+ location[iter-1][colIter] = (char*)malloc(sizeof(char) * (piLen[colIter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, location[iter-1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ //------Actual processing------//
+ if(descriptionCount != classifierDescriptionCount)
+ {
+ Scierror(999, "Error: The input imageSet does not match the classifier's training set.\n");
+ return 0;
+ }
+ for(int i=0; i<descriptionCount; i++)
+ {
+ if(strcmp(classifierDescription[i],description[i])!=0)
+ {
+ Scierror(999, "Error: The input imageSet does not match the classifier's training set.\n");
+ return 0;
+ }
+ }
+ sciprint("Evaluating image category classifier for %d categories.\n",descriptionCount);
+ sciprint("--------------------------------------------------------\n\n");
+ for(int i=0;i<descriptionCount;i++)
+ {
+ sciprint("# Category %d: %s\n",i+1,description[i]);
+ }
+ sciprint("\n");
+ confMatrix = (double*) malloc(sizeof(double)*descriptionCount*descriptionCount);
+ for(int i=0;i<descriptionCount*descriptionCount;i++)
+ {
+ confMatrix[i]=0;
+ }
+ FileStorage fs(bagOfFeaturesLocation, FileStorage::READ);
+ fs["dictionary"] >> dictionary;
+ fs.release();
+ dictionarySize = dictionary.rows;
+ bowDE.setVocabulary(dictionary);
+ svm.load(classifierLocation);
+ for(int i=0; i<descriptionCount;i++)
+ {
+ sciprint("# Evaluating %d images from category %d ...",count[i],i+1);
+ for(int j=0; j<count[i]; j++)
+ {
+ features.release();
+ keyPoints.clear();
+ fileName = location[i][j];
+ inp = imread(fileName);
+ detector.detect(inp, keyPoints);
+ bowDE.compute(inp, keyPoints, features);
+ response = svm.predict(features);
+ confMatrix[i+(int)response*descriptionCount]++;
+ }
+ sciprint("done.\n");
+ }
+ sciprint("\n");
+ sciprint("\t PREDICTED\n");
+ sciprint("KNOWN\t|");
+ for(int i=0;i<descriptionCount;i++)
+ {
+ sciprint(" %d\t",i+1);
+ }
+ sciprint("\n");
+ for(int i=0; i<descriptionCount;i++)
+ {
+ sciprint("%d\t|",i+1);
+ for(int j=0; j<descriptionCount; j++)
+ {
+ confMatrix[i+descriptionCount*j] /= count[i];
+ sciprint(" %.2f\t",confMatrix[i+descriptionCount*j]);
+ }
+ sciprint("\n");
+ }
+ sciprint("\n");
+ for(int i=0;i<descriptionCount*descriptionCount;i=i+descriptionCount+1)
+ {
+ avgAccuracy += confMatrix[i];
+ }
+ sciprint("# Average accuracy: %f\n",avgAccuracy/descriptionCount);
+ //------Create output arguments------//
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx)+1, descriptionCount, descriptionCount, confMatrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_evaluateImageRetrieval.cpp b/sci_gateway1/cpp/opencv_evaluateImageRetrieval.cpp
new file mode 100644
index 0000000..d8bed5c
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_evaluateImageRetrieval.cpp
@@ -0,0 +1,566 @@
+#
+/*************************************************************************************************************************************
+* Author: Umang Agrawal *
+* Code: evaluateImageRetrieval.cpp *
+* Funtion Call: [ Average_Precision, Index, Score ] = evaluateImageRetreival( QureyImage, IndexImage, Expected Index, OptionalArgument) *
+* Optional Argument: Name Value *
+* NumResults Any Value greater than 0 *
+* ROI [ x_coordinate y_coordinate width height ] *
+*************************************************************************************************************************************/
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/ml/ml.hpp"
+
+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"
+
+ bool count_based(const vector<int>& a, const vector<int>& b);// {
+ // return a[1] > b[1];
+ //}
+
+ int opencv_evaluateImageRetrieval(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piChild = NULL;
+ int *piGrandChild = NULL;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ int iRows, iCols;
+ int no_item_list = 0;
+ int no_item_list_2 = 0;
+ int inp_params = 0;
+ char **arg = NULL;
+
+ double *expectedID = NULL;
+ char ***location_img = NULL;
+ double **WordIndex = NULL;
+ double **Location = NULL;
+ double **Vocab_size = NULL;
+ double **Count = NULL;
+ double *wordFrequency = NULL;
+ char *bagOfFeaturesLocation = NULL;
+ int count_res = 0, count_roi = 0;
+ double numRes = 0;
+ double *roi_arg = NULL;
+ double x, y, width, height;
+ int no_expectation = 0;
+ int count;
+
+ Mat image;
+ Mat feature_des;
+ Mat dictionary;
+ Mat des_matched;
+ Mat hist;
+ vector<KeyPoint> keypoints;
+ vector<KeyPoint> valid_key;
+ vector< vector<int> > clusterID;
+ vector<int> WordIndex_size;
+ vector<int> avg_ID;
+
+ int indx;
+ int search_ind;
+ double *Index_Out = NULL;
+ double *Score = NULL;
+ double **ImageWords = NULL;
+ double avg_prec = 0;
+
+ CheckInputArgument(pvApiCtx, 3, 7); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 3); //Check on Number of Output Arguments
+
+ retrieveImage(image, 1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr2))
+ {
+ Scierror(999, "Error: Invalid Second argument. List Expected.\n");
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx, piAddr2, &no_item_list);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!(strcmp(pstData[0],"invertedImageIndex")==0))
+ {
+ Scierror(999, "Error: The input argument 2 is not of type invertedImageIndex.\n");
+ return 0;
+ }
+
+ sciErr = getListItemAddress(pvApiCtx, piAddr2, 2, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx, piChild, &no_item_list_2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ WordIndex = (double**)malloc(sizeof(double*)*no_item_list_2);
+ Location = (double**)malloc(sizeof(double*)*no_item_list_2);
+ Vocab_size = (double**)malloc(sizeof(double*)*no_item_list_2);
+ Count = (double**)malloc(sizeof(double*)*no_item_list_2);
+ for( int i=0; i<no_item_list_2; i++)
+ {
+ sciErr = getListItemAddress(pvApiCtx, piChild, i+1, &piGrandChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 1, &iRows, &iCols, &WordIndex[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ WordIndex_size.push_back(iRows);
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 2, &iRows, &iCols, &Location[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 3, &iRows, &iCols, &Vocab_size[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 4, &iRows, &iCols, &Count[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr2, 3, &iRows, &iCols, &wordFrequency);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 4, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 4, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ bagOfFeaturesLocation = pstData[0];
+ if(no_item_list == 5)
+ {
+ location_img = (char***)malloc(sizeof(char**)*1);
+ sciErr = getListItemAddress(pvApiCtx, piAddr2, 5, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ location_img[0] = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int colIter = 0 ; colIter < iRows * iCols ; colIter++)
+ {
+ location_img[0][colIter] = (char*)malloc(sizeof(char) * (piLen[colIter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, 1, &iRows, &iCols, piLen, location_img[0]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !isVarMatrixType(pvApiCtx, piAddr3))
+ {
+ Scierror(999,"Expecting a Matrix indicating the number of Expected IDs\n");
+ return 0;
+ }
+ if(!(isDoubleType(pvApiCtx, piAddr3)||isIntegerType(pvApiCtx, piAddr3)))
+ {
+ Scierror(999,"Expecting a matrix of integer values indicating the indices of Expected IDs\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols, &expectedID);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows==1 && iCols!=1)
+ no_expectation = iCols;
+ else if(iRows!=1 && iCols==1)
+ no_expectation = iRows;
+ else no_expectation = iRows;
+
+ inp_params = *getNbInputArgument(pvApiCtx);
+ for( int i=4; i<=inp_params; i++)
+ {
+ if( inp_params%2 == 0)
+ {
+ Scierror(999,"Either Argument Name or its Value missing\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr4))
+ {
+ Scierror(999, "%s: Wrong type of argument for Name of Optional Argument. A string is expected.\n", fname);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ free(arg);
+ return 0;
+ }
+
+ if(strcmp(arg[0],"NumResuts") == 0)
+ {
+ if(count_res != 0)
+ {
+ Scierror(999,"NumResults Argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr5);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of value
+ if(!(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr5)))
+ {
+ Scierror(999,"Not a valid type of value for NumResults.\n");
+ return 0;
+ }
+ if(getScalarDouble(pvApiCtx, piAddr5, &numRes))
+ {
+ Scierror(999,"Error Reading value of NumResults Argument\n");
+ return 0;
+ }
+ if(numRes < 0)
+ {
+ Scierror(999,"Not a valid value for NumResults\n");
+ return 0;
+ }
+ i++;
+ count_res += 1;
+ }
+ else if(strcmp(arg[0],"ROI") == 0)
+ {
+ if(count_roi != 0)
+ {
+ Scierror(999,"ROI Argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr5);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of argument
+ if(!(isDoubleType(pvApiCtx, piAddr5)||isIntegerType(pvApiCtx, piAddr5)))
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr5, &iRows, &iCols, &roi_arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the elements of the list to their proper function
+ x = roi_arg[0];
+ y = roi_arg[1];
+ width = roi_arg[2];
+ height = roi_arg[3];
+ i++;
+ count_roi += 1;
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument Name\n");
+ return 0;
+ }
+ }
+
+ if(count_roi != 0)
+ {
+ Rect masker(x, y, width, height);
+ Mat croppedRef(image, masker);
+ image = Mat();
+ croppedRef.copyTo(image);
+ }
+
+ FileStorage fs(bagOfFeaturesLocation, FileStorage::READ);
+ fs["dictionary"] >> dictionary;
+ fs.release();
+
+ SurfFeatureDetector detector(100, 4, 2, 1, 1);
+ Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
+ Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor(100, 4, 2, 1, 1);
+ BOWImgDescriptorExtractor bowDE(extractor, matcher);
+ bowDE.setVocabulary(dictionary);
+ detector.detect(image, keypoints);
+ bowDE.compute(image, keypoints, hist, &clusterID, &des_matched);
+
+ ImageWords = (double**)malloc(sizeof(double*)*4*1);
+ ImageWords[0] = (double*)malloc(sizeof(double)*keypoints.size()*1);
+ ImageWords[1] = (double*)malloc(sizeof(double)*keypoints.size()*2);
+ ImageWords[2] = (double*)malloc(sizeof(double)*1);
+ ImageWords[3] = (double*)malloc(sizeof(double)*1);
+
+ ImageWords[2][0] = Vocab_size[0][0];
+ ImageWords[3][0] = keypoints.size();
+
+ vector<vector<int> > count_index(no_item_list_2 , vector<int>(3));
+
+ for( int i=0; i<keypoints.size(); i++)
+ {
+ ImageWords[1][i] = keypoints[i].pt.x;
+ ImageWords[1][keypoints.size() + i] = keypoints[i].pt.y;
+ }
+ for( int i=0; i<clusterID.size(); i++)
+ {
+ for( int j=0; j<clusterID[i].size(); j++)
+ {
+ indx = clusterID[i][j];
+ ImageWords[0][indx] = i;
+ }
+ }
+
+ for( int i=0; i<no_item_list_2; i++)
+ {
+ count = 0;
+ for( int j=0; j<keypoints.size(); j++)
+ {
+ search_ind = ImageWords[0][j];
+ for( int k=0; k<WordIndex_size[i]; k++)
+ {
+ if(int(WordIndex[i][k]) == int(search_ind))
+ {
+ count += 1;
+ break;
+ }
+ }
+ }
+ count_index[i][0] = i+1;
+ count_index[i][1] = count;
+ count_index[i][2] = WordIndex_size[i];
+ }
+
+ sort(count_index.begin(), count_index.end(), count_based);
+ if(count_res == 0 || no_item_list_2<numRes)
+ numRes = no_item_list_2;
+ Index_Out = (double*)malloc(sizeof(double)*numRes);
+ Score = (double*)malloc(sizeof(double)*numRes);
+ for( int i=0; i<numRes; i++)
+ {
+ Index_Out[i] = count_index[i][0];
+ Score[i] = double(count_index[i][1])/double(keypoints.size());
+ }
+
+ int flag = 0;
+ for( int i =0; i<no_expectation; i++)
+ {
+ if(expectedID[i] <= 0 || expectedID[i]>no_item_list_2 )
+ {
+ Scierror(999,"Not a valid expected Index ID. \n");
+ return 0;
+ }
+ int k = int(expectedID[i]);
+ if( i==0 )
+ {
+ for( int j=0; j<WordIndex_size[k-1]; j++)
+ {
+ avg_ID.push_back(WordIndex[k-1][j]);
+ }
+ }
+ else
+ {
+ for( int j=0; j<WordIndex_size[k-1]; j++)
+ {
+ flag = 0;
+ search_ind = WordIndex[k-1][j];
+ for( int k=0; k<avg_ID.size(); k++)
+ {
+ if( avg_ID[k] == search_ind)
+ {
+ flag = 1;
+ }
+ }
+ if(flag==0)
+ avg_ID.push_back(search_ind);
+ }
+ }
+ }
+
+ count = 0;
+ for( int i=0; i<keypoints.size(); i++)
+ {
+ search_ind = ImageWords[0][i];
+ for( int j=0; j<avg_ID.size(); j++)
+ {
+ if(search_ind == avg_ID[j])
+ {
+ count += 1;
+ break;
+ }
+ }
+ }
+ avg_prec = double(count)/double(keypoints.size());
+
+ if(createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, avg_prec))
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, numRes, 1, Index_Out);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, numRes, 1, Score);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx)+2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx)+3;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_extractFeatures.cpp b/sci_gateway1/cpp/opencv_extractFeatures.cpp
new file mode 100644
index 0000000..abb8ffc
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_extractFeatures.cpp
@@ -0,0 +1,1706 @@
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+
+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"
+
+ /*string type2str(int type)
+ {
+ string r;
+ uchar depth = type & CV_MAT_DEPTH_MASK;
+ uchar chans = 1 + (type >> CV_CN_SHIFT);
+ switch ( depth )
+ {
+ case CV_8U: r = "8U"; break;
+ case CV_8S: r = "8S"; break;
+ case CV_16U: r = "16U"; break;
+ case CV_16S: r = "16S"; break;
+ case CV_32S: r = "32S"; break;
+ case CV_32F: r = "32F"; break;
+ case CV_64F: r = "64F"; break;
+ default: r = "User"; break;
+ }
+ r += "C";
+ r += (chans+'0');
+ return r;
+ }*/
+
+ int opencv_extractFeatures(char *fname, unsigned long fname_len)
+ {
+ //......................................................................................................................................................................................
+ //Declarations
+ // Error Handling
+ SciErr sciErr;
+
+ // Address of Various Scilab API
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+
+ // Number of input and output Arguments
+ int inputArguments = 0;
+ int out_params;
+
+ // Matrix Reading Argument
+ int iPrec = 0;
+ int noItemInList = 0;
+ int iRows,iCols;
+ int Rows, Cols;
+ int *pilen = NULL;
+ char **arg = NULL;
+ char **method = NULL;
+ char **clas = NULL;
+ int length_M = 0;
+
+ // Necessary Output Arguments
+ double *valid_points = NULL;
+ double numBits = 0;
+ double numFeatures = 0;
+ double *featureVector = NULL;
+
+ // Count of various Arguments
+ int count_method=0, count_block=0, count_surf=0, count_upright=0 ,count_metric=0;
+ int count_orient=0, count_scale=0, count_axes=0, count_sign=0, count_class=0;
+
+ // Iterator
+ int i;
+
+ //Input Arguments Parameters
+ double *metric = NULL;
+ double *orient = NULL;
+ double *axes = NULL;
+ double *scale = NULL;
+ double *sign = NULL;
+ double block_size = 0;
+ double upright = 0;
+ double surf_size = 64;
+
+ // Keypoint Vector
+ vector<KeyPoint> keypoints;
+ vector<KeyPoint> copy_k;
+
+ //Image Container
+ Mat image;
+
+ //Output Argument
+ int feature_rows, feature_cols;
+ int valid_rows;
+ double count;
+ double *metric_o = NULL;
+ double *scale_o = NULL;
+ double *orientation_o = NULL;
+ double *axes_o = NULL;
+ double *sign_o = NULL;
+
+ // Checks on Number of Input and Output Arguments
+ CheckInputArgument(pvApiCtx, 4, 22);
+ CheckOutputArgument(pvApiCtx, 2, 9);
+
+ inputArguments = *getNbInputArgument(pvApiCtx);
+
+ //.......................................................................................................................................................................................
+ //Checking for the Presence of Valid Number of Arguments
+ if( inputArguments%2 == 0)
+ {
+
+ //Argument 1 - Image
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isListType(pvApiCtx, piAddr1))
+ {
+ sciErr = getListItemNumber(pvApiCtx, piAddr1, &noItemInList);
+ if( noItemInList != 1)
+ {
+ Scierror(999,"Expecting a grayscale image as first Argument\n");
+ return 0;
+ }
+ retrieveImage(image, 1);
+ }
+ else
+ {
+ if( !isDoubleType(pvApiCtx, piAddr1))
+ {
+ Scierror(999,"Expecting a grayscale Image as first Argument\n");
+ return 0;
+ }
+ retrieveImage(image, 1);
+ }
+
+
+ //..............................................................................................................................................................................
+ //Argument 2 - Location Co-ordinates
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !isVarMatrixType(pvApiCtx, piAddr2))
+ {
+ Scierror(999,"Expecting a Matrix of Mx2 order depicting the Location Coordinates as 2nd Argument.\n");
+ return 0;
+ }
+ //Checking the type of location coordinates
+ if(isDoubleType(pvApiCtx, piAddr2))
+ {
+ //for double location co-ordinates
+ double *points = NULL;
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ length_M = iRows;
+ KeyPoint *X = new KeyPoint;
+ for(int i=0; i<iRows; i++)
+ {
+ X->pt = Point2f(points[i],points[iRows+i]);
+ X->size = 7;
+ keypoints.push_back(*X);
+ copy_k.push_back(*X);
+ }
+ }
+ else if(isIntegerType(pvApiCtx, piAddr2))
+ {
+ sciErr = getMatrixOfIntegerPrecision(pvApiCtx, piAddr2, &iPrec);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ switch(iPrec)
+ {
+ case SCI_UINT8: //for unsigned integer 8 location co-ordinates
+ {
+ unsigned char *points = NULL;
+ sciErr = getMatrixOfUnsignedInteger8(pvApiCtx, piAddr2, &iRows, &iCols, &points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ length_M = iRows;
+ KeyPoint *X = new KeyPoint;
+ for(int i=0; i<iRows; i++)
+ {
+ X->pt = Point2f(points[i],points[iRows+i]);
+ X->size = 7;
+ keypoints.push_back(*X);
+ copy_k.push_back(*X);
+ }
+ break;
+ }
+ case SCI_UINT16: //for unsigned integer 16 location co-ordinates
+ {
+ unsigned short *points = NULL;
+ sciErr = getMatrixOfUnsignedInteger16(pvApiCtx, piAddr2, &iRows, &iCols, &points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ length_M = iRows;
+ KeyPoint *X = new KeyPoint;
+ for(int i=0; i<iRows; i++)
+ {
+ X->pt = Point2f(points[i],points[iRows+i]);
+ X->size = 7;
+ keypoints.push_back(*X);
+ copy_k.push_back(*X);
+ }
+ break;
+ }
+ case SCI_INT32:
+ {
+ int *points = NULL;
+ sciErr = getMatrixOfInteger32(pvApiCtx, piAddr2, &iRows, &iCols, &points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ length_M = iRows;
+ KeyPoint *X = new KeyPoint;
+ for(int i=0; i<iRows; i++)
+ {
+ X->pt = Point2f(points[i],points[iRows+i]);
+ X->size = 7;
+ keypoints.push_back(*X);
+ copy_k.push_back(*X);
+ }
+ break;
+ }
+ }
+ }
+ else
+ {
+ Scierror(999,"Expecting a Double or an Integer Matrix as Location Coordinates in 2nd Argument.\n");
+ return 0;
+ }
+
+
+ //.............................................................................................................................................................................
+ //Argument 3 - Class
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr3))
+ {
+ Scierror(999,"Expecting String Argument \"Class\" as Argument 3.\n");
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &Rows, &Cols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * Rows * Cols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &Rows, &Cols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * Rows * Cols);
+ for(int j=0;j< Rows * Cols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &Rows, &Cols, pilen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(arg);
+ return 0;
+ }
+
+ //Checking Whether Argument 3 is Method or not
+ if(strcmp(arg[0],"Class") == 0)
+ {
+ //If method extracting the Value of the Argument
+ if(count_class != 0)
+ {
+ Scierror(999,"Class Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr4))
+ {
+ Scierror(999, "%s: Wrong type of 2nd argument #%d. A string is expected.\n", fname, 1);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &Rows, &Cols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * Rows * Cols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &Rows, &Cols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ clas = (char**)malloc(sizeof(char*) * Rows * Cols);
+ for(int j=0;j< Rows*Cols; j++)
+ {
+ clas[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &Rows, &Cols, pilen, clas);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(clas);
+ return 0;
+ }
+ count_class += 1;
+ }
+ else
+ {
+ Scierror(999,"Expecting \"Class\" as the 3rd Argument\n");
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999,"Required Arguments are Missing\n");
+ return 0;
+ }
+
+
+
+
+ //..........................................................................................................................................................................................
+ //Getting Optional Input Arguments
+ for( i=5; i<= inputArguments; i++)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr3))
+ {
+ Scierror(999, "%s: Wrong type of argument #%d. A string is expected.\n", fname, 1);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &Rows, &Cols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * Rows * Cols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &Rows, &Cols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * Rows * Cols);
+ for(int j=0;j< Rows * Cols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &Rows, &Cols, pilen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(arg);
+ return 0;
+ }
+
+
+
+ //.................................................................................................................................................................................
+ //Reading the Value of Optional Arguments
+ //If Optional Argument is Method
+ if(strcmp(arg[0],"Method") == 0)
+ {
+ if(count_method!= 0)
+ {
+ Scierror(999,"Method Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr4))
+ {
+ Scierror(999, "%s: Wrong type of 2nd argument #%d. A string is expected.\n", fname, 1);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &Rows, &Cols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * Rows * Cols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &Rows, &Cols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ method = (char**)malloc(sizeof(char*) * Rows * Cols);
+ for(int j=0;j< Rows*Cols; j++)
+ {
+ method[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &Rows, &Cols, pilen, method);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(method);
+ return 0;
+ }
+ i++;
+ count_method += 1;
+ }
+ //.................................................................................................................................................................................
+ //If Optional Argument is Metric
+ else if(strcmp(arg[0],"Metric") == 0)
+ {
+ if(count_metric != 0)
+ {
+ Scierror(999,"Metric Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isVarMatrixType(pvApiCtx, piAddr4))
+ {
+ Scierror(999,"Expecting a Matrix of Mx1 order depicting the Metric Values as Value of Metric Argument.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &metric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( iCols != 1)
+ {
+ Scierror(999,"Expecting a single Column Metric Matrix\n");
+ return 0;
+ }
+ if( iRows != length_M)
+ {
+ Scierror(999,"Expecting a M Row matrix having M number of elements corresponding to M rows of location coordinates\n");
+ return 0;
+ }
+ i++;
+ count_metric += 1;
+ }
+ //.................................................................................................................................................................................
+ //If Optional Argument is BlockSize
+ else if(strcmp(arg[0],"BlockSize") == 0)
+ {
+ if(count_block != 0)
+ {
+ Scierror(999,"BlockSize has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !(isDoubleType(pvApiCtx, piAddr4)) )
+ {
+ Scierror(999,"BlockSize Value should be an odd Integer\n");
+ return 0;
+ }
+ if(getScalarDouble(pvApiCtx, piAddr4, &block_size))
+ {
+ Scierror(999,"Cannot Read Block Size Value");
+ return 0;
+ }
+ if(int(block_size)%2 == 0)
+ {
+ Scierror(999,"Expecting a odd value for Block Size");
+ return 0;
+ }
+ i++;
+ count_block += 1;
+ }
+ //.................................................................................................................................................................................
+ //If Optional Argument is Upright
+ else if(strcmp(arg[0],"Upright") == 0)
+ {
+ if(count_upright != 0)
+ {
+ Scierror(999,"Upright Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !(isDoubleType(pvApiCtx, piAddr4)) )
+ {
+ Scierror(999,"Upright Value must be a logic scalar\n");
+ return 0;
+ }
+ if(getScalarDouble(pvApiCtx, piAddr4, &upright))
+ {
+ Scierror(999,"Cannot Read Upright Value\n");
+ return 0;
+ }
+ i++;
+ count_upright += 1;
+ }
+ //.................................................................................................................................................................................
+ //If Optional Argument is SURFSize
+ else if(strcmp(arg[0],"SURFSize") == 0)
+ {
+ if(count_surf != 0)
+ {
+ Scierror(999,"SURFSize Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !(isDoubleType(pvApiCtx, piAddr4)) )
+ {
+ Scierror(999,"Surf Size Value should be an Integer\n");
+ return 0;
+ }
+ if(getScalarDouble(pvApiCtx, piAddr4, &surf_size))
+ {
+ Scierror(999,"Cannot Read Surf Size Value");
+ return 0;
+ }
+ if( int(surf_size) != 64 && int(surf_size) !=128 )
+ {
+ Scierror(999,"Expecting value 64 or 128 for Surf Size\n");
+ return 0;
+ }
+ i++;
+ count_surf += 1;
+ }
+ //.................................................................................................................................................................................
+ //If Optional Argument is Orientation
+ else if(strcmp(arg[0],"Orientation") == 0)
+ {
+ if(count_orient != 0)
+ {
+ Scierror(999,"Orientation Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isVarMatrixType(pvApiCtx, piAddr4))
+ {
+ Scierror(999,"Expecting a Matrix of Mx1 order depicting the Orientation Values as Value of Orientation Argument.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &orient);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( iCols != 1)
+ {
+ Scierror(999,"Expecting a single Column Orientation Matrix\n");
+ return 0;
+ }
+ if( iRows != length_M)
+ {
+ Scierror(999,"Expecting a M Row matrix having M number of elements corresponding to M rows of location coordinates\n");
+ return 0;
+ }
+ i++;
+ count_orient += 1;
+ }
+ //.................................................................................................................................................................................
+ //If Optional Argument is Axes
+ else if(strcmp(arg[0],"Axes") == 0)
+ {
+ if(count_axes != 0)
+ {
+ Scierror(999,"Axes Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isVarMatrixType(pvApiCtx, piAddr4))
+ {
+ Scierror(999,"Expecting a Matrix of Mx2 order depicting the Axes as Value of Axes Argument.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &axes);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( iCols != 2)
+ {
+ Scierror(999,"Expecting a 2 Column Axes Matrix\n");
+ return 0;
+ }
+ if( iRows != length_M)
+ {
+ Scierror(999,"Expecting a M Row matrix having M number of elements corresponding to M rows of location coordinates\n");
+ return 0;
+ }
+ i++;
+ count_axes += 1;
+ }
+ //................................................................................................................................................................................
+ //If Optional Argument is Scale
+ else if(strcmp(arg[0],"Scale") == 0)
+ {
+ if(count_scale != 0)
+ {
+ Scierror(999,"Scale Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isVarMatrixType(pvApiCtx, piAddr4))
+ {
+ Scierror(999,"Expecting a Matrix of Mx1 order depicting the Scale as Value of Scale Argument.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &scale);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( iCols != 1)
+ {
+ Scierror(999,"Expecting a single Column Scale Matrix\n");
+ return 0;
+ }
+ if( iRows != length_M)
+ {
+ Scierror(999,"Expecting a M Row matrix having M number of elements corresponding to M rows of location coordinates\n");
+ return 0;
+ }
+ i++;
+ count_scale += 1;
+ }
+ //................................................................................................................................................................................
+ //If Optional Argument is SignOfLaplacian
+ else if(strcmp(arg[0],"SignOfLaplacian") == 0)
+ {
+ if(count_sign != 0)
+ {
+ Scierror(999,"SignOfLaplacian Argument has been called twice\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isVarMatrixType(pvApiCtx, piAddr4))
+ {
+ Scierror(999,"Expecting a Matrix of Mx1 order depicting the Sign Of Laplacian as Value of SignOfLaplacian Argument.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &sign);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( iCols != 1)
+ {
+ Scierror(999,"Expecting a single Column Axes Matrix\n");
+ return 0;
+ }
+ if( iRows != length_M)
+ {
+ Scierror(999,"Expecting a M Row matrix having M number of elements corresponding to M rows of location coordinates\n");
+ return 0;
+ }
+ i++;
+ count_sign += 1;
+ //Check for Validity of Laplacian Matrix
+ for(int i=0; i<iRows; i++)
+ {
+ if( !(sign[i]==0 || sign[i]==1 || sign[i]==-1))
+ {
+ Scierror(999,"SignOfLaplacian Matrix should contain only 0,1 or -1 as its elements.\n");
+ return 0;
+ }
+ }
+ }
+ else
+ {
+ Scierror(999, "Invalid Argument Name. Provide Valid Arguments\n");
+ return 0;
+ }
+ }
+
+
+ //Reading Part Completed
+ //.........................................................................................................................................................................................
+ //.........................................................................................................................................................................................
+ //Checking for Presence of All necessary Arguments for the computation of specified Method
+ if(strcmp(clas[0], "cornerPoints") == 0)
+ {
+ if(count_metric==0)
+ {
+ Scierror(999,"For cornerPoints Object \"Metric\" Matrix is necessary.\n");
+ return 0;
+ }
+ if(count_method==0)
+ {
+ method = (char**)malloc(sizeof(char*) * 1 * 1);
+ method[0] = (char*)malloc(sizeof(char) * 6);
+ strcpy(method[0],"FREAK");
+ }
+ for( i=0; i<keypoints.size(); i++)
+ {
+ keypoints[i].response = metric[i];
+ }
+ }
+ else if(strcmp(clas[0], "BRISKPoints") == 0)
+ {
+ if(count_metric==0 || count_scale==0 || count_orient==0)
+ {
+ Scierror(999,"For BRISKPoints Object \"Metric\" Matrix, \"Orientation\" Matrix and \"Scale\" Matrix are necessary\n");
+ return 0;
+ }
+ if(count_method==0)
+ {
+ method = (char**)malloc(sizeof(char*) * 1 * 1);
+ method[0] = (char*)malloc(sizeof(char) * 6);
+ strcpy(method[0],"FREAK");
+ }
+ for( i=0; i<keypoints.size(); i++)
+ {
+ keypoints[i].response = metric[i];
+ keypoints[i].angle = orient[i];
+ }
+ }
+ else if(strcmp(clas[0], "MSERRegions") == 0)
+ {
+ if(count_orient==0 || count_axes==0)
+ {
+ Scierror(999,"For MSERRegions \"Orientation\" Matrix and \"Axes\" Matrix re necessary.\n");
+ return 0;
+ }
+ if(count_method==0)
+ {
+ method = (char**)malloc(sizeof(char*) * 1 * 1);
+ method[0] = (char*)malloc(sizeof(char) * 5);
+ strcpy(method[0],"SURF");
+ }
+ for( i=0; i<keypoints.size(); i++)
+ {
+ keypoints[i].angle = orient[i];
+ }
+ }
+ else if(strcmp(clas[0], "SURFPoints") == 0)
+ {
+ if(count_scale==0 || count_metric==0 || count_sign==0 || count_orient==0 )
+ {
+ Scierror(999,"For SURFPoints Object \"Metric\" Matrix \"Orientation\" Matrix \"Scale\" Matrix and \"SignOfLaplacian\" Matrix is necessary.\n");
+ return 0;
+ }
+ if(count_method==0)
+ {
+ method = (char**)malloc(sizeof(char*) * 1 * 1);
+ method[0] = (char*)malloc(sizeof(char) * 5);
+ strcpy(method[0],"SURF");
+ }
+ for( i=0; i<keypoints.size(); i++)
+ {
+ keypoints[i].response = metric[i];
+ keypoints[i].angle = orient[i];
+ }
+ }
+ else if(strcmp(clas[0], "Matrix") == 0)
+ {
+ if(count_block==0)
+ {
+ Scierror(999,"For Matirx Object \"BlockSize\" argument is necessary.\n");
+ return 0;
+ }
+ if(count_method==0)
+ {
+ method = (char**)malloc(sizeof(char*) * 1 * 1);
+ method[0] = (char*)malloc(sizeof(char) * 6);
+ strcpy(method[0],"Block");
+ }
+ }
+ else
+ {
+ Scierror(999,"Provide a Valid Class object\n");
+ return 0;
+ }
+
+
+
+
+ //All Input Checks has been completed.
+ //.........................................................................................................................................................................................
+ //Processing....
+
+ Mat descriptor;
+
+
+ //FREAK
+ if(strcmp(method[0], "FREAK")==0)
+ {
+ FREAK obj( int(upright), 1, 22.0f, 4 );
+
+ obj.compute(image, keypoints, descriptor);
+ numBits = descriptor.size[1];
+ numFeatures = descriptor.size[0];
+
+ valid_points = (double *)malloc(sizeof(double) * keypoints.size() * 2);
+
+ for( int i=0; i<keypoints.size(); i++)
+ {
+ valid_points[i] = keypoints[i].pt.x;
+ valid_points[keypoints.size() + i] = keypoints[i].pt.y;
+ }
+
+ featureVector = (double*)malloc(sizeof(double)*descriptor.size[0]*descriptor.size[1]);
+ for( int i=0; i<descriptor.size[0]; i++)
+ for( int j=0; j<descriptor.size[1]; j++)
+ {
+ *(featureVector + j*descriptor.size[0] + i) = int( descriptor.at<uchar>(i,j));
+ }
+ feature_rows = descriptor.size[0];
+ feature_cols = descriptor.size[1];
+ valid_rows = descriptor.size[0];
+ count = descriptor.size[0];
+
+ if( strcmp(clas[0],"cornerPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ else if(strcmp(clas[0],"BRISKPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"MSERRegions") == 0)
+ {
+ axes_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ axes_o[iterator] = axes[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"SURFPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+
+ sign_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ sign_o[iterator] = sign[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ }
+
+ //..........................................................................................................................................................................................
+ //SURF
+ else if(strcmp(method[0], "SURF")==0)
+ {
+ SURF obj;
+ if( int(upright) == 1)
+ {
+ if( int(surf_size) == 64)
+ obj = SURF(100, 4, 3, 0, 1);
+ else if ( int(surf_size) == 128)
+ obj = SURF(100, 4, 3, 1, 1);
+ }
+ else if( int(upright) == 0)
+ {
+ if( int(surf_size) == 64)
+ obj = SURF(100, 4, 3, 0, 0);
+ else if ( int(surf_size) == 128)
+ obj = SURF(100, 4, 3, 1, 0);
+ }
+
+ obj.compute(image, keypoints, descriptor);
+ numBits = descriptor.size[1];
+ numFeatures = descriptor.size[0];
+
+ valid_points = (double *)malloc(sizeof(double) * keypoints.size() * 2);
+
+ for( int i=0; i<keypoints.size(); i++)
+ {
+ valid_points[i] = keypoints[i].pt.x;
+ valid_points[keypoints.size() + i] = keypoints[i].pt.y;
+ }
+
+ featureVector = (double*)malloc(sizeof(double)*descriptor.size[0]*descriptor.size[1]);
+ for( int i=0; i<descriptor.size[0]; i++)
+ for( int j=0; j<descriptor.size[1]; j++)
+ {
+ *(featureVector + j*descriptor.size[0] + i) = int( descriptor.at<uchar>(i,j));
+ }
+ feature_rows = descriptor.size[0];
+ feature_cols = descriptor.size[1];
+ valid_rows = descriptor.size[0];
+ count = descriptor.size[0];
+
+ if( strcmp(clas[0],"cornerPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ else if(strcmp(clas[0],"BRISKPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"MSERRegions") == 0)
+ {
+ axes_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ axes_o[iterator] = axes[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"SURFPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+
+ sign_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ sign_o[iterator] = sign[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ }
+
+ //.........................................................................................................................................................................................
+ //BRISK
+ else if(strcmp(method[0], "BRISK")==0)
+ {
+ BRISK obj;
+
+ obj.compute(image, keypoints, descriptor);
+ numBits = descriptor.size[1];
+ numFeatures = descriptor.size[0];
+
+ valid_points = (double *)malloc(sizeof(double) * keypoints.size() * 2);
+
+ for( int i=0; i<keypoints.size(); i++)
+ {
+ valid_points[i] = keypoints[i].pt.x;
+ valid_points[keypoints.size() + i] = keypoints[i].pt.y;
+ }
+
+ featureVector = (double*)malloc(sizeof(double)*descriptor.size[0]*descriptor.size[1]);
+ for( int i=0; i<descriptor.size[0]; i++)
+ for( int j=0; j<descriptor.size[1]; j++)
+ {
+ *(featureVector + j*descriptor.size[0] + i) = int( descriptor.at<uchar>(i,j));
+ }
+ feature_rows = descriptor.size[0];
+ feature_cols = descriptor.size[1];
+ valid_rows = descriptor.size[0];
+ count = descriptor.size[0];
+
+ if( strcmp(clas[0],"cornerPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ else if(strcmp(clas[0],"BRISKPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"MSERRegions") == 0)
+ {
+ axes_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ axes_o[iterator] = axes[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"SURFPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+
+ sign_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ sign_o[iterator] = sign[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ }
+
+ //.........................................................................................................................................................................................
+ //Block
+ else if(strcmp(method[0], "Block")==0)
+ {
+ vector <KeyPoint> valid;
+ for( i=0; i<keypoints.size(); i++)
+ {
+ if( keypoints[i].pt.x - (block_size-1)/2 < 0 || keypoints[i].pt.y - (block_size-1)/2 < 0)
+ continue;
+ if( keypoints[i].pt.x + (block_size-1)/2 > image.cols || keypoints[i].pt.y + (block_size-1)/2 > image.rows)
+ continue;
+ valid.push_back(keypoints[i]);
+ }
+ valid_points = (double *)malloc(sizeof(double)*valid.size()*2);
+ featureVector = (double *)malloc(sizeof(double)*valid.size()*int(block_size)*int(block_size));
+ for( int i=0; i<valid.size(); i++)
+ {
+ int iterator = 0;
+ valid_points[i] = valid[i].pt.x;
+ valid_points[valid.size() + i] = valid[i].pt.y;
+ for( int j=int(valid[i].pt.x-(int(block_size/2))); j<=int(valid[i].pt.x+(int(block_size/2))); j++)
+ for( int k=int(valid[i].pt.y-(int(block_size/2))); k<=int(valid[i].pt.y+(int(block_size/2))); k++)
+ {
+ *(featureVector + i*int(block_size)*int(block_size) + iterator) = image.at<uchar>(j,k);
+ iterator = iterator+1;
+ }
+ }
+ feature_rows = valid.size();
+ feature_cols = int(block_size)*int(block_size);
+ valid_rows = valid.size();
+ numFeatures = valid.size();
+ numBits = int(block_size)*int(block_size);
+ count = valid.size();
+
+ if( strcmp(clas[0],"cornerPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == valid[iterator].pt.x && copy_k[i].pt.y == valid[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ else if(strcmp(clas[0],"BRISKPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"MSERRegions") == 0)
+ {
+ axes_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ axes_o[iterator] = axes[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+ }
+ else if(strcmp(clas[0],"SURFPoints") == 0)
+ {
+ metric_o = (double*)malloc(sizeof(double) * valid_rows);
+ int iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ metric_o[iterator] = metric[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ scale_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ scale_o[iterator] = scale[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+
+ orientation_o = (double*)malloc(sizeof(double) * valid_rows);
+ for(int i=0; i<valid_rows; i++)
+ {
+ orientation_o[i] = (keypoints[i].angle * 3.14)/180 ;
+ }
+
+ sign_o = (double*)malloc(sizeof(double) * valid_rows);
+ iterator = 0;
+ for(int i=0; i<copy_k.size(); i++)
+ {
+ if( copy_k[i].pt.x == keypoints[iterator].pt.x && copy_k[i].pt.y == keypoints[iterator].pt.y )
+ {
+ sign_o[iterator] = sign[i];
+ iterator++;
+ }
+ if(iterator == keypoints.size())
+ break;
+ }
+ }
+ }
+ else
+ {
+ Scierror(999,"Input a valid method\n");
+ return 0;
+ }
+
+
+
+ //.........................................................................................................................................................................................
+ //Output Arguments
+ out_params = *getNbOutputArgument(pvApiCtx);
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, feature_rows, feature_cols, featureVector);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, valid_rows, 2, valid_points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 3, 1, 1, &numBits);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 4, 1, 1, &numFeatures);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
+ AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
+
+ if(strcmp(clas[0],"cornerPoints") == 0)
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, 1, 1, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 6, valid_rows, 1, metric_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
+ }
+ else if(strcmp(clas[0],"BRISKPoints") == 0)
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, valid_rows, 1, scale_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 6, valid_rows, 1, metric_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 7, valid_rows, 1, orientation_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 7) = nbInputArgument(pvApiCtx) + 7;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 8, 1, 1, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 8) = nbInputArgument(pvApiCtx) + 8;
+ }
+ else if(strcmp(clas[0],"MSERRegions") == 0)
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, 1, 1, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 6, valid_rows, 1, axes_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 7, valid_rows, 1, orientation_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 7) = nbInputArgument(pvApiCtx) + 7;
+ }
+ else if(strcmp(clas[0],"SURFPoints") == 0)
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 5, 1, 1, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 6, valid_rows, 1, scale_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 6) = nbInputArgument(pvApiCtx) + 6;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 7, valid_rows, 1, metric_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 7) = nbInputArgument(pvApiCtx) + 7;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 8, valid_rows, 1, sign_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 8) = nbInputArgument(pvApiCtx) + 8;
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 9, valid_rows, 1, orientation_o);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 9) = nbInputArgument(pvApiCtx) + 9;
+ }
+
+ free(valid_points);
+ free(featureVector);
+
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_extractHOGFeatures.cpp b/sci_gateway1/cpp/opencv_extractHOGFeatures.cpp
new file mode 100644
index 0000000..ad22814
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_extractHOGFeatures.cpp
@@ -0,0 +1,399 @@
+/*******************************************************************************************************************
+ Author : Kevin George
+
+-> Syntax- extractHOGFeatures("cellsize",..., "BlockSize",...,
+ "BlockOverlap",..., "NumBins",...)
+
+-> NumBins is strictly of integer type
+********************************************************************************************************************/
+#include <numeric>
+#include <string.h>
+#include <math.h>
+#include <iostream>
+#include <bits/stdc++.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include <opencv2/objdetect/objdetect.hpp>
+
+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_extractHOGFeatures(char *fname, unsigned long fname_len)
+ {
+
+ //Error variables
+ SciErr sciErr;
+ int intErr = 0;
+
+ //-> Mat containers for images
+ Mat img;
+ Mat img_gray;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+ //int *piAddr2 = NULL;
+
+ //-> Local variables
+ int num_InputArgs; //-> gives total number of arguments
+ int iRows, iCols;
+ int featureVector_size;
+ int *piLen = NULL;
+ char **pstData = NULL; //-> why double pointer?? and what is it
+ char *currentArg = NULL; //-> Stores current string representing 'name' of name,value pair arguments
+ bool *providedArgs = NULL; //-> Used to check that optional argument is not entered more than once
+ double *featureVector;
+ //-> Name,Value pair variables
+ double *CellSize = NULL; //->
+ double *BlockSize = NULL; //->
+ double *BlockOverlap = NULL; //->
+ /*Size CellSize ; //->
+ Size BlockSize ; //->
+ Size BlockOverlap ; //-> */
+
+ int NumBins = 9; //-> In docs, it must be int type
+ //vector< int> CellSize; CellSize.push_back(8); CellSize.push_back(8);
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ //-> Checks number of input and output arguments
+ CheckInputArgument(pvApiCtx, 1, 5);
+ CheckOutputArgument(pvApiCtx, 1, 5);
+
+ //-> Read Image
+ retrieveImage( img, 1);
+
+ //-> Count number of input arguments
+ num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ providedArgs = (bool*) malloc(sizeof(bool) * 5);
+
+ //-> Based on number of input arguments
+
+//************************************************************ Optional Input Arguments *************************************************
+ vector<KeyPoint> Points;
+
+//************************************************ Retrieval of Name, Value Argument Pair *************************************************
+ for(int iter = 2; iter<= num_InputArgs; iter++)
+ {
+ //-> Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Extracting name of next argument takes three calls to getMatrixOfString
+ //-> First call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ //-> Third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+//****************************************************** Name,Value - Cellsize *****************************************************************
+ if(strcmp(currentArg, "CellSize")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &CellSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows*iCols!=2)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if(CellSize[0]<0 || CellSize[1]<0)
+ {
+ sciprint("Arguments cannot be negative\n");
+ return 0;
+ }
+
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+//************************************** Name,Value - BlockSize ************************************
+ else if(strcmp(currentArg, "BlockSize")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &BlockSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows*iCols!=2)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if(BlockSize[0]<0 || BlockSize[1]<0)
+ {
+ sciprint("Arguments cannot be negative\n");
+ return 0;
+ }
+
+ providedArgs[1] = 1;
+ }
+ else if(providedArgs[1]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+ }
+
+
+//********************************************* Name,Value - BlockOverlap ************************************************
+ else if(strcmp(currentArg, "BlockOverlap")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &BlockOverlap);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows*iCols!=2)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if(BlockOverlap[0]<0 || BlockOverlap[1]<0)
+ {
+ sciprint("Arguments cannot be negative\n");
+ return 0;
+ }
+
+ providedArgs[2] = 1;
+ }
+
+ else if(providedArgs[2]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+
+ }
+//*********************************************** *********** Name,Value - NumBins **********************************************************************
+ else if(strcmp(currentArg, "NumBins")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &NumBins);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if( NumBins<= 0)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values must be more than zero.\n", currentArg);
+ return 0;
+ }
+ providedArgs[3] = 1;
+ }
+
+ else if(providedArgs[3])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ else
+ {
+ Scierror(999, "Incorrect Name type. Please re-enter the correct Name-Value pair arguments\n");
+ return 0;
+ }
+
+ }//-> Brace for closing for loop
+
+//******************************************************** Giving Default Arguments *******************************************************************
+
+ if(providedArgs[0] == 0)
+ {
+ CellSize = (double*) malloc(sizeof(double)*2);
+ CellSize[0] = 8;
+ CellSize[1] = 8;
+ }
+
+
+ if(providedArgs[1] == 0)
+ {
+ BlockSize = (double*) malloc(sizeof(double)*2);
+ BlockSize[0] = 16;
+ BlockSize[1] = 16;
+ }
+
+ if(providedArgs[2] == 0)
+ {
+ BlockOverlap = (double*) malloc(sizeof(double)*2);
+ BlockOverlap[0] = 8;
+ BlockOverlap[1] = 8;
+ }
+
+ if(providedArgs[3] == 0)
+ {
+ NumBins = 9;
+ }
+
+//**************************************************************Actual Processing*******************************************************************************
+
+ //-> resizing
+ //resize(img, img, Size(64,48) );
+ resize(img, img, Size(64,128) );
+
+ //-> Convert to grayscale(Necessary Step)
+ cvtColor(img, img_gray, CV_RGB2GRAY);
+
+ //-> CellSize (8,8) is only supported size
+ // in opencv 2.4.9
+ //HOGDescriptor d( Size(64,128), Size(16,16), Size(8,8), Size(8,8), 9);
+ HOGDescriptor d(Size(64,128), Size(BlockSize[0],BlockSize[1]), Size(BlockOverlap[0],BlockOverlap[1]),Size(CellSize[0],CellSize[1]), NumBins);
+ //-> This is our descriptor vector
+
+ vector<float> descriptorsValues;
+ vector< Point> locations ;
+ d.compute( img_gray, descriptorsValues, Size(32,32), Size(0,0), locations);
+
+ //-> Displaying feature vector size
+ //sciprint("%d\n",descriptorsValues.size());
+ //for(int i =0; i<descriptorsValues.size();i++)
+ // sciprint("%f\t", descriptorsValues[i]);
+ //cout<< descriptorsValues[i]<< "\t";*/
+ //sciprint("%d\n",locations.size());
+
+ featureVector_size = descriptorsValues.size();
+ featureVector = (double*) malloc(sizeof(double)*featureVector_size); //doesn't have floating point
+ for(int i=0; i<featureVector_size; i++)
+ {
+ featureVector[i] = descriptorsValues[i];
+ }
+//************************************************************ Output **************************************************************************
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx)+1, featureVector_size, 1, featureVector);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Returning Output
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_extractLBPFeatures.cpp b/sci_gateway1/cpp/opencv_extractLBPFeatures.cpp
new file mode 100644
index 0000000..291f6bb
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_extractLBPFeatures.cpp
@@ -0,0 +1,515 @@
+/***************************************************
+Author : Tanmay Chaudhari
+
+TO DO:
+1) nearest neighbor interpolation
+2) upright parameter implementation
+ ***************************************************/
+
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include <bits/stdc++.h>
+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"
+//#include "../common.cpp"
+
+ void ELBP(const Mat& src, Mat& dst, int radius, int neighbors)
+ {
+ neighbors = max(min(neighbors,31),1); // set bounds...
+ // Note: alternatively you can switch to the new OpenCV Mat_
+ // type system to define an unsigned int matrix... I am probably
+ // mistaken here, but I didn't see an unsigned int representation
+ // in OpenCV's classic typesystem...
+ dst = Mat::zeros(src.rows-2*radius, src.cols-2*radius, CV_32SC1);
+ for(int n=0; n<neighbors; n++)
+ {
+ // sample points
+ float x = static_cast<float>(radius) * cos(2.0*M_PI*n/static_cast<float>(neighbors));
+ float y = static_cast<float>(radius) * -sin(2.0*M_PI*n/static_cast<float>(neighbors));
+ // relative indices
+ int fx = static_cast<int>(floor(x));
+ int fy = static_cast<int>(floor(y));
+ int cx = static_cast<int>(ceil(x));
+ int cy = static_cast<int>(ceil(y));
+ // fractional part
+ float ty = y - fy;
+ float tx = x - fx;
+ // set interpolation weights
+ float w1 = (1 - tx) * (1 - ty);
+ float w2 = tx * (1 - ty);
+ float w3 = (1 - tx) * ty;
+ float w4 = tx * ty;
+ // iterate through your data
+ for(int i=radius; i < src.rows-radius;i++)
+ {
+ for(int j=radius;j < src.cols-radius;j++)
+ {
+ float t = w1*src.at<float>(i+fy,j+fx) + w2*src.at<float>(i+fy,j+cx) + w3*src.at<float>(i+cy,j+fx) + w4*src.at<float>(i+cy,j+cx);
+ // we are dealing with floating point precision, so add some little tolerance
+ dst.at<unsigned int>(i-radius,j-radius) += ((t > src.at<float>(i,j)) && (abs(t-src.at<float>(i,j)) > std::numeric_limits<float>::epsilon())) << n;
+ }
+ }
+ }
+ }
+
+ /*void ELBP(const Mat& src, Mat& dst, int radius, int neighbors)
+ {
+ switch(src.type()) {
+ case CV_8SC1: ELBP_<char>(src, dst, radius, neighbors); break;
+ case CV_8UC1: ELBP_<unsigned char>(src, dst, radius, neighbors); break;
+ case CV_16SC1: ELBP_<short>(src, dst, radius, neighbors); break;
+ case CV_16UC1: ELBP_<unsigned short>(src, dst, radius, neighbors); break;
+ case CV_32SC1: ELBP_<int>(src, dst, radius, neighbors); break;
+ case CV_32FC1: ELBP_<float>(src, dst, radius, neighbors); break;
+ case CV_64FC1: ELBP_<double>(src, dst, radius, neighbors); break;
+ }
+ }*/
+
+ static Mat histc_(const Mat& src, int minVal=0, int maxVal=255, bool normed=false)
+ {
+ Mat result;
+ // Establish the number of bins.
+ int histSize = maxVal-minVal+1;
+ // Set the ranges.
+ float range[] = { static_cast<float>(minVal), static_cast<float>(maxVal+1) };
+ const float* histRange = { range };
+ // calc histogram
+ calcHist(&src, 1, 0, Mat(), result, 1, &histSize, &histRange, true, false);
+ // normalize
+ if(normed) {
+ result /= (int)src.total();
+ }
+ return result.reshape(1,1);
+ }
+
+ static Mat histc(InputArray _src, int minVal, int maxVal, bool normed)
+ {
+ Mat src = _src.getMat();
+ switch (src.type()) {
+ case CV_8SC1:
+ return histc_(Mat_<float>(src), minVal, maxVal, normed);
+ break;
+ case CV_8UC1:
+ return histc_(src, minVal, maxVal, normed);
+ break;
+ case CV_16SC1:
+ return histc_(Mat_<float>(src), minVal, maxVal, normed);
+ break;
+ case CV_16UC1:
+ return histc_(src, minVal, maxVal, normed);
+ break;
+ case CV_32SC1:
+ return histc_(Mat_<float>(src), minVal, maxVal, normed);
+ break;
+ case CV_32FC1:
+ return histc_(src, minVal, maxVal, normed);
+ break;
+ }
+ return Mat();
+ }
+
+
+ static Mat spatial_histogram(InputArray _src, int numPatterns, int grid_x, int grid_y, bool normed)
+ {
+ Mat src = _src.getMat();
+ // calculate LBP patch size
+ //int width = src.cols/grid_x;
+ //int height = src.rows/grid_y;
+ int width = grid_x;
+ int height = grid_y;
+
+ // allocate memory for the spatial histogram
+ Mat result = Mat::zeros(grid_x * grid_y, numPatterns, CV_32FC1);
+ // return matrix with zeros if no data was given
+ if(src.empty())
+ return result.reshape(1,1);
+ // initial result_row
+ int resultRowIdx = 0;
+ // iterate through grid
+ for(int i = 0; i < grid_y; i++) {
+ for(int j = 0; j < grid_x; j++) {
+ Mat src_cell = Mat(src, Range(i*height,(i+1)*height), Range(j*width,(j+1)*width));
+ Mat cell_hist = histc(src_cell, 0, (numPatterns-1), normed);
+ // copy to the result matrix
+ Mat result_row = result.row(resultRowIdx);
+ cell_hist.reshape(1,1).convertTo(result_row, CV_32FC1);
+ // increase row count in result matrix
+ resultRowIdx++;
+ }
+ }
+ // return result as reshaped feature vector
+ return result.reshape(1,1);
+ }
+
+ int opencv_extractLBPFeatures(char *fname, unsigned long fname_len)
+ {
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int iRows = 0;
+ int iCols = 0;
+ int intErr = 0;
+ int nbInputArguments = 0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ bool *providedArgs = NULL;
+ bool linearInterpolation = 1;
+ bool normalization = 1;
+ char *currentArg = NULL;
+ char **pstData = NULL;
+ double radius = 1;
+ double upright = 1;
+ double neighbors = 8;
+ double *cellSize = NULL;
+ double *outputHist = NULL;
+ Mat image;
+ Mat grayscaleImage;
+ Mat lbpImage;
+ Mat spatialHistogram;
+
+ //Check input output arguments
+ CheckInputArgument(pvApiCtx, 1, 13);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ if((nbInputArguments-1)%2!=0)
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+ providedArgs = (bool*)malloc(sizeof(bool) * 6);
+ for(int i=0;i<6;i++)
+ providedArgs[i] = 0;
+
+ //getting input arguments
+ retrieveImage(image, 1);
+ cellSize = (double*)malloc(sizeof(double) * 2);
+
+ for(int iter=2;iter<=nbInputArguments;iter++)
+ {
+ // Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ // providedArgs[] makes sure that no optional argument is provided more than once
+
+ if(strcmp(currentArg, "NumNeighbors")==0)
+ {
+ if(!providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr, &neighbors);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(neighbors < 4 || neighbors > 24)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible range is [4, 24].\n", currentArg);
+ return 0;
+ }
+ providedArgs[0] = 1;
+
+ }
+ else if(providedArgs[0])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "Radius")==0)
+ {
+ if(!providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr, &radius);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(radius < 1 || radius > 5)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible range is [1, 5].\n", currentArg);
+ return 0;
+ }
+ providedArgs[1] = 1;
+ }
+ else if(providedArgs[1])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "Upright")==0)
+ {
+ if(!providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr, &upright);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(upright!=0.0 && upright!=1.0)
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are 0 or 1.\n", currentArg);
+ return 0;
+ }
+ providedArgs[2] = 1;
+ }
+ else if(providedArgs[2])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "Interpolation")==0)
+ {
+ if(!providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp(pstData[0],"Mean square error")==0)
+ linearInterpolation=1;
+ else if(strcmp(pstData[0], "Nearest")==0)
+ linearInterpolation=0;
+ else
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are Linear or Nearest.\n", currentArg);
+ return 0;
+ }
+ providedArgs[3]=1;
+ }
+ else if(providedArgs[3])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "CellSize")==0)
+ {
+ if(!providedArgs[4])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999, "%s: Wrong type for input argument #%d: A real matrix expected.\n", fname, iter);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &cellSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows!=1 || iCols!=2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument CellSize.\n");
+ return 0;
+ }
+ providedArgs[4]=1;
+ }
+ else if(providedArgs[4])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "Normalization")==0)
+ {
+ if(!providedArgs[5])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp(pstData[0],"L2")==0)
+ normalization=1;
+ else if(strcmp(pstData[0], "None")==0)
+ normalization=0;
+ else
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are L2 or None.\n", currentArg);
+ return 0;
+ }
+ providedArgs[5]=1;
+ }
+ else if(providedArgs[5])
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ }
+ }
+ //onvert RGB image to gray
+ cvtColor(image, grayscaleImage, CV_BGR2GRAY);
+ ELBP(grayscaleImage, lbpImage, radius, neighbors);
+
+ if(!providedArgs[4])
+ {
+ cellSize[0] = lbpImage.cols;
+ cellSize[1] = lbpImage.rows;
+ }
+
+ //calculate the spatial histogram
+ spatialHistogram = spatial_histogram(lbpImage, static_cast<int>(pow(2.0, static_cast<double>(neighbors))), int(cellSize[0]), int(cellSize[1]), normalization);
+
+ outputHist = (double*)malloc(sizeof(double) * spatialHistogram.cols);
+ for(int i=0;i<spatialHistogram.cols;i++)
+ outputHist[i] = spatialHistogram.at<double>(0,i);
+
+ //create output argument
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx)+1, 1, spatialHistogram.cols, outputHist);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //return output Arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_fillconvexpoly.cpp b/sci_gateway1/cpp/opencv_fillconvexpoly.cpp
new file mode 100644
index 0000000..1ce29c6
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_fillconvexpoly.cpp
@@ -0,0 +1,173 @@
+/*************************************************
+Authors : Abhilasha Sancheti & Sukul Bagai
+**************************************************
+ sample inputs : b=fillconvexpoly(a,points,4,0,0,0,8,0); (points: [0 0;0 100;100 0; 100 100])
+ fillConvexpoly( image , points , r_value , g_value , b_value , linrtype,shift);
+*************************************************/
+
+#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_fillconvexpoly(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int i,j,k ;
+ double *pstData = NULL;
+ double npts ,r_value,g_value ,b_value ,linetype=8 ,shift=0;
+
+
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 8, 8);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+//retreive the value of clockwise parameter
+ Mat image;
+ retrieveImage(image,1);
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+///// store values in a contour
+
+ Point *pts = (Point *)malloc(iRows * 2 * sizeof(double));
+ for ( i = 0 ; i < iRows ; i++)
+ {
+ pts[i].x = *(pstData + i);
+ pts[i].y = *(pstData + 1*iRows + i);
+ }
+
+ /// to retrieve the number of points
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &npts);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+//// to retreive the value of r_value
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &r_value);
+ if(intErr)
+ {
+ return intErr;
+ }
+ /// to retreive the value of g_value
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &g_value);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ /// to retreive the value of b_value
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &b_value);
+ if(intErr)
+ {
+ return intErr;
+ }
+ /// to retreive the value of linetype
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7, &linetype);
+ if(intErr)
+ {
+ return intErr;
+ }
+/// to retreive the value of shift
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr8, &shift);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+
+ // call the fillconvexpoly function of opencv
+ fillConvexPoly(image,pts,npts,Scalar(r_value,g_value,b_value),linetype,shift);
+
+ //temp variable was not needed, hence has been discarded
+ string tempstring = type2str(image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,image,1); //here, remove the temp as a parameter as it is not needed, and instead add 1 as the third parameter. 1 denotes that the first output argument will be this variable
+ free(checker); //free memory taken up by checker
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_filter2D.cpp b/sci_gateway1/cpp/opencv_filter2D.cpp
new file mode 100644
index 0000000..650771b
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_filter2D.cpp
@@ -0,0 +1,184 @@
+/***************************************************
+Author : Sukul Bagai
+****************************************************
+Usage : return_image = filter2D(input_image,"<ddepth>",kernel_matrix,anchor_x,anchor_y,delta);
+***************************************************/
+
+#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_filter2D(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ char **ddepth = NULL;
+ int i,j,k;
+ double *kernel,anchorX,anchorY,delta;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 6, 6);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for ddepth
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ddepth = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ ddepth[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, ddepth);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for kernel matrix
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols ,&kernel);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ int n=iRows;
+ double kernelArray[n][n];
+ //assigning values to actual kernelMatrix
+ for(i=0;i<n;i++)
+ for(j=0;j<n;j++)
+ kernelArray[i][j]=kernel[(i*n)+j];
+ // converting the array to a matrix, so that we can pass it into the filter2D function
+ Mat kernelMatrix(n, n, CV_32FC1, &kernelArray);
+
+ //for value of anchorX
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &anchorX);
+ if(intErr)
+ return intErr;
+
+ //for value of anchorY
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &anchorY);
+ if(intErr)
+ return intErr;
+
+ //for value of delta
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &delta);
+ if(intErr)
+ return intErr;
+
+ //error check
+ if(anchorX >= n || anchorY >=n)
+ {
+ sciprint("Invalid anchor point given. Centre point (-1,-1) was used instead");
+ anchorY = -1;
+ anchorX = -1;
+ }
+ Mat new_image(image.rows,image.cols,image.type());
+ Point pt(anchorX,anchorY);
+
+ int actualddepth;
+
+ if(strcmp(ddepth[0],"CV_8U")==0)
+ actualddepth=CV_8U;
+ else if(strcmp(ddepth[0],"CV_16U")==0)
+ actualddepth=CV_16U;
+ else if(strcmp(ddepth[0],"CV_16S")==0)
+ actualddepth=CV_16S;
+ else if(strcmp(ddepth[0],"CV_32F")==0)
+ actualddepth=CV_32F;
+ else if(strcmp(ddepth[0],"CV_64F")==0)
+ actualddepth=CV_64F;
+ else
+ {
+ sciprint("Invalid type %s used. CV_8U was used instead by default",ddepth[0]);
+ actualddepth = CV_8U;
+ }
+
+ //applying function
+ filter2D(image,new_image,actualddepth,kernelMatrix,pt,delta);
+
+ //returning image
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_findContours.cpp b/sci_gateway1/cpp/opencv_findContours.cpp
new file mode 100644
index 0000000..05da2b3
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_findContours.cpp
@@ -0,0 +1,199 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ contours = findcontours(input_image(after canny is applied on it), mode, method, point_x, point_y)
+********************************************************/
+
+#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_findContours(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen2=NULL;
+ int *piLen3 = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int i,j,k, findmode , findmethod;
+ char **find_method=NULL , **mode = NULL;
+ double x,y;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+ Mat src;
+ retrieveImage(src,1);
+
+ // for mode parameter of findContours
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, NULL, NULL);
+ piLen2 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen2, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ mode= (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ mode[i] = (char*)malloc(sizeof(char) * (piLen2[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen2, mode);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // for method parameter of findContours
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, NULL, NULL);
+ piLen3 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen3, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ find_method= (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ find_method[i] = (char*)malloc(sizeof(char) * (piLen3[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen3, find_method);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //toget the x coordinate of point parameter of findcontours
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&x);
+ if(intErr)
+ return intErr;
+
+ //toget the y coordinate of point parameter of findcontours
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&y);
+ if(intErr)
+ return intErr;
+
+ //to set hte mode for findcontour
+ if (strcmp(mode[0],"CV_RETR_EXTERNAL")==0)
+ findmode = CV_RETR_EXTERNAL;
+ else if (strcmp(mode[0],"CV_RETR_LIST")==0)
+ findmode = CV_RETR_LIST;
+ else if (strcmp(mode[0],"CV_RETR_CCOMP")==0)
+ findmode = CV_RETR_CCOMP;
+ else if (strcmp(mode[0],"CV_RETR_TREE")==0)
+ findmode = CV_RETR_TREE;
+ else
+ {
+ findmode = CV_RETR_TREE;
+ sciprint("wrong mode given , using CV_RETR_TREE instead");
+ }
+ // to set the method for findContours
+ if (strcmp(find_method[0],"CV_CHAIN_APPROX_NONE")==0)
+ findmethod = CV_CHAIN_APPROX_NONE;
+ else if (strcmp( find_method[0],"CV_CHAIN_APPROX_SIMPLE")==0)
+ findmethod = CV_CHAIN_APPROX_SIMPLE;
+ else if (strcmp(find_method[0],"CV_CHAIN_APPROX_TC89_L1")==0)
+ findmethod = CV_CHAIN_APPROX_TC89_L1;
+ else if (strcmp(find_method[0],"CV_CHAIN_APPROX_TC89_KCOS")==0)
+ findmethod = CV_CHAIN_APPROX_TC89_KCOS;
+ else
+ {
+ findmethod = CV_CHAIN_APPROX_SIMPLE;
+ sciprint("wrong method given , using CV_CHAIN_APPROX_SIMPLE instead");
+ }
+ Point pt(x,y);
+ /// Find contours
+ vector<vector<Point> > contours;
+ vector<Vec4i> hierarchy;
+ findContours( src, contours, hierarchy, findmode, findmethod, pt);
+
+ //Assigning the list as the Output Variable
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, contours.size(), &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(i=0;i<contours.size();i++)
+ {
+ double *arr = (double *)malloc(sizeof(double) * 2 * contours[i].size());
+
+ for(j=0;j<contours[i].size();j++)
+ {
+ *(arr + j*2 + 0) = contours[i][j].x;
+ *(arr + j*2 + 1) = contours[i][j].y;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, i+1, contours[i].size(), 2, arr);
+ free(arr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_gaussianblur.cpp b/sci_gateway1/cpp/opencv_gaussianblur.cpp
new file mode 100644
index 0000000..f81885e
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_gaussianblur.cpp
@@ -0,0 +1,132 @@
+/***************************************************
+Author : Sukul Bagai
+****************************************************
+Usage : return_image = gaussianblur(input_image,ksize_height,ksize_width,sigmaX,sigmaY);
+***************************************************/
+
+#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_gaussianblur(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int i,j,k;
+ double ksize_width,ksize_height,sigmaX,sigmaY;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of ksize_height
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &ksize_height);
+ if(intErr)
+ return intErr;
+
+ //for value of ksize_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &ksize_width);
+ if(intErr)
+ return intErr;
+
+ //for value of sigmaX
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &sigmaX);
+ if(intErr)
+ return intErr;
+
+ //for value of sigmaY
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &sigmaY);
+ if(intErr)
+ return intErr;
+
+ //applying checks to input parameters, and assigning default values in case of error
+ Mat new_image(image.rows,image.cols,CV_8UC3);
+ if(ksize_height<0)
+ {
+ sciprint("Positive Value Required for Height. 1 value was used instead");
+ ksize_height=1;
+ }
+ if(ksize_width<0)
+ {
+ sciprint("Positive Value Required for Width. 1 value was used instead");
+ ksize_width=1;
+ }
+ if((int)ksize_height%2==0)
+ {
+ ksize_height+=1;
+ sciprint("Odd Value Required for Height. %f value was used instead",&ksize_height);
+ }
+ if((int)ksize_width%2==0)
+ {
+ ksize_width+=1;
+ sciprint("Odd Value Required for Width. %f value was used instead",&ksize_width);
+ }
+
+ //temporary size variable, to use in function
+ Size sz(ksize_height,ksize_width);
+
+ //void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT )
+ GaussianBlur(image,new_image,sz,sigmaX,sigmaY);
+
+ //returning image
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_generateCheckerboardPoints.cpp b/sci_gateway1/cpp/opencv_generateCheckerboardPoints.cpp
new file mode 100644
index 0000000..998f6fe
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_generateCheckerboardPoints.cpp
@@ -0,0 +1,157 @@
+/***************************************************
+Author : Tanmay Chaudhari
+ **************************************************/
+
+#include <numeric>
+#include <iostream>
+using namespace std;
+extern "C"
+{
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "BOOL.h"
+#include <localization.h>
+#include "sciprint.h"
+
+ int opencv_genCheckerboardPoints(char *fname, unsigned long fname_len)
+ {
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int iType = 0;
+ int iComplex = 0;
+ int rowsOfBoardSize = 0;
+ int rowsOfSquareSize = 0;
+ int colsOfBoardSize = 0;
+ int colsOfSquareSize = 0;
+ int iterator1 = 0;
+ int iterator2 = 0;
+ int *piAddr = NULL;
+ double *boardSize = NULL;
+ double *squareSize = NULL;
+ double *worldPoints = NULL;
+
+ //Check input output arguments
+ checkInputArgument(pvApiCtx, 2, 2);
+ checkOutputArgument(pvApiCtx, 1, 1);
+
+ //Get variable address of the first input argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfBoardSize, &colsOfBoardSize, &boardSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(((rowsOfBoardSize != 1) || (colsOfBoardSize != 2)) || (boardSize[0] <= 0) || (boardSize[1] <= 0))
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get variable address of the second input argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfSquareSize, &colsOfSquareSize, &squareSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(((rowsOfSquareSize != 1) || (colsOfSquareSize != 1)) || (squareSize[0] <= 0))
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ boardSize[0] -= 1;
+ boardSize[1] -= 1;
+ worldPoints = (double*)malloc(sizeof(double) * 2 * (int(boardSize[0])) * (int(boardSize[1])));
+
+ iterator1 = 0;
+ iterator2 = (int(boardSize[0])) * (int(boardSize[1]));
+
+ for(int j = 0; j <= int(boardSize[1]) - 1; j++)
+ {
+ for(int i = 0; i <= int(boardSize[0]) - 1; i++)
+ {
+ worldPoints[iterator1] = j * squareSize[0];
+ worldPoints[iterator2] = i * squareSize[0];
+ iterator1++;
+ iterator2++;
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, (int(boardSize[0])) * (int(boardSize[1])), 2, worldPoints);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Return Output Argument
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
+
+
+
diff --git a/sci_gateway1/cpp/opencv_getStructuringElement.cpp b/sci_gateway1/cpp/opencv_getStructuringElement.cpp
new file mode 100644
index 0000000..8226671
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_getStructuringElement.cpp
@@ -0,0 +1,147 @@
+/*************************************************
+Author: Sukul Bagai
+**************************************************/
+
+#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_getStructuringElement(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr1 = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int i,j,k,type;
+ char **gettype = NULL;
+ double cols,rows,anchorX,anchorY;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows, &iCols, NULL, NULL);
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ gettype= (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ gettype[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ //third call to retrieve data of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows, &iCols, piLen, gettype);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp("MORPH_RECT",gettype[0])==0)
+ type=MORPH_RECT;
+ else if(strcmp("MORPH_ELLIPSE",gettype[0])==0)
+ type=MORPH_ELLIPSE;
+ else if(strcmp("MORPH_CROSS",gettype[0])==0)
+ type=MORPH_CROSS;
+
+ //for cols
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2 ,&cols);
+ if(intErr)
+ return intErr;
+
+ //for rows
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &rows);
+ if(intErr)
+ return intErr;
+
+ //for anchorX
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4 ,&anchorX);
+ if(intErr)
+ return intErr;
+
+ //for anchorY
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&anchorY);
+ if(intErr)
+ return intErr;
+
+ Mat temp = getStructuringElement(type,Size(rows,cols),Point(anchorX,anchorY));
+
+ double *m = (double *)malloc(temp.rows*temp.cols*sizeof(double));
+ for(i=0;i<temp.rows;i++)
+ {
+ for(j=0;j<temp.cols;j++)
+ {
+ uchar intensity = temp.at<uchar>(i, j);
+ *(m + i*temp.cols + j) = intensity;
+ }
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, temp.rows, temp.cols, m);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_getTextSize.cpp b/sci_gateway1/cpp/opencv_getTextSize.cpp
new file mode 100644
index 0000000..150b8ec
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_getTextSize.cpp
@@ -0,0 +1,188 @@
+/***************************************************
+Author : Sukul Bagai , Abhilasha Sancheti
+****************************************************
+Usage : [size,baseline] = getTextSize("<input text>","<fontface>",fontscale,thickness);
+***************************************************/
+
+#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_getTextSize(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piLen = NULL;
+ int *piLen2 = NULL;
+ char **pstData = NULL;
+ char **pstData2 = NULL;
+ double font_scale = 0,thickness = 0;
+ int i;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 2, 2) ;
+
+ //for string
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(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, piAddr, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for fontface
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen2 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen2, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData2 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ pstData2[i] = (char*)malloc(sizeof(char) * (piLen2[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen2, pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for value of font scale
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &font_scale);
+ if(intErr)
+ return intErr;
+
+ //for value of thickness
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &thickness);
+ if(intErr)
+ return intErr;
+
+ int fontFace;
+
+ if(strcmp(pstData2[0],"FONT_HERSHEY_SIMPLEX")==0)
+ fontFace = FONT_HERSHEY_SIMPLEX;
+ else if (strcmp(pstData2[0],"FONT_HERSHEY_PLAIN")==0)
+ fontFace= FONT_HERSHEY_PLAIN;
+ else if (strcmp(pstData2[0],"FONT_HERSHEY_DUPLEX")==0)
+ fontFace= FONT_HERSHEY_DUPLEX;
+ else if (strcmp(pstData2[0],"FONT_HERSHEY_COMPLEX")==0)
+ fontFace= FONT_HERSHEY_COMPLEX;
+ else if (strcmp(pstData2[0],"FONT_HERSHEY_TRIPLEX")==0)
+ fontFace = FONT_HERSHEY_TRIPLEX;
+ else if (strcmp(pstData2[0],"FONT_HERSHEY_COMPLEX_SMALL")==0)
+ fontFace = FONT_HERSHEY_COMPLEX_SMALL;
+ else if (strcmp(pstData2[0],"FONT_HERSHEY_SCRIPT_SIMPLEX")==0)
+ fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
+ else if (strcmp(pstData2[0],"FONT_HERSHEY_SCRIPT_COMPLEX")==0)
+ fontFace = FONT_HERSHEY_SCRIPT_COMPLEX;
+
+ int baseline;
+ Size sz = getTextSize(pstData[0],fontFace,font_scale,thickness,&baseline);
+ double tempsize[2];
+ tempsize[0]=sz.width;
+ tempsize[1]=sz.height;
+ double returnbaseline = (double)baseline;
+
+ sciErr = createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,1,2,tempsize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr,0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx,nbInputArgument(pvApiCtx)+2,1,1,&returnbaseline);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr,0);
+ return 0;
+ }
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_getgaussiankernel.cpp b/sci_gateway1/cpp/opencv_getgaussiankernel.cpp
new file mode 100644
index 0000000..99c6d7d
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_getgaussiankernel.cpp
@@ -0,0 +1,142 @@
+/********************************************************
+ Author: Shubheksha Jalan
+*********************************************************
+Mat getGaussianKernel(int ksize, double sigma, int ktype=CV_64F )
+********************************************************/
+
+
+#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_getgaussiankernel(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ double ksize, sigma;
+ char **kType = NULL;
+ int i, j, k;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+
+ //for value of ksize
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &ksize);
+ if(intErr || ksize < 0 || (int) ksize % 2 == 0)
+ {
+ return intErr;
+ }
+
+
+ //for first value of size
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &sigma);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &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, piAddr3, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ kType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ kType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, kType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ Mat temp;
+
+ if(strcmp(kType[0], "CV_32F") == 0)
+ temp = getGaussianKernel(ksize, sigma, CV_32F
+ );
+ else if(strcmp(kType[0], "CV_64F") == 0)
+ temp = getGaussianKernel(ksize, sigma, CV_64F);
+
+ double *m = (double *)malloc(temp.rows*temp.cols*sizeof(double));
+ for(i=0;i<temp.rows;i++)
+ {
+ for(j=0;j<temp.cols;j++)
+ {
+ uchar intensity = temp.at<uchar>(i, j);
+ *(m + i*temp.cols + j) = intensity;
+ }
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, temp.rows, temp.cols, m);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
+
+
+
+
+
diff --git a/sci_gateway1/cpp/opencv_getrectsubpix.cpp b/sci_gateway1/cpp/opencv_getrectsubpix.cpp
new file mode 100644
index 0000000..2f6e835
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_getrectsubpix.cpp
@@ -0,0 +1,142 @@
+/********************************************************
+ Author: Shubheksha Jalan
+*********************************************************
+ void getRectSubPix(InputArray image, Size patchSize, Point2f center, OutputArray patch, int patchType=-1 )¶
+********************************************************/
+
+
+#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_getrectsubpix(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int i,j,k;
+ double centerX, centerY, alpha, beta, patchType;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 6, 6);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for first value of size
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &alpha);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //for second value of size
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &beta);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for x coordinate of center
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &centerX);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for y coordinate of center
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &centerY);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //for patchType
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &patchType);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ Size patchSize = Size(alpha, beta);
+
+ Point2f center = Point2f(centerX, centerY);
+
+ Mat patch;
+
+ getRectSubPix(image, patchSize, center, patch, patchType);
+
+
+ String tempstring = type2str(patch.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, patch, 1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_getrotationmatrix2D.cpp b/sci_gateway1/cpp/opencv_getrotationmatrix2D.cpp
new file mode 100644
index 0000000..5a54ed2
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_getrotationmatrix2D.cpp
@@ -0,0 +1,121 @@
+/********************************************************
+ Author: Shubheksha Jalan
+*********************************************************
+Mat getRotationMatrix2D(Point2f center, double angle, double scale)
+********************************************************/
+
+
+#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_getrotationmatrix2D(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int i,j,k;
+ double centerX, centerY, angle, scale;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+
+ //for x coordinate of center
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &centerX);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for y coordinate of center
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &centerY);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //for value of angle
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &angle);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of scale
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &scale);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ Point2f center = Point2f(centerX, centerY);
+
+ Mat temp = getRotationMatrix2D(center, angle, scale);
+
+ double *m = (double *)malloc(temp.rows*temp.cols*sizeof(double));
+ for(i=0;i<temp.rows;i++)
+ {
+ for(j=0;j<temp.cols;j++)
+ {
+ uchar intensity = temp.at<uchar>(i, j);
+ *(m + i*temp.cols + j) = intensity;
+ }
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, temp.rows, temp.cols, m);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
+
diff --git a/sci_gateway1/cpp/opencv_goodfeaturestotrack.cpp b/sci_gateway1/cpp/opencv_goodfeaturestotrack.cpp
new file mode 100644
index 0000000..79e614f
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_goodfeaturestotrack.cpp
@@ -0,0 +1,168 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ corner_points = goodFeaturesToTrack( input_image, maxCorners, qualityLevel, minDistance, blockSize, useHarrisDetector((1 for true)/(0 for false)),k );
+********************************************************/
+
+
+// Abhilasha Sancheti
+// sample input :
+//output: (image , corners)
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#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 <sciprint.h>
+ #include "../common.h"
+
+ int opencv_goodfeaturestotrack(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+
+ int i,j, detector;
+ double maxCorners ,qualityLevel,minDistance,blocksize=3 ,k=0.04, usedetector;
+ bool useHarrisDetector = false;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 7, 7);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ Mat image;
+ retrieveImage(image,1);
+
+ //for maximum corners
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2 ,&maxCorners);
+ if(intErr)
+ return intErr;
+
+
+ //for qualityLevel
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&qualityLevel);
+ if(intErr)
+ return intErr;
+
+ //for minDistance
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4 ,&minDistance);
+ if(intErr)
+ return intErr;
+
+
+ //for blocksize
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&blocksize);
+ if(intErr)
+ return intErr;
+
+ //for Harrisusedetector taking integer 1 or 0
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6,&usedetector);
+ if(intErr)
+ return intErr;
+ detector=(int)usedetector;
+
+ //for k value
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7 ,&k);
+ if(intErr)
+ return intErr;
+
+
+ //checking the input parameter usedetector
+ if (detector == 1)
+ useHarrisDetector = true;
+ else if(detector == 0)
+ useHarrisDetector = false;
+ else
+ {
+ sciprint("Either 1 or 0 , 0 value was used instead");
+ useHarrisDetector = false;
+ }
+
+ /// processing of the input image and other parameters
+ if( maxCorners < 1 ) { maxCorners = 1; sciprint("maxcorners cannot be less than 1 , using 1 instead");}
+
+ /// Parameters for Shi-Tomasi algorithm
+
+ vector<Point2f> corners;
+ /// Copy the source image
+ Mat src_gray;
+ cvtColor( image, src_gray, CV_BGR2GRAY );
+ /// Apply corner detection
+ goodFeaturesToTrack( src_gray,corners,maxCorners,qualityLevel,minDistance,Mat(),blocksize,useHarrisDetector,k );
+
+ int row = corners.size();
+ double *cor = (double *)malloc(2*row*sizeof(double *));
+ for (int i=0;i<row;i++)
+ {
+ *(cor + i*2 + 0)=corners[i].x;
+ *(cor + i*2 + 1)=corners[i].y;
+ }
+
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, row, 2, cor);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_houghcircles.cpp b/sci_gateway1/cpp/opencv_houghcircles.cpp
new file mode 100644
index 0000000..4b36aa6
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_houghcircles.cpp
@@ -0,0 +1,164 @@
+/********************************************************
+Authors: Sukul Bagai, Abhilasha Sancheti
+********************************************************/
+
+#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_houghcircles(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 *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int i,j,k;
+ double *dp =NULL , *mindist = NULL ,*param1= NULL ,*param2=NULL;
+ double *minradius =NULL, *maxradius = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 7, 7);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat src;
+ retrieveImage(src,1);
+
+ // for dp parameter of houghCircles function
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols ,&dp);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // for minDist parameter of houghCircles function
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols ,&mindist);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // for param1 parameter of houghCircles function
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols ,&param1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // for param2 parameter of houghCircles function
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr5, &iRows, &iCols ,&param2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ // for minradius parameter of houghCircles function
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr6, &iRows, &iCols ,&minradius);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ // for maxradius parameter of houghCircles function
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr7, &iRows, &iCols ,&maxradius);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ Mat src_gray;
+ cvtColor( src, src_gray, CV_BGR2GRAY );
+
+ /// Reduce the noise so we avoid false circle detection
+
+
+ vector<Vec3f> circles;
+
+ /// Apply the Hough Transform to find the circles
+ HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, dp[0], mindist[0], param1[0], param2[0], minradius[0], maxradius[0] );
+ int rows = circles.size();
+ cout<<circles.size();
+ double *output = (double *)malloc(3*rows*sizeof(double *));
+
+ /// Draw the circles detected
+ for(int i=0;i<rows;i++)
+ {
+ *(output + i*3 + 0) = circles[i][0];
+ *(output + i*3 + 1) = circles[i][1];
+ *(output + i*3 + 2) = circles[i][2];
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, rows, 3, output);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_houghlines.cpp b/sci_gateway1/cpp/opencv_houghlines.cpp
new file mode 100644
index 0000000..28202d1
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_houghlines.cpp
@@ -0,0 +1,133 @@
+/********************************************************
+Author: Shubheksha Jalan
+********************************************************/
+
+#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_houghlines(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int i,j,k;
+ double rho, theta, srn, stn, threshold;
+ CheckInputArgument(pvApiCtx, 6, 6);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+ Mat image;
+ retrieveImage(image, 1);
+ cvtColor(image, image, CV_BGR2GRAY);
+ //for value of rho
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &rho);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of theta
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &theta);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of threshold
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &threshold);
+ if(intErr)
+ {
+ return intErr;
+ }
+ //for value of srn
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &srn);
+ if(intErr)
+ {
+ return intErr;
+ }
+ //for value of stn
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &stn);
+ if(intErr)
+ {
+ return intErr;
+ }
+ vector < vector <double> > output;
+ cout<<"here5";
+ HoughLines(image, output, rho, theta, threshold, srn, stn);
+ cout<<"here5";
+//create matrix from 2-D vector
+ int row = output.size();
+ cout<<row;
+ double *cor = (double *)malloc(row*2*sizeof(double));
+ for (int i=0;i<row;i++)
+ {
+ *(cor + i*2 +0)=output[i][0];
+ // cout<<output[i][0]<<" "<<output[i][1];
+ *(cor + i*2 +1)=output[i][1];
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, row, 2, cor);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_houghlinesp.cpp b/sci_gateway1/cpp/opencv_houghlinesp.cpp
new file mode 100644
index 0000000..1e69a09
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_houghlinesp.cpp
@@ -0,0 +1,134 @@
+#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_houghlinesp(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int i,j,k;
+ double rho, theta, minLineLength = 0, maxLineGap = 0, threshold;
+ CheckInputArgument(pvApiCtx, 6, 6);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+ Mat image;
+ retrieveImage(image, 1);
+ cvtColor(image, image, CV_BGR2GRAY);
+ //for value of rho
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &rho);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of theta
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &theta);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of threshold
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &threshold);
+ if(intErr)
+ {
+ return intErr;
+ }
+ //for value of minLineLength
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &minLineLength);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of maxLineGap
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &maxLineGap);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ vector < vector <double> > output;
+
+ HoughLinesP(image, output, rho, theta, threshold, minLineLength, maxLineGap);
+
+//create matrix from 2-D vector
+ int row = output.size();
+ double *cor = (double *)malloc(row*4*sizeof(double));
+
+
+ for (int i=0;i<row;i++)
+ {
+ *(cor + i*2 +0)=output[i][0];
+ // cout<<output[i][0]<<" "<<output[i][1];
+ *(cor + i*2 +1)=output[i][1];
+ *(cor + i*2 +2)=output[i][2];
+ *(cor + i*2 +3)=output[i][3];
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, row, 4, cor);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_im2double.cpp b/sci_gateway1/cpp/opencv_im2double.cpp
new file mode 100644
index 0000000..45ee009
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_im2double.cpp
@@ -0,0 +1,56 @@
+/********************************************************
+Author: Sukul Bagai
+********************************************************/
+
+#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 "../common.h"
+
+ int opencv_im2double(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int i,j,k;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ Mat img_dbprec;
+ image.convertTo(img_dbprec, CV_64FC3,1.0/255.0); /// Create Image with Double Precision
+
+ string tempstring = type2str(img_dbprec.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,img_dbprec,1);
+ free(checker);
+
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imageSet.cpp b/sci_gateway1/cpp/opencv_imageSet.cpp
new file mode 100644
index 0000000..9b27840
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imageSet.cpp
@@ -0,0 +1,294 @@
+
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+
+#include <iostream>
+#include <dirent.h>
+#include <vector>
+#include <string>
+#include <string.h>
+#include <algorithm>
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+
+
+ string formats[] = {"jpeg","jpg","bmp","png","JPEG","JPG","BMP","PNG"};
+
+ vector<vector<string> > descriptionVector;
+
+ const char pathSeparator =
+ #ifdef _WIN32
+ '\\';
+ #else
+ '/';
+ #endif
+
+ bool recursive = false;
+ bool listDirError = 0;
+
+ bool isImage(string fname)
+ {
+ for(int i=0;i<8;i++)
+ {
+ if(fname.substr(fname.length()-formats[i].length()).compare(formats[i])==0)
+ return 1;
+ }
+ return 0;
+ }
+
+ void listDir(string dirName, vector<string> &currentDir)
+ {
+ DIR *dir;
+ struct dirent *entry;
+ if(!(dir = opendir(dirName.c_str())))
+ {
+ Scierror(999,"Cannot open directory for reading. Please check the directory name.\n");
+ listDirError = 1;
+ return;
+ }
+ if(!(entry = readdir(dir)))
+ {
+ Scierror(999,"The directory is empty.\n");
+ listDirError = 1;
+ return;
+ }
+
+ do
+ {
+ if (entry -> d_type == DT_DIR)
+ {
+ if(strcmp(entry->d_name,".")==0 || strcmp(entry->d_name,"..")==0) continue;
+ if(recursive)
+ {
+ vector<string> nextDir;
+ nextDir.push_back(entry->d_name);
+ listDir(dirName+pathSeparator+entry->d_name,nextDir);
+ }
+ }
+ else
+ {
+ if(isImage(entry->d_name))
+ {
+ //cout<<dirName<<pathSeparator<<entry->d_name<<endl;
+ currentDir.push_back(dirName+pathSeparator+entry->d_name);
+ }
+ }
+ }while(entry = readdir(dir));
+ vector<string>::iterator it = currentDir.begin();
+ sort(it+1,currentDir.end());
+ descriptionVector.push_back(currentDir);
+ }
+
+ /*Calling syntax: imageSet(imageLocation) OR imageSet(imageFolder,'recursive') */
+
+ int opencv_imageSet(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+
+ //------Local variables------//
+ int *piAddr = NULL;
+ int *piChild = NULL;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ int iRows, iCols;
+
+ string filePath,fileName,tempPath;
+ char **description = NULL;
+ char ***location = NULL;
+ int *count = NULL;
+ int descriptionCount = 0;
+ int pos = 0;
+ char *objectType = "imageSet";
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ //------Get input arguments------//
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ filePath = string(pstData[0]);
+
+ if(*getNbInputArgument(pvApiCtx) == 2)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp("recursive",pstData[0])!=0)
+ {
+ Scierror(999, "Error: Argument %s is invalid. \n", pstData[0]);
+ return 0;
+ }
+ recursive = true;
+ }
+
+ //------Actual processing------//
+ while(filePath[filePath.length()-1]==pathSeparator)
+ {
+ filePath = filePath.substr(0,filePath.length()-1);
+ }
+ vector<string> nextDir;
+ nextDir.push_back(filePath.substr(filePath.find_last_of(pathSeparator)+1));
+
+ listDir(filePath,nextDir);
+
+ if(listDirError)
+ {
+ listDirError = 0; //Doing this is very important as it is a global
+ return 0;
+ }
+ for(int i=0;i<descriptionVector.size();i++)
+ {
+ if(descriptionVector[i].size()>1)
+ descriptionCount++;
+
+ }
+ description = (char**) malloc(sizeof(char*) * descriptionCount);
+ count = (int*) malloc(sizeof(int) * descriptionCount);
+ location = (char***) malloc(sizeof(char**) * descriptionCount);
+
+ for(int i=0;i<descriptionVector.size();i++)
+ {
+ if(descriptionVector[i].size()>1)
+ {
+ description[pos] = (char*) malloc(sizeof(char) * descriptionVector[i][0].length() + 1);
+ descriptionVector[i][0].copy(description[pos],descriptionVector[i][0].length());
+ description[pos][descriptionVector[i][0].length()] = 0;
+
+ count[pos] = descriptionVector[i].size()-1;
+
+ location[pos] = (char**) malloc(sizeof(char*) * (descriptionVector[i].size()-1));
+ for(int j=1;j<descriptionVector[i].size();j++)
+ {
+ location[pos][j-1] = (char*) malloc(sizeof(char) * descriptionVector[i][j].length() + 1);
+ descriptionVector[i][j].copy(location[pos][j-1],descriptionVector[i][j].length());
+ location[pos][j-1][descriptionVector[i][j].length()] = 0;
+ }
+ pos++;
+ }
+ }
+
+ descriptionVector.clear(); //Doing this is very important as it is a global
+ recursive = false; //Doing this is very important as it is a global
+
+ //------Create output arguments------//
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 1, 1, 1, &objectType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 2, descriptionCount, 1, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 3, descriptionCount, 1, count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createListInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 4, descriptionCount, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(int i=0;i<descriptionCount;i++)
+ {
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piChild, i+1, 1, count[i], location[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imcontrast.cpp b/sci_gateway1/cpp/opencv_imcontrast.cpp
new file mode 100644
index 0000000..216228f
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imcontrast.cpp
@@ -0,0 +1,100 @@
+/********************************************************
+Author: Sukul Bagai
+********************************************************/
+
+#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 "../common.h"
+
+ int opencv_imcontrast(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int i,j,k;
+ double alpha, beta;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ //for value of alpha
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &alpha);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of beta
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &beta);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //we copy the original image into the new_image, and change values of each pixel using value of alpha and beta given by the user
+ Mat new_image = Mat::zeros( image.size(), image.type() );
+
+ //changes the attributes of each individual pixel
+ for( int y = 0; y < image.rows; y++ )
+ {
+ for( int x = 0; x < image.cols; x++ )
+ {
+ for( int c = 0; c < 3; c++ )
+ {
+ new_image.at<Vec3b>(y,x)[c] =
+ saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
+ }
+ }
+ }
+
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imcrop.cpp b/sci_gateway1/cpp/opencv_imcrop.cpp
new file mode 100644
index 0000000..d180c0a
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imcrop.cpp
@@ -0,0 +1,130 @@
+/********************************************************
+Author: Sukul Bagai
+********************************************************/
+
+#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_imcrop(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int i,j,k;
+ double x, y, width, height;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ //for value of top-left x-coordinate
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &x);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value top-left y-coordinate
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &y);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of width
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &width);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //for value of height
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &height);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if(x>=image.cols || y>=image.rows || x<0 || y<0)
+ {
+ sciprint("Invalid x or y value\n");
+ return 0;
+ }
+ if(width<=0 || height<=0 || x+width > image.cols || y+height > image.rows)
+ {
+ sciprint("Invalid width or height value\n");
+ return 0;
+ }
+ //defining a temporary rectangle, that denotes the area that has to be cropped into the new image
+ Rect myROI(x, y, width, height);
+
+ // Crop the full image to that image contained by the rectangle myROI
+ // Note that this doesn't copy the data
+ Mat croppedRef(image, myROI);
+
+ Mat cropped;
+ // Copy the data into new matrix
+ croppedRef.copyTo(cropped);
+
+ string tempstring = type2str(cropped.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,cropped,1);
+ free(checker);
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imfindcircles.cpp b/sci_gateway1/cpp/opencv_imfindcircles.cpp
new file mode 100644
index 0000000..2569343
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imfindcircles.cpp
@@ -0,0 +1,128 @@
+/********************************************************
+Function :imfindcircles
+Syntax :B=imfindcircles(A)
+Author: Tess Zacharias
+
+********************************************************/
+
+#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_imfindcircles(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ Mat src_gray,image;
+ double Rmin,Rmax;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 2) ;
+ retrieveImage(image, 1);
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &Rmin);
+ if(intErr)
+ {
+ return intErr;
+ }
+ if(Rmin!= round(Rmin) || Rmin<=0)
+ {
+ sciprint("The value of minium Radius must be an integer\n");
+ return 0;
+ }
+ if(Rmin<5)
+ {
+ sciprint("The value of minium Radius too small\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &Rmax);
+ if(intErr)
+ {
+ return intErr;
+ }
+ if(Rmax!= round(Rmax) || Rmax<=0)
+ {
+ sciprint("The value of maximum Radius must be an integer\n");
+ return 0;
+ }
+ cvtColor(image,src_gray, CV_BGR2GRAY);
+ GaussianBlur( src_gray, src_gray, Size(9, 9), 2, 2 );
+ vector<Vec3f> circles;
+ HoughCircles( src_gray, circles, CV_HOUGH_GRADIENT, 2, 10, 200, 100,Rmin,Rmax);
+ int k=circles.size();
+ double *radius=NULL;
+ radius=( double *)malloc(sizeof(double)*k);
+ double *c1=NULL;
+ c1=( double *)malloc(sizeof(double)*k);
+ double *c2=NULL;
+ c2=( double *)malloc(sizeof(double)*k);
+ for( size_t i= 0; i < circles.size(); i++ )
+ {
+ c1[i]=cvRound(circles[i][0]);
+ c2[i]=cvRound(circles[i][1]);
+ radius[i]=cvRound(circles[i][2]);
+ }
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 2, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddrNew, 1, 1, k, c1);
+ free(c1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddrNew, 2, 1, k, c2);
+ free(c2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ if(Lhs==2)
+ {
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) +2,1,k,radius);
+ free(radius);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ }
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_imread.cpp b/sci_gateway1/cpp/opencv_imread.cpp
new file mode 100644
index 0000000..c02af10
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imread.cpp
@@ -0,0 +1,99 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+#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"
+ #include "../common.cpp"
+
+int opencv_imread(char *fname, unsigned long fname_len)
+{
+ SciErr sciErr;
+ int iLen = 0;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ int **pstData1 = NULL;
+ int i,j,k=0;
+
+
+ //Checking number of input and output arguments (enviromnet variable, min arguments, max arguments)
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // get Address of inputs
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(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, piAddr, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating image matrix, by getting the image at the specified path
+ Mat img = imread(pstData[0],CV_LOAD_IMAGE_COLOR);
+
+ string tempstring = type2str(img.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,img,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imread.cpp~ b/sci_gateway1/cpp/opencv_imread.cpp~
new file mode 100644
index 0000000..2f5ad90
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imread.cpp~
@@ -0,0 +1,99 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+#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"
+ #include "../common.cpp"
+
+int opencv_imread(char *fname, unsigned long fname_len)
+{
+ SciErr sciErr;
+ int iLen = 0;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ int **pstData1 = NULL;
+ int i,j,k=0;
+
+
+ //Checking number of input and output arguments (enviromnet variable, min arguments, max arguments)
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // get Address of inputs
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(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, piAddr, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //creating image matrix, by getting the image at the specified path
+ Mat img = imread(pstData[0],CV_LOAD_IMAGE_UNCHANGED);
+
+ string tempstring = type2str(img.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,img,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imresize.cpp b/sci_gateway1/cpp/opencv_imresize.cpp
new file mode 100644
index 0000000..190ab5e
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imresize.cpp
@@ -0,0 +1,94 @@
+/********************************************************
+Author: Sukul Bagai
+********************************************************/
+
+#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_imresize(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int i,j,k;
+ double alpha, beta;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ //for new no. of rows
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &alpha);
+ if(sciErr.iErr)
+ {
+ return intErr;
+ }
+
+ //for new no. of columns
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &beta);
+ if(sciErr.iErr)
+ {
+ return intErr;
+ }
+
+
+ Mat new_image;
+ Size size(alpha, beta);
+
+ if(alpha<=0 || beta<=0)
+ {
+ sciprint("Invalid new size\n");
+ return 0;
+ }
+ //resizes the image to new_image to the size given by the user
+ resize(image,new_image,size);
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imsharpen.cpp b/sci_gateway1/cpp/opencv_imsharpen.cpp
new file mode 100644
index 0000000..ad0a593
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imsharpen.cpp
@@ -0,0 +1,59 @@
+/********************************************************
+Author: Sukul Bagai
+********************************************************/
+
+#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 "../common.h"
+
+ int opencv_imsharpen(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int i,j,k;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ Mat tmp;
+ cv::GaussianBlur(image, tmp, cv::Size(5,5), 5);
+ cv::addWeighted(image, 1.5, tmp, -0.5, 0, image);
+
+ string tempstring = type2str(image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, image, 1);
+ free(checker);
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_imwrite.cpp b/sci_gateway1/cpp/opencv_imwrite.cpp
new file mode 100644
index 0000000..2815ac9
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_imwrite.cpp
@@ -0,0 +1,85 @@
+/********************************************************
+Author: Sukul Bagai
+********************************************************/
+
+#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 "../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;
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_indexImages.cpp b/sci_gateway1/cpp/opencv_indexImages.cpp
new file mode 100644
index 0000000..6a37466
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_indexImages.cpp
@@ -0,0 +1,663 @@
+/****************************************************************************************
+* Author: Umang Agrawal *
+* Code: indexImages.cpp *
+* Function Call: indexImage = indexImages( Image_Set, Bag, Optional Arguments) *
+* Optional Argument: Name Value *
+* Verbose Bool(1 or 0) *
+* SaveFeatureLocations Bool(1 or 0) *
+****************************************************************************************/
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/ml/ml.hpp"
+
+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"
+
+ bool response(const KeyPoint& p1, const KeyPoint& p2) {
+ return p1.response > p2.response;
+ }
+
+ int opencv_indexImages(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+
+ int *piAddr = NULL;
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piChild = NULL;
+ int *piGrandChild = NULL;
+ int iRows, iCols;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ char *objectType = "invertedImageIndex";
+ char **description = NULL;
+ char ***location = NULL;
+ int *count = NULL;
+ int descriptionCount;
+ char **arg = NULL;
+ char **filePath = NULL;
+
+ int inp_params = 0;
+ char *bagOfFeaturesLocation = NULL;
+ double *upright_bag = NULL;
+ double *strength_bag = NULL;
+ double *vocab_size_bag = NULL;
+ int count_ver = 0, count_save = 0;
+ double save = 1;
+ double verbose = 1;
+ int upright = 1;
+ int vocab_size = 500;
+ double strength = 0.8;
+
+ vector<int> key_size_vector;
+ double *wordFrequency = NULL;
+ double ***ImageWords = NULL;
+ int indx;
+
+ Mat image;
+ Mat dictionary;
+ Mat featuresUnclustered;
+ Mat feature_des;
+ Mat des_matched;
+ Mat hist;
+ vector<KeyPoint> keypoints;
+ vector<KeyPoint> valid_key;
+ vector< vector<int> > clusterID;
+ int key_size;
+ int v_key_size;
+
+ CheckInputArgument(pvApiCtx, 1, 6); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 1); //Check on Number of Output Arguments
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr1))
+ {
+ Scierror(999, "Error: Invalid first argument. List Expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"imageSet")==0))
+ {
+ Scierror(999, "Error: The input argument 1 is not of type imageSet.\n");
+ return 0;
+ }
+
+ // Extracting Description attribute of input argument
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( iRows!= 1 )
+ {
+ Scierror(999,"Expecting an image Set with single type of Images.\n");
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ description = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ description[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, piLen, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ descriptionCount = iRows;
+
+ // Extracting Count attribute of input argument
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr1, 3, &iRows, &iCols, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( iRows!= 1 )
+ {
+ Scierror(999,"Expecting an image Set with single type of Images.\n");
+ return 0;
+ }
+ location = (char***) malloc(sizeof(char**) * descriptionCount);
+ sciErr = getListItemAddress(pvApiCtx, piAddr1, 4, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int iter = 1; iter<=descriptionCount; iter++)
+ {
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ location[iter-1] = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int colIter = 0 ; colIter < iRows * iCols ; colIter++)
+ {
+ location[iter-1][colIter] = (char*)malloc(sizeof(char) * (piLen[colIter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, location[iter-1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+//..............................................................................................................
+ inp_params = *getNbInputArgument(pvApiCtx);
+ if( inp_params>=2 )
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr2))
+ {
+ Scierror(999, "Error: Invalid first argument. List Expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!(strcmp(pstData[0],"bagOfFeatures")==0))
+ {
+ Scierror(999, "Error: The input argument 2 is not of type bagOfFeatures.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 2, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ bagOfFeaturesLocation = pstData[0];
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr2, 3, &iRows, &iCols, &vocab_size_bag);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr2, 4, &iRows, &iCols, &strength_bag);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr2, 5, &iRows, &iCols, &upright_bag);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ upright = int(upright_bag[0]);
+ vocab_size = int(vocab_size_bag[0]);
+ strength = strength_bag[0];
+ FileStorage fs(bagOfFeaturesLocation, FileStorage::READ);
+ fs["dictionary"] >> dictionary;
+ fs.release();
+
+//................................................................................................................
+ for( int i=3; i<=inp_params; i++)
+ {
+ if( inp_params%2 != 0)
+ {
+ Scierror(999,"Either Argument Name or its Value missing\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr3))
+ {
+ Scierror(999, "%s: Wrong type of argument for Name of Optional Argument. A string is expected.\n", fname);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));
+ }
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ free(arg);
+ return 0;
+ }
+
+ if(strcmp(arg[0],"Verbose") == 0)
+ {
+ if( count_ver != 0)
+ {
+ Scierror(999,"Verbose has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr4)))
+ {
+ Scierror(999,"Not a valid type of value for Verbose.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ if(getScalarDouble(pvApiCtx, piAddr4, &verbose))
+ {
+ Scierror(999,"Not a valid type of value for Verbose.\n");
+ return 0;
+ }
+ if( !(verbose == 1|| verbose == 0) )
+ {
+ Scierror(999,"Enter a valid value for Verbose (Either 0 or 1)\n");
+ return 0;
+ }
+ i++;
+ count_ver += 1;
+ }
+ else if(strcmp(arg[0],"SaveFeatureLocations") == 0)
+ {
+ if( count_save != 0)
+ {
+ Scierror(999,"SaveFeatureLoactions has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr4)))
+ {
+ Scierror(999,"Not a valid type of value for SaveFeatureLoactions.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ if(getScalarDouble(pvApiCtx, piAddr4, &save))
+ {
+ Scierror(999,"Not a valid type of value for SaveFeatureLoactions.\n");
+ return 0;
+ }
+ if( !(save == 1|| save == 0) )
+ {
+ Scierror(999,"Enter a valid value for SaveFeatureLoactions (Either 0 or 1)\n");
+ return 0;
+ }
+ i++;
+ count_save += 1;
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument Name\n");
+ return 0;
+ }
+ }
+ }
+
+ if(int(verbose))
+ {
+ sciprint("Creating an Inverted image Index Using Bag-Of-Features.\n");
+ sciprint("--------------------------------------------------------\n");
+ }
+
+ if( inp_params == 1)
+ {
+ bagOfFeaturesLocation = "Bag-Of-Features.yml";
+ SurfFeatureDetector detector(100, 4, 2, 1, upright);
+ SurfDescriptorExtractor extractor(100, 4, 2, 1, upright);
+
+ if(int(verbose))
+ {
+ sciprint("Creating Bag-Of-Features from %d image sets.\n\n",descriptionCount);
+ for(int i=0; i<descriptionCount; i++)
+ sciprint("Image set %d: %s\n",i+1,description[i]);
+ sciprint("\nExtracting SURF Features from each image set.\n\n");
+ }
+
+ for( int i=0; i<descriptionCount; i++)
+ {
+ if(int(verbose))
+ sciprint("Extracting features from %d images in image set %d",count[i],i+1);
+ key_size = 0;
+ v_key_size = 0;
+ for( int j=0; j<count[i]; j++)
+ {
+ if(int(verbose))
+ sciprint(".");
+ keypoints.clear();
+ valid_key.clear();
+ image = imread(location[i][j],1);
+ detector.detect(image, keypoints);
+ sort(keypoints.begin(), keypoints.end(), response);
+ for( int k=0; k<(keypoints.size()*strength); k++)
+ {
+ valid_key.push_back(keypoints[k]);
+ }
+ extractor.compute(image, valid_key, feature_des);
+ featuresUnclustered.push_back(feature_des);
+ key_size += keypoints.size();
+ v_key_size += valid_key.size();
+ }
+ if(int(verbose))
+ {
+ sciprint("done. Extracted %d features.\n",key_size);
+ sciprint("Keeping %f percent of the strongest features.\n",(strength)*100);
+ sciprint("Net Extracted features : %d\n\n",v_key_size);
+ }
+ }
+
+ vocab_size = featuresUnclustered.rows;
+ TermCriteria tc(CV_TERMCRIT_ITER, 100, 0.001);
+ int retries = 3;
+ BOWKMeansTrainer bowTrainer(int(vocab_size), tc, retries, KMEANS_PP_CENTERS);
+
+ if(int(verbose))
+ {
+ sciprint("Using K-Means Clustering to create a %d word visual vocabulary.\n",int(vocab_size));
+ sciprint("Number of Features : %d\n",featuresUnclustered.rows);
+ sciprint("Number of Clusters : %d\n\n",int(vocab_size));
+ }
+
+ dictionary = bowTrainer.cluster(featuresUnclustered);
+
+ if(int(verbose))
+ sciprint("Finished creating Bag-Of-Features\n");
+
+ FileStorage fs(bagOfFeaturesLocation, FileStorage::WRITE);
+ fs<<"dictionary"<<dictionary;
+ fs.release();
+ }
+
+ filePath = (char**)malloc(sizeof(char*)*1*1);
+ filePath[0] = (char*)malloc(sizeof(char)*20*1);
+ strcpy(filePath[0],bagOfFeaturesLocation);
+
+ if(int(verbose))
+ {
+ sciprint("Encoding 1 Image Set using Bag-Of-Features.\n");
+ sciprint("--------------------------------------------\n");
+ }
+
+ if(int(verbose))
+ {
+ sciprint("\nImage set 1: %s\n\n",description[0]);
+ sciprint("Encoding %d images from image set 1",count[0]);
+ }
+
+ ImageWords = (double***)malloc(sizeof(double**)*count[0]*1);
+ wordFrequency = (double*)malloc(sizeof(double)*vocab_size);
+ for( int j=0; j<vocab_size; j++)
+ {
+ wordFrequency[j] = 0;
+ }
+
+ Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
+ Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor(100, 4, 2, 1, 1);
+ SurfFeatureDetector detector(100, 4, 2, 1, 1);
+ BOWImgDescriptorExtractor bowDE(extractor, matcher);
+ bowDE.setVocabulary(dictionary);
+ for( int i=0; i<count[0]; i++)
+ {
+ if(int(verbose))
+ sciprint(".");
+ valid_key.clear();
+ keypoints.clear();
+ feature_des.release();
+ image = imread(location[0][i],1);
+ detector.detect(image, keypoints);
+ bowDE.compute(image, keypoints, hist, &clusterID, &des_matched);
+
+ key_size_vector.push_back(keypoints.size());
+ ImageWords[i] = (double**)malloc(sizeof(double*)*4*1);
+ ImageWords[i][0] = (double*)malloc(sizeof(double)*keypoints.size()*1);
+ ImageWords[i][1] = (double*)malloc(sizeof(double)*keypoints.size()*2);
+ ImageWords[i][2] = (double*)malloc(sizeof(double)*1);
+ ImageWords[i][3] = (double*)malloc(sizeof(double)*1);
+
+ ImageWords[i][2][0] = vocab_size;
+ ImageWords[i][3][0] = keypoints.size();
+
+ for( int j=0; j<keypoints.size(); j++)
+ {
+ ImageWords[i][1][j] = keypoints[j].pt.x;
+ ImageWords[i][1][keypoints.size() + j] = keypoints[j].pt.y;
+ }
+ for( int j=0; j<clusterID.size(); j++)
+ {
+ wordFrequency[j] = wordFrequency[j]+clusterID[j].size();
+ for( int k=0; k<clusterID[j].size(); k++)
+ {
+ indx = clusterID[j][k];
+ ImageWords[i][0][indx] = j;
+ }
+ }
+ }
+ if(int(verbose))
+ {
+ sciprint("done.\n\n");
+ sciprint("Finished encoding images.\nFinished creating the image index\n");
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 4+int(save), &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 1, 1, 1, &objectType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createListInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 2, count[0], &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for( int i=0; i<count[0]; i++)
+ {
+ sciErr = createListInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piChild, i+1, 4, &piGrandChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piGrandChild, 1, key_size_vector[i], 1, ImageWords[i][0]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piGrandChild, 2, key_size_vector[i], 2, ImageWords[i][1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piGrandChild, 3, 1, 1, ImageWords[i][2]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piGrandChild, 4, 1, 1, ImageWords[i][3]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 3, vocab_size, 1, wordFrequency);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 4, 1, 1, filePath);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(int(save) == 1)
+ {
+ sciErr = createListInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 5, descriptionCount, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int i=0;i<descriptionCount;i++)
+ {
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piChild, i+1, 1, count[i], location[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_integralFilter.cpp b/sci_gateway1/cpp/opencv_integralFilter.cpp
new file mode 100644
index 0000000..093f4e3
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_integralFilter.cpp
@@ -0,0 +1,250 @@
+/***************************************************
+Author : Tanmay Chaudhari
+ ***************************************************/
+
+#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"
+ // #include "../common.cpp"
+
+ int opencv_integralFilter(char *fname, unsigned long fname_len)
+ {
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int i, j, k;
+ int iType = 0;
+ int iComplex = 0;
+ int rowsOfintImage = 0;
+ int colsOfintImage = 0;
+ int rowsOfBbox = 0;
+ int rowsOfWeights = 0;
+ int colsOfBbox = 0;
+ int colsOfWeights = 0;
+ int rowsOfFilter = 0;
+ int colsOfFilter = 0;
+ int sR = 0;
+ int sC = 0;
+ int eR = 0;
+ int eC = 0;
+ int *piAddr = NULL;
+ int *outSize = NULL;
+ double bboxSum = 0;
+ double *integralFilter = NULL;
+ double *intImage = NULL;
+ double *bbox = NULL;
+ double *weights = NULL;
+ double *filterSize = NULL;
+
+ //Check input output argument
+ checkInputArgument(pvApiCtx, 4, 4);
+ checkOutputArgument(pvApiCtx, 1, 1);
+
+ //Get variable address of the first input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfintImage, &colsOfintImage, &intImage);
+ if(sciErr.iErr || rowsOfintImage == 0 || colsOfintImage == 0)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get variable address of the second input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfBbox, &colsOfBbox, &bbox);
+ if(sciErr.iErr || colsOfBbox != 4 || rowsOfBbox == 0)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get variable address of the third input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfWeights, &colsOfWeights, &weights);
+ if(sciErr.iErr || colsOfWeights == 0 || rowsOfWeights != 1 || colsOfWeights != rowsOfBbox)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get variable address of the fourth input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfFilter, &colsOfFilter, &filterSize);
+ if(sciErr.iErr || colsOfFilter != 2 || rowsOfFilter != 1)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ outSize = (int*)malloc(sizeof(int) * 2);
+ if(filterSize[0] != 0 && filterSize[1] != 0)
+ {
+ outSize[0] = rowsOfintImage - filterSize[0];
+ outSize[1] = colsOfintImage - filterSize[1];
+ }
+ else
+ {
+ outSize[0] = rowsOfintImage - 1;
+ outSize[1] = colsOfintImage - 1;
+ }
+
+ if(outSize[0] <= 0 || outSize[1] <= 0)
+ outSize[0] = outSize[1] = 0;
+
+ integralFilter = (double*)malloc(sizeof(double) * outSize[0] * outSize[1]);
+
+ for( i = 0; i < outSize[0] * outSize[1]; i++)
+ integralFilter[i] = 0;
+
+ for( i = 1; i <= outSize[1]; i++)
+ {
+ for( j = 1; j <= outSize[0]; j++)
+ {
+ for( k = 0; k < rowsOfBbox; k++)
+ {
+ sR = j + bbox[1 * rowsOfBbox + k] - 1;
+ sC = i + bbox[0 * rowsOfBbox + k] - 1;
+ eR = sR + bbox[3 * rowsOfBbox + k];
+ eC = sC + bbox[2 * rowsOfBbox + k];
+
+ bboxSum = intImage[(eC - 1) * rowsOfintImage + (eR - 1)] - intImage[(sC - 1) * rowsOfintImage + (eR - 1)];
+ bboxSum -= intImage[(eC - 1) * rowsOfintImage + (sR - 1)];
+ bboxSum += intImage[(sC - 1) * rowsOfintImage + (sR - 1)];
+
+ integralFilter[(j - 1) * outSize[1] + (i - 1)] = integralFilter[(j - 1) * outSize[1] + (i - 1)] + weights[k] * bboxSum;
+ }
+ }
+ }
+
+ //Creating list to store integral filter in it
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, outSize[0], outSize[1], integralFilter);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Return output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_integralImage.cpp b/sci_gateway1/cpp/opencv_integralImage.cpp
new file mode 100644
index 0000000..b40e268
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_integralImage.cpp
@@ -0,0 +1,153 @@
+/***************************************************
+Author : Tanmay Chaudhari
+***************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <bits/stdc++.h>
+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"
+ // #include "../common.cpp"
+
+int opencv_integralImage(char *fname, unsigned long fname_len)
+{
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int nbInputArguments = 0;
+ int iRows = 0;
+ int iCols = 0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int tilted = 0;
+ char **pstData = NULL;
+ double *integralImage;
+ Mat image, sum, sqsum, tiltedsum;
+
+ //Check input output arguments
+ checkInputArgument(pvApiCtx, 1, 2);
+ checkOutputArgument(pvApiCtx, 1, 1);
+
+ nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ //getting input arguments
+ retrieveImage(image, 1);
+
+ if(nbInputArguments == 2)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp(pstData[0],"upright")==0)
+ tilted=0;
+ else if(strcmp(pstData[0],"rotated")==0)
+ tilted=1;
+ else
+ {
+ Scierror(999, "Error: Please provide proper value for \"%s\". Permissible values are upright or rotated.\n", pstData[0]);
+ return 0;
+ }
+ }
+
+ integral(image,sum,sqsum,tiltedsum);
+
+ if(tilted==0)
+ {
+ integralImage = (double*)malloc(sizeof(double) * int(sum.rows) * int(sum.cols));
+ for(int i=0;i<sum.rows;i++)
+ {
+ for(int j=0;j<sum.cols;j++)
+ {
+ integralImage[j*int(sum.rows)+i] = sum.at<int>(i,j);
+ }
+ }
+ }
+ else
+ {
+ integralImage = (double*)malloc(sizeof(double) * int(sum.rows) * (int(sum.cols)+1));
+ for(int i=0;i<sum.rows;i++)
+ {
+ for(int j=0;j<=sum.cols;j++)
+ {
+ integralImage[j*sum.rows+i]=0;
+ }
+ }
+ for(int i=0;i<sum.rows;i++)
+ {
+ for(int j=0;j<sum.cols;j++)
+ {
+ integralImage[j*int(sum.rows)+i] = tiltedsum.at<int>(i,j);
+ }
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(tilted==0)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, int(sum.rows), int(sum.cols), integralImage);
+ else
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, int(sum.rows), int(sum.cols)+1, integralImage);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Return output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_integralKernel.cpp b/sci_gateway1/cpp/opencv_integralKernel.cpp
new file mode 100644
index 0000000..5dfabf3
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_integralKernel.cpp
@@ -0,0 +1,251 @@
+/***************************************************
+Author : Tanmay Chaudhari
+ ***************************************************/
+
+#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"
+ // #include "../common.cpp"
+
+ int opencv_integralKernel(char *fname, unsigned long fname_len)
+ {
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int i, j, k;
+ int iType = 0;
+ int iComplex = 0;
+ int rowsOfBbox = 0;
+ int rowsOfWeights = 0;
+ int colsOfBbox = 0;
+ int colsOfWeights = 0;
+ int *piAddr = NULL;
+ double *filterSize = NULL;
+ double *hlSize = NULL;
+ double *ulCorner = NULL;
+ double *lrCorner = NULL;
+ double *centre = NULL;
+ double sR = 0;
+ double sC = 0;
+ double eR = 0;
+ double eC = 0;
+ double *coefficients = NULL;
+ double *bbox = NULL;
+ double *weights = NULL;
+
+ //Check input output argument
+ checkInputArgument(pvApiCtx, 2, 2);
+ checkOutputArgument(pvApiCtx, 5, 5);
+
+ //Get variable address of the first input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfBbox, &colsOfBbox, &bbox);
+ if(sciErr.iErr || colsOfBbox != 4 || rowsOfBbox == 0)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get variable address of the second input arguent
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rowsOfWeights, &colsOfWeights, &weights);
+ if(sciErr.iErr || colsOfWeights == 0 || rowsOfWeights != 1 || colsOfWeights != rowsOfBbox)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Creating list to storing bouding boxes
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, rowsOfBbox, colsOfBbox, bbox);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Creating list to store weights
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 2, piAddr, 1, rowsOfWeights, colsOfWeights, weights);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Computing filter size
+ filterSize = (double*)malloc(sizeof(double) * 2);
+ hlSize = (double*)malloc(sizeof(double) * 2);
+ ulCorner = (double*)malloc(sizeof(double) * 2);
+ lrCorner = (double*)malloc(sizeof(double) * 2);
+
+ filterSize[0] = filterSize[1] = 0;
+ for( i = 0 ; i < rowsOfBbox; i++)
+ {
+ hlSize[0] = bbox[3 * rowsOfBbox + i];
+ hlSize[1] = bbox[2 * rowsOfBbox + i];
+
+ ulCorner[0] = bbox[1 * rowsOfBbox + i];
+ ulCorner[1] = bbox[0 * rowsOfBbox + i];
+
+ lrCorner[0] = ulCorner[0] + hlSize[0] - 1;
+ lrCorner[1] = ulCorner[1] + hlSize[1] - 1;
+
+ if(filterSize[0] < lrCorner[0])
+ filterSize[0] = lrCorner[0];
+ if(filterSize[1] < lrCorner[1])
+ filterSize[1] = lrCorner[1];
+ }
+
+ //Computing coefficient matrix
+ coefficients = (double*)malloc(sizeof(double) * int(filterSize[0]) * int(filterSize[1]));
+ for( i = 0; i < int(filterSize[0]) * int(filterSize[1]); i++)
+ coefficients[i] = 0;
+
+ for( i = 0; i < rowsOfBbox; i++)
+ {
+ sR = bbox[1 * rowsOfBbox + i];
+ sC = bbox[0 * rowsOfBbox + i];
+ eR = sR + bbox[3 * rowsOfBbox + i] - 1;
+ eC = sC + bbox[2 * rowsOfBbox + i] - 1;
+
+ for( j = sR - 1; j < eR; j++)
+ for( k = sC - 1; k < eC; k++)
+ coefficients[k * int(filterSize[0]) + j] += weights[i];
+ }
+
+ //Computing centre of filter
+ centre = (double*)malloc(sizeof(double) * 2);
+ centre[0] = ceil(filterSize[0]/2.0);
+ centre[1] = ceil(filterSize[1]/2.0);
+
+ //Storing coefficient matrix in list
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 3, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 3, piAddr, 1, int(filterSize[0]), int(filterSize[1]), coefficients);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Storing centre of filter in list
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 4, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 4, piAddr, 1, 1, 2, centre);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Storing size of filter in list
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 5, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 5, piAddr, 1, 1, 2, filterSize);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Return output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx) + 3;
+ AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx) + 4;
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_isEpipoleInImage.cpp b/sci_gateway1/cpp/opencv_isEpipoleInImage.cpp
new file mode 100644
index 0000000..8663032
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_isEpipoleInImage.cpp
@@ -0,0 +1,164 @@
+/********************************************************
+Author: Suraj Prakash
+[isepi, epipole] = isEpipoleInImage(fundamental_matrix, imagesize)
+********************************************************/
+
+#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_isEpipoleInImage(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j, n = 0;
+
+ int iRows = 0;
+ int iCols = 0;
+
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+
+ double *pdblReal = NULL;
+ double *imagesize = NULL;
+
+ int isepi = 0;
+ double *epipole = NULL;
+ double inf = 1e17;
+ /// take the fundamental matrix
+ Mat fundamental_matrix(3, 3, CV_64F);
+
+ epipole = (double*)malloc(sizeof(double*) * 2);
+ memset(epipole, 0, 2);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows != 3 and iCols != 3){
+ Scierror(999, "Incorrect dimension of martrix for argument\n");
+ return 0;
+ }
+
+ for(i = 0; i < 3; ++i)
+ for(j = 0; j < 3; ++j)
+ fundamental_matrix.at<double>(i, j) = pdblReal[i + j * 3];
+
+
+ /// Get image size
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows != 1 and iCols != 2){
+ Scierror(999, "Invalid array for imagesize provided\n");
+ return 0;
+ }
+
+ imagesize = (double*)malloc(sizeof(double) * 2);
+ imagesize[0] = pdblReal[0];
+ imagesize[1] = pdblReal[1];
+
+ /// compute the SVD of the matrix provided
+ Mat w, u, vt;
+ SVD::compute(fundamental_matrix, w, u, vt);
+
+ transpose(vt, vt);
+
+ /// getting the last column of the vt
+ Mat epipoleHmg(1, 3, CV_64F);
+
+ epipoleHmg.at<double>(0,0) = vt.at<double>(0, 2);
+ epipoleHmg.at<double>(0,1) = vt.at<double>(1, 2);
+ epipoleHmg.at<double>(0,2) = vt.at<double>(2, 2);
+
+
+ if(epipoleHmg.at<double>(0,2) != 0){
+ /// location of epipolecl
+
+ epipole[0] = epipoleHmg.at<double>(0, 0) / epipoleHmg.at<double>(0, 2);
+ epipole[1] = epipoleHmg.at<double>(0, 1) / epipoleHmg.at<double>(0, 2);
+
+ double *imageOrigin = NULL;
+ imageOrigin = (double*)malloc(sizeof(double) * 2);
+ memset(imageOrigin, 0.5, 2);
+
+ double *imageEnd = NULL;
+ imageEnd = (double*)malloc(sizeof(double) * 2);
+ memset(imageEnd, 0, 2);
+
+ /// imageend = imageorigin + imagesize(::-1)
+ imageEnd[0] = imageOrigin[0] + imagesize[1];
+ imageEnd[1] = imageOrigin[1] + imagesize[0];
+
+ if(epipole[0] >= imageOrigin[0] and epipole[1] >= imageOrigin[1] and epipole[0] <= imageEnd[0] and epipole[1] <= imageEnd[1])
+ isepi = 1;
+ else
+ isepi = 0;
+ }
+
+ else{
+ epipole[0] = epipoleHmg.at<double>(0, 0) > 0 ? inf : -inf;
+ epipole[1] = epipoleHmg.at<double>(0, 1) > 0 ? inf : -inf;
+ }
+
+
+
+
+
+ int iRet = createScalarBoolean(pvApiCtx, nbInputArgument(pvApiCtx) + 1, isepi);
+ if(iRet){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, 1, 2, epipole);
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_isfilter.cpp b/sci_gateway1/cpp/opencv_isfilter.cpp
new file mode 100644
index 0000000..963ae0a
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_isfilter.cpp
@@ -0,0 +1,237 @@
+/*********************************************************************************
+*Author : Kevin George
+*
+*-> To execute, isfilter("Data",..,"Size",..)
+*
+*
+*********************************************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include <iostream>
+#include <math.h>
+#include <vector>
+
+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"
+ // # include "../common.cpp"
+
+ int opencv_isfilter(char *fname, unsigned long fname_len)
+ {
+ //-> Error Management variables
+ SciErr sciErr;
+ int intErr=0;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+
+ //-> Local variables
+ double size;
+ double *data = NULL;
+
+ Mat s;
+ Mat u;
+ Mat v;
+
+ int num_InputArgs; //-> gives total number of arguments
+ int iRows, iCols;
+ int *piLen = NULL;
+ char **pstData = NULL; //-> why double pointer?? and what is it
+ char *currentArg = NULL; //-> Stores current string representing 'name' of name,value pair arguments
+ bool *providedArgs = NULL; //-> Used to check that optional argument is not entered more than once
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ //-> Checks number of input and output arguments
+ CheckInputArgument(pvApiCtx, 4 , 4);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ //-> Count number of input arguments
+ num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ providedArgs = (bool*) malloc(sizeof(bool) * 2);
+
+//***************************************************** Getting Input Arguments *************************************************************
+ for(int iter = 1; iter<= num_InputArgs; iter++)
+ {
+ //-> Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Extracting name of next argument takes three calls to getMatrixOfString
+ //-> First call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ //-> Third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+
+
+//****************************************************** Name,Value - Data *****************************************************************
+
+ if(strcmp(currentArg, "Data")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &data);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /*if(iRows*iCols!=)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ } */
+
+ providedArgs[0] = 1;
+ }
+
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+ }
+
+//****************************************************** Name,Value - Size *****************************************************************
+ else if(strcmp(currentArg, "Size")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr, &size);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if( size < 0)
+ {
+ Scierror(999," Invalid Value for NumPyramidLevels. Please enter a non negative Double value\\n");
+ return 0;
+ }
+ providedArgs[1] = 1;
+ }
+
+ else if(providedArgs[1]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+ }
+
+ }
+//***************************************************** Actual Processing *************************************************************
+
+ int size2 = int(size);
+ float *kdata = new float[size2*size2];
+
+ for(int i = 0;i<size2*size2; i++)
+ {
+ kdata[i] = float(data[i]);
+ }
+
+ Mat kernel( size2, size2, CV_32F, kdata);
+ SVD::compute(kernel,s,u,v);
+
+ int count = 0;
+ for(int i = 0; i < s.rows; i++)
+ {
+ for(int j = 0; j < s.cols; j++)
+ {
+ if( s.at<float>(i,j) != 0)
+ count++;
+ }
+ }
+
+ if (count == 1)
+ sciprint("\nFilter is seperale\n");
+
+ else
+ sciprint("\nFilter is not seperale\n");
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+ } \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_laplacian.cpp b/sci_gateway1/cpp/opencv_laplacian.cpp
new file mode 100644
index 0000000..46ce129
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_laplacian.cpp
@@ -0,0 +1,156 @@
+/********************************************************
+ Author: Sukul Bagai
+*********************************************************
+ return_image = laplacian(input_image , depth , ksize , scale, delta);
+********************************************************/
+
+#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_laplacian(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ char **ddepth = NULL;
+ int i,j,k;
+ double ksize,scale,delta;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ddepth = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ ddepth[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, ddepth);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for value of ksize
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&ksize);
+ if(intErr)
+ return intErr;
+
+ //for value of scale
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&scale);
+ if(intErr)
+ return intErr;
+
+ //for value of delta
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&delta);
+ if(intErr)
+ return intErr;
+
+
+ Mat new_image(image.rows,image.cols,CV_8UC3);
+ if((int)ksize!=1 && (int)ksize!=3 && (int)ksize!=5 && (int)ksize!=7)
+ {
+ sciprint("Value of 1,3,5,7 Required for ksize. Default value of 3 was used instead");
+ ksize=3;
+ }
+
+ if(strcmp(ddepth[0],"CV_8U")==0)
+ Laplacian(image,new_image,CV_8U,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_16U")==0)
+ Laplacian(image,new_image,CV_16U,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_16S")==0)
+ Laplacian(image,new_image,CV_16S,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_32F")==0)
+ Laplacian(image,new_image,CV_32F,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_64F")==0)
+ Laplacian(image,new_image,CV_64F,ksize,scale,delta);
+ else
+ {
+ Laplacian(image,new_image,CV_8U,ksize,scale,delta);
+ sciprint("Wrong depth given,using CV_8U instead");
+ }
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_line.cpp b/sci_gateway1/cpp/opencv_line.cpp
new file mode 100644
index 0000000..c047381
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_line.cpp
@@ -0,0 +1,211 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ return_image = line(image , x1 , y1 , x2,y2,r_value,g_value,b_value,thickness,linetype,shift);
+********************************************************/
+
+#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_line(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int *piAddr9 = NULL;
+ int *piAddr10 = NULL;
+ int *piAddr11=NULL;
+ int i,j,k;
+ double thickness=1,linetype=8,shift=0 ,x1,y1,x2,y2,r_value,g_value,b_value;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 8, 11);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat src;
+ retrieveImage(src,1);
+
+ //for value of x coordinate of first point
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2 ,&x1);
+ if(intErr)
+ return intErr;
+
+ //for value of y coordinate of first point
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&y1);
+ if(intErr)
+ return intErr;
+
+ //for value of x coordinate of second point
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4 ,&x2);
+ if(intErr)
+ return intErr;
+
+ ///for value of y coordinate of second point
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5 ,&y2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //for value of R value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6 ,&r_value);
+ if(intErr)
+ return intErr;
+
+ // for G value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7 ,&g_value);
+ if(intErr)
+ return intErr;
+
+ // for B value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr8,&b_value);
+ if(intErr)
+ return intErr;
+
+ // for thickness of line default: 1
+ sciErr = getVarAddressFromPosition(pvApiCtx,9,&piAddr9);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr9,&thickness);
+ if(intErr)
+ return intErr;
+
+ //for line type of line default: 8
+ sciErr = getVarAddressFromPosition(pvApiCtx,10,&piAddr10);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr10 ,&linetype);
+ if(intErr)
+ return intErr;
+
+ // for shift in line defulat : 0
+ sciErr = getVarAddressFromPosition(pvApiCtx,11,&piAddr11);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Syntax: sciErr = getMatrixOfInteger8(pvApiCtx, piAddr8, &iRows8, &iCols8, &pcData);
+ intErr = getScalarDouble(pvApiCtx, piAddr11 ,&shift);
+ if(intErr)
+ return intErr;
+
+
+ //temporary pt variable, to use in function as centre
+ Point pt1(x1,y1);
+ Point pt2(x2,y2);
+ /// checking the parmeters for correct values
+ if( r_value <0 || r_value >255)
+ {
+ r_value=0;
+ sciprint(" r value of colour should be between 0 and 255 , using 0 instead");
+ }
+ if( g_value <0 || g_value >255)
+ {
+ g_value=0;
+ sciprint(" g value of colour should be between 0 and 255 , using 0 instead");
+ }
+ if( b_value <0 || b_value >255)
+ {
+ b_value=0;
+ sciprint(" b value of colour should be between 0 and 255 , using 0 instead");
+ }
+ if ((linetype!=0) && (linetype!=4)&& (linetype!=8))
+ {
+ linetype=8;
+ sciprint("Only 0/4/8 allowed , using 8 instead");
+ }
+
+//calling the opencv function
+ line( src, pt1, pt2, Scalar(b_value,g_value,r_value), thickness, linetype, shift);
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(src.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,src,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_matchFeatures.cpp b/sci_gateway1/cpp/opencv_matchFeatures.cpp
new file mode 100644
index 0000000..c8a35fd
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_matchFeatures.cpp
@@ -0,0 +1,490 @@
+/********************************************************************************************************************************************************************************************************
+* Author: Umang Agrawal *
+* Code: matchFeatures.cpp *
+* Function Format: [ index_Pairs_of_Matched_fetaures Metric ] = matchFeatures( feature_Vector_1, feature_Vector_2, Optional Arguments ) *
+* Optional Arguments: Name Value *
+* 'Method' [ 'Exhaustive' : 'Brute Force Matching', 'Approximate' : FANN Based Matching' ] *
+* 'Metric' [ 'SSD', 'SAD', 'Hamming', 'Hamming_2' ] *
+* 'Unique' [ Boolean True or False ] *
+* 'MatchThreshold' [ Percentage: 0 - 100 ] *
+********************************************************************************************************************************************************************************************************/
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+
+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_matchFeatures(char *fname, unsigned long fname_len)
+ {
+ // Error Handling
+ SciErr sciErr;
+
+ // Address of Various Scilab API
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+
+ // Number of input and output Arguments
+ int inputArguments = 0;
+
+ int Rows_1,Cols_1;
+ int Rows_2,Cols_2;
+
+ double *feature_1 = NULL;
+ double *feature_2 = NULL;
+
+ int iRows, iCols;
+ int *pilen = NULL;
+ char **arg = NULL;
+ char **method = NULL;
+ char **metric = NULL;
+ double unique = 0;
+ double thresh = 10;
+
+ int count_method = 0,count_metric = 0, count_unique = 0, count_thresh = 0;
+
+ double max_dist = 0, min_dist;
+ double *indexPairs = NULL;
+ double *matchMetric = NULL;
+
+ vector <DMatch> matches;
+ vector <DMatch> valid_m;
+
+ // Checks on Number of Input and Output Arguments
+ CheckInputArgument(pvApiCtx, 2, 10);
+ CheckOutputArgument(pvApiCtx, 1, 2);
+
+ inputArguments = *getNbInputArgument(pvApiCtx);
+
+ if( inputArguments%2 == 0 )
+ {
+ //Feature Matrix 1
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !isVarMatrixType(pvApiCtx, piAddr1))
+ {
+ Scierror(999,"Expecting a Matrix of MxN order containing the Binary Feature Set of Image 1 (Query Image)\n");
+ return 0;
+ }
+ if( !isDoubleType(pvApiCtx, piAddr1))
+ {
+ Scierror(999,"Feature Matrix should be of Double Type\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &Rows_1, &Cols_1, &feature_1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Feature Matrix 2
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if( !isVarMatrixType(pvApiCtx, piAddr2))
+ {
+ Scierror(999,"Expecting a Matrix of MxN order containing the Binary Feature Set of Image 1 (Query Image)\n");
+ return 0;
+ }
+ if( !isDoubleType(pvApiCtx, piAddr2))
+ {
+ Scierror(999,"Feature Matrix should be of Double Type\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &Rows_2, &Cols_2, &feature_2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ else
+ {
+ Scierror(999,"Required Arguments are Missing\n");
+ return 0;
+ }
+
+ for( int i=3; i<=inputArguments; i++)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr3))
+ {
+ Scierror(999, "%s: Wrong type of argument #%d. A string is expected.\n", fname, 1);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, pilen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(arg);
+ return 0;
+ }
+
+ if(strcmp(arg[0],"Method") == 0)
+ {
+ if(count_method != 0)
+ {
+ Scierror(999,"Method argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr4))
+ {
+ Scierror(999, "%s: Wrong type of value for Method Argument. A string is expected.\n");
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ method = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ method[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, pilen, method);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(method);
+ return 0;
+ }
+ i++;
+ count_method += 1;
+ }
+ else if(strcmp(arg[0],"Metric") == 0)
+ {
+ if(count_metric != 0)
+ {
+ Scierror(999,"Metric argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr4))
+ {
+ Scierror(999, "%s: Wrong type of Value for Metric Argument. A string is expected.\n");
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pilen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, pilen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ return 0;
+ }
+ metric = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ metric[j] = (char*)malloc(sizeof(char) * (pilen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, pilen, metric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(pilen);
+ free(metric);
+ return 0;
+ }
+ i++;
+ count_metric += 1;
+ }
+ else if(strcmp(arg[0],"Unique") == 0)
+ {
+ if(count_unique != 0)
+ {
+ Scierror(999,"Unique argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !(isDoubleType(pvApiCtx, piAddr4)) )
+ {
+ Scierror(999,"Unique Value must be a logic scalar\n");
+ return 0;
+ }
+ if(getScalarDouble(pvApiCtx, piAddr4, &unique))
+ {
+ Scierror(999,"Cannot Read Upright Value\n");
+ return 0;
+ }
+ if( !(int(unique)==0 || int(unique)==1) )
+ {
+ Scierror(999,"Unique Value must be a logic scalar\n");
+ return 0;
+ }
+ i++;
+ count_unique += 1;
+ }
+ else if(strcmp(arg[0],"MatchThreshold") == 0)
+ {
+ if(count_thresh != 0)
+ {
+ Scierror(999,"Match Threshold argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(pilen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !(isDoubleType(pvApiCtx, piAddr4)) )
+ {
+ Scierror(999,"Match Threshold Value must be a scalar Double\n");
+ return 0;
+ }
+ if(getScalarDouble(pvApiCtx, piAddr4, &thresh))
+ {
+ Scierror(999,"Cannot Read Threshold Value\n");
+ return 0;
+ }
+ if( !(thresh>0 && thresh<=100) )
+ {
+ Scierror(999,"Threshold Value must be in the range of 1 to 100\n");
+ return 0;
+ }
+ i++;
+ count_thresh += 1;
+ }
+ else
+ {
+ Scierror(999, "Invalid Argument Name. Provide Valid Arguments\n");
+ return 0;
+ }
+ }
+
+ if( count_metric == 0 )
+ {
+ metric = (char**)malloc(sizeof(char*) * 1 * 1);
+ metric[0] = (char*)malloc(sizeof(char) * 4);
+ strcpy(metric[0], "SSD");
+ }
+
+ if( count_method == 0)
+ {
+ method = (char**)malloc(sizeof(char*) * 1 * 1);
+ method[0] = (char*)malloc(sizeof(char) * 11);
+ strcpy(method[0], "Exhaustive");
+ }
+
+
+ if( strcmp(method[0],"Exhaustive") == 0)
+ {
+ Mat descriptor_1(Rows_1, Cols_1, CV_8UC1);
+ Mat descriptor_2(Rows_2, Cols_2, CV_8UC1);
+
+ for(int i=0; i<Rows_1; i++)
+ for(int j=0; j<Cols_1; j++)
+ {
+ descriptor_1.at<uchar>(i,j) = int(feature_1[j*Rows_1 + i]);
+ }
+
+ for(int i=0; i<Rows_2; i++)
+ for(int j=0; j<Cols_2; j++)
+ {
+ descriptor_2.at<uchar>(i,j) = int(feature_2[j*Rows_2 + i]);
+ }
+ if( strcmp(metric[0],"SSD") == 0)
+ {
+ BFMatcher matcher(NORM_L2, int(unique));
+ matcher.match(descriptor_1, descriptor_2, matches);
+ }
+ else if( strcmp(metric[0],"SAD") == 0)
+ {
+ BFMatcher matcher(NORM_L1, int(unique));
+ matcher.match(descriptor_1, descriptor_2, matches);
+ }
+ else if( strcmp(metric[0],"Hamming") == 0)
+ {
+ BFMatcher matcher(NORM_HAMMING, int(unique));
+ matcher.match(descriptor_1, descriptor_2, matches);
+ }
+ else if( strcmp(metric[0],"Hamming_2") == 0)
+ {
+ BFMatcher matcher(NORM_HAMMING2, int(unique));
+ matcher.match(descriptor_1, descriptor_2, matches);
+ }
+ else
+ {
+ Scierror(999,"Enter a Valid value for Metric Argument\n");
+ return 0;
+ }
+ }
+ else if( strcmp(method[0],"Approximate") == 0)
+ {
+ Mat descriptor_1(Rows_1, Cols_1, CV_32FC1);
+ Mat descriptor_2(Rows_2, Cols_2, CV_32FC1);
+
+ for(int i=0; i<Rows_1; i++)
+ for(int j=0; j<Cols_1; j++)
+ {
+ descriptor_1.at<float>(i,j) = float(feature_1[j*Rows_1 + i]);
+ }
+
+ for(int i=0; i<Rows_2; i++)
+ for(int j=0; j<Cols_2; j++)
+ {
+ descriptor_2.at<float>(i,j) = float(feature_2[j*Rows_2 + i]);
+ }
+ FlannBasedMatcher matcher;
+ matcher.match(descriptor_1,descriptor_2,matches);
+ }
+ else
+ {
+ Scierror(999,"Enter a Valid value for Method Argument\n");
+ return 0;
+ }
+
+ for( int i=0; i<matches.size(); i++ )
+ {
+ double dist = matches[i].distance;
+ if( dist > max_dist )
+ max_dist = dist;
+ }
+ min_dist = (thresh * max_dist)/100;
+
+ for( int i=0; i<matches.size(); i++)
+ {
+ if( matches[i].distance >= min_dist)
+ valid_m.push_back(matches[i]);
+ }
+ indexPairs = (double*)malloc(sizeof(double) * valid_m.size() * 2);
+ for( int i=0; i<valid_m.size(); i++)
+ {
+ indexPairs[i] = valid_m[i].queryIdx+1;
+ indexPairs[valid_m.size() + i] = valid_m[i].trainIdx+1;
+ }
+
+ matchMetric = (double*)malloc(sizeof(double) * valid_m.size());
+ for( int i=0; i<valid_m.size(); i++)
+ {
+ matchMetric[i] = valid_m[i].distance;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, valid_m.size(), 2, indexPairs);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, valid_m.size(), 1, matchMetric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+
+ free(method);
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_medianblur.cpp b/sci_gateway1/cpp/opencv_medianblur.cpp
new file mode 100644
index 0000000..8886af5
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_medianblur.cpp
@@ -0,0 +1,81 @@
+/********************************************************
+ Author: Sukul Bagai
+********************************************************/
+
+#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_medianblur(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int i,j,k;
+ double ksize;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+ //for value of ksize
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &ksize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ Mat new_image(image.rows,image.cols,CV_8UC3);
+
+ //checking input parameters
+ if((int)ksize != 1 && (int)ksize != 3 && (int)ksize != 5 && (int)ksize != 7)
+ {
+ sciprint("Value of 1,3,5,7 Required for ksize. Default value of 3 was used instead");
+ ksize = 3;
+ }
+ medianBlur(image,new_image,ksize);
+
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_montage.cpp b/sci_gateway1/cpp/opencv_montage.cpp
new file mode 100644
index 0000000..fcb66d7
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_montage.cpp
@@ -0,0 +1,216 @@
+/***************************************************
+Author : Sukul Bagai
+***************************************************/
+
+#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_montage(char *fname, unsigned long fname_len)
+{
+ SciErr sciErr;
+ int iLen = 0;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddrChild = NULL;
+ int *piAddrNew = NULL;
+ int piRows = 0;
+ int piCols = 0;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ int **pstData1 = NULL;
+ int i,j,k=0,iItem=0,height,width,intErr=0;
+ double new_rows,new_cols;
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ vector <Mat> image;
+ Mat tempimage;
+
+
+ //Checking number of input and output arguments (enviromnet variable, min arguments, max arguments)
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx,piAddr,&iItem);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int x=0;x<iItem;x++)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemAddress(pvApiCtx,piAddr,x+1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddrChild, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemAddress(pvApiCtx,piAddr,x+1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddrChild, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemAddress(pvApiCtx,piAddr,x+1,&piAddrChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfUnsignedInteger8InList(pvApiCtx, piAddrChild, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ tempimage = Mat(iRows,iCols,CV_8UC3);
+ k=0;
+ for(i=0;i<iRows;i++)
+ {
+ for(j=0;j<iCols;j++)
+ {
+ tempimage.at<Vec3b>(i,j)[2]=pstDataR[k];
+ tempimage.at<Vec3b>(i,j)[1]=pstDataG[k];
+ tempimage.at<Vec3b>(i,j)[0]=pstDataB[k++];
+ }
+ }
+ image.push_back(tempimage);
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &new_rows);
+ if(intErr)
+ return intErr;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &new_cols);
+ if(intErr)
+ return intErr;
+
+ for(i=1;i<iItem;i++)
+ {
+ if((image[i].rows != image[i-1].rows) || (image[i].cols != image[i-1].cols))
+ {
+ sciprint("Images not of same size. Montage did not take place\n");
+ }
+ }
+ if( ((new_rows-1)*new_cols >= iItem) || ((new_rows*new_cols) < iItem) )
+ {
+ sciprint("Given Row and Column Dimensions do not match with number of images in list. Montage cannot be created. Please check arguments\n");
+ return 0;
+ }
+ height=new_rows*image[0].rows;
+ width=new_cols*image[0].cols;
+
+ Mat new_image = Mat::zeros(height,width,CV_8UC3);
+
+ k=0;
+ for(int x=0;x<new_rows;x++)
+ {
+ for(int y=0;y<new_cols;y++)
+ {/*
+ if((k)>=iItem)
+ {
+ new_image.at<Vec3b>(image[0].rows*x+i,image[0].cols*y+j)[2]=black_image.at<Vec3b>(i,j)[2];
+ new_image.at<Vec3b>(image[0].rows*x+i,image[0].cols*y+j)[1]=black_image.at<Vec3b>(i,j)[1];
+ new_image.at<Vec3b>(image[0].rows*x+i,image[0].cols*y+j)[0]=black_image.at<Vec3b>(i,j)[0];
+ }*/
+ if(k<iItem)
+ {
+ for(i=0;i<image[x+y].rows;i++)
+ {
+ for(j=0;j<image[x+y].cols;j++)
+ {
+ new_image.at<Vec3b>(image[k].rows*x+i,image[k].cols*y+j)[2]=image[k].at<Vec3b>(i,j)[2];
+ new_image.at<Vec3b>(image[k].rows*x+i,image[k].cols*y+j)[1]=image[k].at<Vec3b>(i,j)[1];
+ new_image.at<Vec3b>(image[k].rows*x+i,image[k].cols*y+j)[0]=image[k].at<Vec3b>(i,j)[0];
+ }
+ }
+ }
+ k++;
+ }
+ }
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_morphologyEx.cpp b/sci_gateway1/cpp/opencv_morphologyEx.cpp
new file mode 100644
index 0000000..cc1666a
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_morphologyEx.cpp
@@ -0,0 +1,232 @@
+/***************************************************
+Author : Sukul Bagai
+****************************************************
+Usage : return_image = morphologyEx(input_image,"<op>",kernel_matrix,anchor_x,anchor_y,iterations,"<bordertype>");
+***************************************************/
+
+#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_morphologyEx(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ char **op = NULL;
+ char **borderType = NULL;
+ int i,j,k;
+ double *kernel,anchorX,anchorY,iterations,border;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 7, 7);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for op
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ op = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ op[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, op);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for kernel matrix
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols ,&kernel);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ int n=iRows;
+ double kernelArray[n][n];
+ //assigning values to actual kernelMatrix
+ for(i=0;i<n;i++)
+ for(j=0;j<n;j++)
+ kernelArray[i][j]=kernel[(i*n)+j];
+ // converting the array to a matrix, so that we can pass it into the filter2D function
+ Mat kernelMatrix(n, n, CV_32FC1, &kernelArray);
+
+ //for value of anchorX
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &anchorX);
+ if(intErr)
+ return intErr;
+
+ //for value of anchorY
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &anchorY);
+ if(intErr)
+ return intErr;
+
+ //for value of iterations
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &iterations);
+ if(intErr)
+ return intErr;
+
+ //for border
+ sciErr = getVarAddressFromPosition(pvApiCtx,7, &piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr7, &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, piAddr7, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr7, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //error check
+ if(anchorX >= n || anchorY >=n)
+ {
+ sciprint("Invalid anchor point given. Centre point (-1,-1) was used instead");
+ anchorY = -1;
+ anchorX = -1;
+ }
+ Mat new_image(image.rows,image.cols,image.type());
+ Point pt(anchorX,anchorY);
+
+ int actualop;
+
+ if(strcmp(op[0],"MORPH_OPEN")==0)
+ actualop=MORPH_OPEN;
+ else if(strcmp(op[0],"MORPH_CLOSE")==0)
+ actualop=MORPH_CLOSE;
+ else if(strcmp(op[0],"MORPH_GRADIENT")==0)
+ actualop=MORPH_GRADIENT;
+ else if(strcmp(op[0],"MORPH_TOPHAT")==0)
+ actualop=MORPH_TOPHAT;
+ else if(strcmp(op[0],"MORPH_BLACKHAT")==0)
+ actualop=MORPH_BLACKHAT;
+ else
+ {
+ sciprint("Invalid type %s used. MORPH_OPEN was used instead by default",op[0]);
+ actualop = MORPH_OPEN;
+ }
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0)
+ border = BORDER_CONSTANT;
+ else if(strcmp(borderType[0], "BORDER_REPLICATE") == 0)
+ border = BORDER_REPLICATE;
+ else if(strcmp(borderType[0], "BORDER_REFLECT") == 0)
+ border = BORDER_REFLECT;
+ else if(strcmp(borderType[0], "BORDER_REFLECT_101") == 0)
+ border = BORDER_REFLECT_101;
+ else if(strcmp(borderType[0], "BORDER_WRAP") == 0)
+ border = BORDER_WRAP;
+ else
+ border = BORDER_DEFAULT;
+
+ //applying function
+ filter2D(image,new_image,actualop,kernelMatrix,pt,iterations,border);
+
+ //returning image
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_ocr.cpp b/sci_gateway1/cpp/opencv_ocr.cpp
new file mode 100644
index 0000000..dc1dc6d
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_ocr.cpp
@@ -0,0 +1,175 @@
+/***************************************************
+Author : Rohit Suri
+TODO : Extract confidences for each character
+ : Calculate Position of words
+***************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include <iostream>
+#include <tesseract/baseapi.h>
+using namespace cv;
+using namespace std;
+using namespace tesseract;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+ #include "../common.h"
+
+ /*Calling syntax: ocr(I) */
+
+ int opencv_ocr(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+
+ //------Local variables------//
+ Mat sourceImage;
+ TessBaseAPI tesseract;
+ int *wordConfidences = NULL;
+ int wordCount = 0, characterCount = 0, count=0, coordinate;
+ string word="";
+ char *text = NULL;
+ char **words = NULL;
+ char *boxInformation = NULL;
+ int *characterBoundingBoxes = NULL;
+ int characterBoundingBoxesPos = 0;
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 4);
+
+ //------Get input arguments------//
+ retrieveImage(sourceImage, 1);
+
+ //------Actual processing------//
+
+ tesseract.Init(NULL, "eng", OEM_TESSERACT_ONLY);
+ tesseract.SetPageSegMode(PSM_SINGLE_BLOCK);
+ tesseract.SetVariable("tessedit_char_whitelist","0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-_=+[]{}:'\";\|,.<>/");
+ tesseract.SetImage(sourceImage.data, sourceImage.cols, sourceImage.rows, sourceImage.elemSize(), sourceImage.step);
+ wordConfidences = tesseract.AllWordConfidences();
+ boxInformation = tesseract.GetBoxText(0);
+ for(int iter = 0; ;iter++)
+ {
+ if(wordConfidences[iter]!=-1)
+ {
+ wordCount++;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ words = (char**) malloc(sizeof(char*)*wordCount);
+ text = tesseract.GetUTF8Text();
+ for(int iter = 0; count < wordCount; iter++)
+ {
+
+ if(count == wordCount)
+ {
+ break;
+ }
+ if(text[iter]==' ' || text[iter]=='\n')
+ {
+ words[count] = (char*) malloc(sizeof(char)*word.length()+1);
+ for(int char_iter=0; char_iter<word.length();char_iter++)
+ {
+ words[count][char_iter] = word[char_iter];
+ }
+ words[count][word.length()] = '\0';
+ word = "";
+ count++;
+
+ }
+ else
+ {
+ characterCount++;
+ word = word + text[iter];
+ }
+ }
+ characterBoundingBoxes = (int*) malloc(sizeof(int)*characterCount*4);
+
+ for( int iter = 0; characterBoundingBoxesPos < characterCount ; iter++)
+ {
+ while( boxInformation[iter]!=' ')
+ {
+ iter++;
+ }
+ iter++;
+ coordinate = 0;
+ while(boxInformation[iter]!=' ')
+ {
+ coordinate = 10 * coordinate + boxInformation[iter] - '0';
+ iter++;
+ }
+ characterBoundingBoxes [characterBoundingBoxesPos] = coordinate;
+ coordinate = 0;
+ iter++;
+ while(boxInformation[iter]!=' ')
+ {
+ coordinate = 10 * coordinate + boxInformation[iter] - '0';
+ iter++;
+ }
+ characterBoundingBoxes [characterCount + characterBoundingBoxesPos] = coordinate;
+ coordinate = 0;
+ iter++;
+ while(boxInformation[iter]!=' ')
+ {
+ coordinate = 10 * coordinate + boxInformation[iter] - '0';
+ iter++;
+ }
+ characterBoundingBoxes [2 * characterCount + characterBoundingBoxesPos] = coordinate;
+ coordinate = 0;
+ iter++;
+ while(boxInformation[iter]!=' ')
+ {
+ coordinate = 10 * coordinate + boxInformation[iter] - '0';
+ iter++;
+ }
+ characterBoundingBoxes [3 * characterCount + characterBoundingBoxesPos] = coordinate;
+ characterBoundingBoxesPos++;
+ iter+=2;
+ }
+ //------Create output arguments------//
+ sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, 1, &text);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 2, characterCount, 4, characterBoundingBoxes);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 3, wordCount, 1, words);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32(pvApiCtx, nbInputArgument(pvApiCtx) + 4, wordCount, 1, wordConfidences);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx)+2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx)+3;
+ AssignOutputVariable(pvApiCtx, 4) = nbInputArgument(pvApiCtx)+4;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_opticalFlowFarneback.cpp b/sci_gateway1/cpp/opencv_opticalFlowFarneback.cpp
new file mode 100644
index 0000000..c6001f0
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_opticalFlowFarneback.cpp
@@ -0,0 +1,553 @@
+/********************************************************************************************************
+ Author : Kevin George
+
+-> Syntax : opticalFlowFarneback("Filename",..,"NumPyramidLevels,..,"PyramidScale",..,
+ "Num_Iteration",..,"NeighborhoodSize",..,"FilterSize",..)
+
+-> First argument "FileName" is necessary,rest are optional
+*******************************************************************************************************/
+#include <stdio.h>
+#include <iostream>
+#include <opencv2/opencv.hpp>
+#include <opencv2/core/core.hpp>
+#include <opencv2/highgui/highgui.hpp>
+#include <opencv2/video/background_segm.hpp>
+#include <unistd.h>
+
+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"
+ // # include "../common.cpp"
+
+ //-> Name,Value Pair Variables
+ char *fileName = NULL; //-> Stores fileName
+ int NumPyramidLevels;
+ int NeighborhoodSize;
+ int NumIteration;
+ int FilterSize;
+ double PyramidScale;
+ bool objectStatus3 = false;
+
+ int opencv_opticalFlowFarneback ( char *fname, unsigned long fname_len)
+ {
+
+ //-> Error Management variables
+ SciErr sciErr;
+ int intErr=0;
+
+ //-> Mat containers for images
+ Mat image_1;
+ Mat image_2;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+
+ //-> Local variables
+ int num_InputArgs; //-> gives total number of arguments
+ int iRows, iCols;
+ int *piLen = NULL;
+ char **pstData = NULL; //-> why double pointer?? and what is it
+ char *currentArg = NULL; //-> Stores current string representing 'name' of name,value pair arguments
+ bool *providedArgs = NULL; //-> Used to check that optional argument is not entered more than once
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ //-> Checks number of input and output arguments
+ CheckInputArgument(pvApiCtx, 0 , 5);
+ CheckOutputArgument(pvApiCtx, 1, 5);
+
+ //-> Count number of input arguments
+ num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ providedArgs = (bool*) malloc(sizeof(bool) * 6);
+
+//************************************************ Retrieval of Name, Value Argument Pair *************************************************
+ for(int iter = 1; iter<= num_InputArgs; iter++)
+ {
+ //-> Getting address of next argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Extracting name of next argument takes three calls to getMatrixOfString
+ //-> First call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ //-> Third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+
+//****************************************************** Name,Value - NumPyramidLevels *****************************************************************
+
+ if(strcmp(currentArg, "FileName")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //-> Extracting name of next argument takes three calls to getMatrixOfString
+ //-> First call to get rows and columns
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &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, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ //-> Third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ fileName = pstData[0];
+ free(pstData);
+ iRows=0;
+ iCols=0;
+ free(piLen);
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else if(strcmp(currentArg, "NumPyramidLevels")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &NumPyramidLevels);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if( NumPyramidLevels < 0)
+ {
+ Scierror(999," Invalid Value for NumPyramidLevels. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[1] = 1;
+ }
+ else if(providedArgs[1]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+//****************************************************** Name,Value - PyramidScale *****************************************************************
+
+ else if(strcmp(currentArg, "PyramidScale")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddr))
+ {
+ Scierror(999," Invalid Value for PyramidScale. Please enter a non negative Double value\\n");
+ return 0;
+ }
+ getScalarDouble(pvApiCtx, piAddr, &PyramidScale);
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if( PyramidScale < 0)
+ {
+ Scierror(999," Invalid Value for NumPyramidLevels. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[2] = 1;
+ }
+
+ else if(providedArgs[2]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+
+ }
+
+//****************************************************** Name,Value - NumIteration *****************************************************************
+
+ else if(strcmp(currentArg, "NumIteration")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &NumIteration);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if( NumIteration < 0)
+ {
+ Scierror(999," Invalid Value for NumPyramidLevels. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[3] = 1;
+ }
+
+ else if(providedArgs[3]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+//****************************************************** Name,Value - NeighborhoodSize *****************************************************************
+
+ else if(strcmp(currentArg, "NeighborhoodSize")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[4])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &NeighborhoodSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if( NeighborhoodSize < 0)
+ {
+ Scierror(999," Invalid Value for size of pixel Neighborhood. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[4] = 1;
+ }
+
+ else if(providedArgs[4]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+//****************************************************** Name,Value - FilterSize *****************************************************************
+
+ else if(strcmp(currentArg, "FilterSize")==0)
+ {
+ if(iter+1<= num_InputArgs && !providedArgs[5])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarInteger32(pvApiCtx, piAddr, &FilterSize);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ //-> Checking if values are in proper range. Same for all optional arguments
+ if( FilterSize < 0)
+ {
+ Scierror(999," Invalid Value for size of pixel Neighborhood. Please enter a non negative Double value\\n");
+ return 0;
+ }
+
+ providedArgs[5] = 1;
+ }
+
+ else if(providedArgs[5]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ else
+ {
+ Scierror(999, "Incorrect Name type. Please re-enter the correct Name-Value pair arguments\n");
+ return 0;
+ }
+
+ }//-> Braces for ending of long for loop
+
+//******************************************************** Giving Default Arguments *******************************************************************
+
+ if(providedArgs[0] == 0)
+ {
+ NumPyramidLevels = 3;
+ }
+
+
+ if(providedArgs[1] == 0)
+ {
+ PyramidScale = 0.5;
+ }
+
+ if(providedArgs[2] == 0)
+ {
+ NumIteration = 3;
+ }
+
+ if(providedArgs[3] == 0)
+ {
+ NeighborhoodSize = 5;
+ }
+
+ if(providedArgs[4] == 0)
+ {
+ FilterSize = 15;
+ }
+//**************************************************************Actual Processing*******************************************************************************
+
+ objectStatus3 = true;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+ int opencv_readopticalFlowFarneback(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int *outList = NULL;
+ unsigned char *red = NULL;
+ unsigned char *green = NULL;
+ unsigned char *blue = NULL;
+
+ if(!objectStatus3)
+ {
+ Scierror(999,"Set up Foreground Detection properties through ForegroundDetection() first.\n");
+ return 0;
+ }
+
+ Mat image_prev, image_next, flow, GetImg, cflow;
+ int s = 2;
+ //char fileName[100] = "ped.avi";
+ //VideoCapture stream1(fileName);
+
+ //if(!(stream1.read(GetImg))) //get one frame from video
+ // return 0;
+
+ retrieveImage(GetImg,1);
+
+ resize(GetImg, image_prev, Size(GetImg.size().width/s, GetImg.size().height/s) );
+ cvtColor(image_prev, image_prev, CV_BGR2GRAY);
+
+ //namedWindow( "prvs", WINDOW_NORMAL);
+ //namedWindow( "next", WINDOW_NORMAL);
+ namedWindow( "OpticalFlowFarneback", WINDOW_NORMAL);
+
+ //while(true)
+ //{
+ //if(!(stream1.read(GetImg))) //get one frame from video
+ // break;
+
+ retrieveImage(GetImg,2);
+ //-> Resize
+ resize(GetImg, image_next, Size(GetImg.size().width/s, GetImg.size().height/s) );
+ cvtColor(image_next, image_next, CV_BGR2GRAY);
+
+ calcOpticalFlowFarneback(image_prev,image_next, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
+
+ cvtColor(image_prev, cflow, CV_GRAY2BGR);
+
+ //drawOptFlowMap(flow, cflow, 10, CV_RGB(0, 255, 0));
+ int step = 10;
+ for(int y = 0; y < cflow.rows; y += step)
+ {
+ for(int x = 0; x < cflow.cols; x += step)
+ {
+ const Point2f& fxy = flow.at< Point2f>(y, x);
+ line(cflow, Point(x,y), Point(cvRound(x+fxy.x), cvRound(y+fxy.y)),
+ CV_RGB(0, 255, 0) );
+ //circle(cflowmap, Point(cvRound(x+fxy.x), cvRound(y+fxy.y)), 1, color, -1);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red = (unsigned char *)malloc(sizeof(unsigned char)*cflow.rows*cflow.cols);
+ green = (unsigned char *)malloc(sizeof(unsigned char)*cflow.rows*cflow.cols);
+ blue = (unsigned char *)malloc(sizeof(unsigned char)*cflow.rows*cflow.cols);
+
+ for(int k=0;k<cflow.rows;k++)
+ {
+ for(int p=0;p<cflow.cols;p++)
+ {
+ Vec3b intensity = cflow.at<Vec3b>(k, p);
+ red[k+cflow.rows*p]=intensity.val[2];
+ green[k+cflow.rows*p]=intensity.val[1];
+ blue[k+cflow.rows*p]=intensity.val[0];
+ }
+ }
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, cflow.rows, cflow.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 2, cflow.rows, cflow.cols, green);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 3, cflow.rows, cflow.cols, blue);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ free(green);
+ free(blue);
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ //imshow("OpticalFlowFarneback", cflow);
+
+ //->Display
+ //imshow("prvs", image_prev);
+ //imshow("next", image_next);
+
+ //if (waitKey(5) >= 0)
+ // break;
+
+ // image_prev = image_next.clone();
+ // sleep(0.5);
+ //}
+
+
+ }
+
+ } \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_partition.cpp b/sci_gateway1/cpp/opencv_partition.cpp
new file mode 100644
index 0000000..0c8d37f
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_partition.cpp
@@ -0,0 +1,488 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <string.h>
+#include <iostream>
+#include <stdlib.h>
+#include <time.h>
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+
+ /* Calling syntax: [set1,set2,...,setN] = partition(imgSet,groupSizes)
+ [set1,set2,...,setN] = partition(imgSet,groupPercentages)
+ [set1,set2,...,setN] = partition(___,method) */
+
+ double findSum(double *array, int n)
+ {
+ double sum = 0;
+ for(int iter=0; iter<n; iter++)
+ {
+ sum+= array[iter];
+ }
+ return sum;
+ }
+
+ int opencv_partition(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+
+ //------Local variables------//
+ int *parentAddr = NULL;
+ int *piAddr = NULL;
+ int *piLen = NULL;
+ int *piChild = NULL;
+ int *piGrandChild = NULL;
+ char **pstData = NULL;
+ int iRows, iCols;
+
+ char *objectType = "imageSet";
+ bool randomized = 0; // 0 for sequential and 1 for randomized method
+ bool sizeProvided; // 0 if percentage and 1 if size provided
+ bool zeroWarning = 0;
+ double *groupSizesOrPercentages = NULL;
+ char **description = NULL;
+ int *count = NULL;
+ int *tempCount = NULL;
+ char ***location = NULL;
+ int **countOutput = NULL;
+ int **locationIndex = NULL;
+ char ***locationOutput = NULL;
+ int descriptionCount, partitionCount;
+ double sumOfSizesOrPercentages;
+ double groupSizesOrPercentagesSum = 0;
+ int index;
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 2, 3);
+ // Output Arguments checked later
+
+ //------Get input arguments------//
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr))
+ {
+ Scierror(999, "Error: Invalid first argument. List Expected.\n");
+ return 0;
+ }
+
+ // Extracting object type and checking if type is imageSet
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"imageSet")==0))
+ {
+ Scierror(999, "Error: The input argument is not of type imageSet.\n");
+ return 0;
+ }
+
+ // Extracting Description attribute of input argument
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ description = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ description[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ descriptionCount = iRows;
+
+ // Extracting Count attribute of input argument
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ location = (char***) malloc(sizeof(char**) * descriptionCount);
+ sciErr = getListItemAddress(pvApiCtx, piAddr, 4, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int iter = 1; iter<=descriptionCount; iter++)
+ {
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ location[iter-1] = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int colIter = 0 ; colIter < iRows * iCols ; colIter++)
+ {
+ location[iter-1][colIter] = (char*)malloc(sizeof(char) * (piLen[colIter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, location[iter-1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &groupSizesOrPercentages);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iCols == 0)
+ {
+ Scierror(999, "Error: Please provide a proper groupSizes vector.\n");
+ return 0;
+ }
+ if(iRows!=1)
+ {
+ Scierror(999, "Error: A one dimensional column vector expected.\n");
+ return 0;
+ }
+ partitionCount = iCols+1;
+ CheckOutputArgument(pvApiCtx, 1, partitionCount);
+
+ if(*getNbInputArgument(pvApiCtx) == 3)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(strcmp("sequential",pstData[0])==0)
+ {
+ randomized = 0;
+ }
+ else if(strcmp("randomized",pstData[0])==0)
+ {
+ randomized = 1;
+ }
+ else
+ {
+ Scierror(999, "Error: Argument \"%s\" is not valid.\n",pstData[0]);
+ return 0;
+ }
+ }
+
+ sumOfSizesOrPercentages = findSum(groupSizesOrPercentages,partitionCount);
+ if(groupSizesOrPercentages[0]>0 && groupSizesOrPercentages[0]<1)
+ {
+ sizeProvided = 0;
+ }
+ else if(groupSizesOrPercentages[0]>=1)
+ {
+ sizeProvided = 1;
+ }
+ else
+ {
+ Scierror(999, "Error: Please enter positive values groupSizes argument.\n");
+ return 0;
+ }
+ for(int iter = 0; iter<partitionCount-1;iter++)
+ {
+ if(sizeProvided && (groupSizesOrPercentages[iter]<1 || groupSizesOrPercentages[iter] - (int)groupSizesOrPercentages[iter]!=0))
+ {
+ Scierror(999, "Error: Please enter positive whole number values for groupSizes argument.\n");
+ return 0;
+ }
+ else if(!sizeProvided && (groupSizesOrPercentages[iter]<=0 || groupSizesOrPercentages[iter]>=1))
+ {
+ Scierror(999, "Error: Please enter proper groupPercentages argument. Values should lie between 0-1.\n");
+ return 0;
+ }
+ groupSizesOrPercentagesSum+=groupSizesOrPercentages[iter];
+ }
+ if(!sizeProvided && groupSizesOrPercentagesSum>1)
+ {
+ Scierror(999, "Error: Sum of values of groupPercentages should be less than or equal to one. \n");
+ return 0;
+ }
+ if(sizeProvided)
+ {
+ for(int iter = 0; iter<descriptionCount; iter++)
+ {
+ if(count[iter]<groupSizesOrPercentagesSum)
+ {
+ Scierror(999, "Error: The sum of groupSizes arguments cannot be greater than the size of any imageSet object.");
+ return 0;
+ }
+ }
+ }
+
+ //------Actual processing------//
+ double temp;
+ countOutput = (int**) malloc(sizeof(int*) * partitionCount);
+ tempCount = (int*) malloc(sizeof(int) * descriptionCount);
+ locationIndex = (int**) malloc(sizeof(int*) * descriptionCount);
+ for(int iter = 0 ; iter<descriptionCount; iter++)
+ {
+ locationIndex[iter] = (int*) malloc(sizeof(int) * count[iter]);
+ tempCount[iter] = count[iter];
+ }
+ for(int iter=0;iter<partitionCount-1; iter++)
+ {
+ countOutput[iter] = (int*) malloc(sizeof(int) * descriptionCount);
+ for(int iter2 = 0; iter2<descriptionCount; iter2++)
+ {
+ if(sizeProvided)
+ {
+ temp = groupSizesOrPercentages[iter];
+ }
+ else
+ {
+ temp = groupSizesOrPercentages[iter] * count[iter2];
+ if(temp - (int)temp >= 0.5)
+ {
+ temp = (int)temp + 1;
+ }
+ else
+ {
+ temp = (int)temp;
+ }
+ }
+ if(tempCount[iter2]==0)
+ {
+ countOutput[iter][iter2] = 0;
+ }
+ else if(tempCount[iter2]-temp<=0)
+ {
+ countOutput[iter][iter2] = tempCount[iter2];
+ tempCount[iter2] = 0;
+ zeroWarning = 1;
+ }
+ else
+ {
+ if(temp==0)
+ {
+ zeroWarning = 1;
+ }
+ countOutput[iter][iter2] = temp;
+ tempCount[iter2] -= temp;
+ }
+ }
+ }
+ countOutput[partitionCount-1] = (int*) malloc(sizeof(int) * descriptionCount);
+ for(int iter = 0; iter<descriptionCount; iter++)
+ {
+ countOutput[partitionCount-1][iter] = tempCount[iter];
+ }
+ for(int iter = 0;iter<descriptionCount;iter++)
+ {
+ for(int iter2=0;iter2<count[iter];iter2++)
+ {
+ locationIndex[iter][iter2] = 0;
+ }
+ }
+ if(randomized)
+ {
+ srand(time(NULL));
+ for(int iter = 0; iter < partitionCount; iter++)
+ {
+ for(int iter2 = 0; iter2 <descriptionCount; iter2++)
+ {
+ temp = countOutput[iter][iter2];
+ while(temp!=0)
+ {
+ index = rand() % count[iter2];
+ if(locationIndex[iter2][index]==0)
+ {
+ locationIndex[iter2][index] = iter+1;
+ temp--;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ for(int iter = 0; iter < partitionCount; iter++)
+ {
+ for(int iter2 = 0; iter2 <descriptionCount; iter2++)
+ {
+ temp = countOutput[iter][iter2];
+ index = 0;
+ while(temp!=0)
+ {
+ if(locationIndex[iter2][index]==0)
+ {
+ locationIndex[iter2][index] = iter+1;
+ temp--;
+ }
+ index++;
+ }
+ }
+ }
+ }
+ if(zeroWarning)
+ {
+ sciprint("Warning: One or more sets may have zero images.\n");
+ }
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, partitionCount, &parentAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //------Create output arguments------//
+ for(int iter=1;iter<=partitionCount;iter++)
+ {
+ sciErr = createListInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, parentAddr, iter, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 1, 1, 1, &objectType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 2, descriptionCount, 1, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfInteger32InList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 3, descriptionCount, 1, countOutput[iter-1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createListInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 4, descriptionCount, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ locationOutput = (char***) malloc(sizeof(char**) * descriptionCount);
+ for(int i=0;i<descriptionCount;i++)
+ {
+ locationOutput[i] = (char**) malloc(sizeof(char*) * countOutput[iter-1][i]);
+ index = 0;
+ for(int j=0;j<count[i];j++)
+ {
+ if(locationIndex[i][j]==iter)
+ {
+ locationOutput[i][index] = (char*) malloc(sizeof(char) * (strlen(location[i][j])+1));
+ strncpy(locationOutput[i][index], location[i][j], strlen(location[i][j])+1);
+ index++;
+ }
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piChild, i+1, countOutput[iter-1][i], 1, locationOutput[i]);
+ }
+ }
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_peopleDetector.cpp b/sci_gateway1/cpp/opencv_peopleDetector.cpp
new file mode 100644
index 0000000..ef8dd5f
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_peopleDetector.cpp
@@ -0,0 +1,468 @@
+/********************************************************
+Author: Suraj Prakash
+[bboxes] = peopleDetector(image)
+
+// 1->image
+
+Optional arguments :
+
+// 2->hitThreshold
+// 3->winStride
+// 4->padding
+// 5->scale
+// 6->finalThreshold
+// 7->useMeanshiftGrouping
+
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+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_peopleDetector(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j;
+ int intErr;
+ int iRows = 0;
+ int iCols = 0;
+ int iRows1 = 0;
+ int iCols1 = 0;
+
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+
+ double hitThreshold = 0;
+ double scale = 1.05;
+ double *winStride = NULL;
+ double *padding = NULL;
+ double finalThreshold = 2.0;
+ int useMeanshiftGrouping = 0;
+
+ double *bboxes = NULL;
+
+
+ /// for the Hog_SVM_Detector
+ HOGDescriptor hog;
+
+ /// found -> for the found rectangles
+ /// found_filtered -> the size of the rectangles found is usually greater so, the rectangles are filtered out
+ /// bboxes in matlab correspond to found_filtered in this code
+ /// answer to hold the modified rectangle after filtering
+ vector< Rect > found, found_filtered, answer;
+
+ /// checking input argument
+ // 1->image
+ // 2->hitThreshold
+ // 3->winStride
+ // 4->padding
+ // 5->scale
+ // 6->finalThreshold
+ // 7->useMeanshiftGrouping
+
+
+ CheckInputArgument(pvApiCtx, 1, 13);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ /// retrieve image
+ Mat image;
+ retrieveImage(image, 1);
+
+ /// Train hog detector for people
+ /// Default training is 48 * 96 people images
+ /// can be used for detection of larger instances
+
+
+ /// For the optional arguments
+ int nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+ providedArgs = (bool*) malloc(sizeof(bool) * 5);
+ memset(providedArgs, 0, 5);
+
+ winStride = (double*)malloc(sizeof(double) * 2);
+ winStride[0] = 8;
+ winStride[1] = 8;
+
+ padding = (double*)malloc(sizeof(double) * 2);
+ padding[0] = 16;
+ padding[1] = 16;
+
+
+ for(int iter = 2; iter <= nbInputArguments; ++iter){
+
+ /// Address of next argument
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int k = 0; k < iRows * iCols; ++k)
+ {
+ pstData[k] = (char*) malloc(sizeof(char) * piLen[k] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+
+ /// getting hit_threshold
+ if(strcmp(currentArg, "hitThreshold") == 0)
+ {
+ if(iter + 1 <= nbInputArguments and !providedArgs[0])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &hitThreshold);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(hitThreshold < 0)
+ {
+ Scierror(999, "Error: Nonnegative hitThreshold only allowed\n");
+ return 0;
+ }
+ providedArgs[0] = 1;
+ }
+ else if(providedArgs[0]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ /// WindowStride
+ if(strcmp(currentArg, "winStride") == 0)
+ {
+ if(iter+1 <= nbInputArguments && !providedArgs[1])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows1, &iCols1, &winStride);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows1 != 1 or iCols1 != 2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument .\n");
+ return 0;
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[1] = 1;
+ }
+ else if(providedArgs[1]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ /// Padding
+ if(strcmp(currentArg, "padding") == 0)
+ {
+ if(iter+1 <= nbInputArguments and !providedArgs[2])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows1, &iCols1, &padding);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows1 != 1 or iCols1 != 2)
+ {
+ Scierror(999, "Incorrect dimension of matrix for argument .\n");
+ return 0;
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[2] = 1;
+ }
+ else if(providedArgs[2]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ /// Scalefactor
+ if(strcmp(currentArg, "scale") == 0)
+ {
+ if(iter + 1 <= nbInputArguments and !providedArgs[3])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &scale);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // Checking if values are in proper range. Same for all optional arguments
+ if(scale < 1.0001)
+ {
+ Scierror(999, "Error: Wrong ScaleFactor given. Cannot be less than 1.0001\n");
+
+ return 0;
+ }
+ providedArgs[3] = 1;
+ }
+ else if(providedArgs[3]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+
+
+ /// finalThreshold
+ if(strcmp(currentArg, "finalThreshold") == 0)
+ {
+ if(iter + 1 <= nbInputArguments and !providedArgs[4])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr, &finalThreshold);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if(finalThreshold < 0)
+ {
+ Scierror(999, "Incorrect value for argument .\n");
+ return 0;
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[4] = 1;
+ }
+ else if(providedArgs[4]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ /// UseMeanshiftGrouping
+ if(strcmp(currentArg, "useMeanshiftGrouping")==0)
+ {
+ if(iter + 1 <= nbInputArguments and !providedArgs[5])
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarBoolean(pvApiCtx, piAddr, &useMeanshiftGrouping);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(useMeanshiftGrouping > 1 or useMeanshiftGrouping < 0)
+ {
+ Scierror(999, "Incorrect value for argument .\n");
+ return 0;
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[5] = 1;
+ }
+ else if(providedArgs[5]) // Send an error message if an argument is provided more than once. Same for all optional arguments.
+ {
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+ else // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+ {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ }
+
+ /// End of error check and input get;
+
+ hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
+
+ ///virtual void cv::HOGDescriptor::detectMultiScale
+ // ( InputArray img,
+ // std::vector< Rect > & foundLocations,
+ // double hitThreshold = 0,
+ // Size winStride = Size(),
+ // Size padding = Size(),
+ // double scale = 1.05,
+ // double finalThreshold = 2.0,
+ // bool useMeanshiftGrouping = false
+ // )
+
+ hog.detectMultiScale(image, found, hitThreshold, Size(winStride[0], winStride[1]), Size(padding[0], padding[0]), scale, finalThreshold, useMeanshiftGrouping);
+
+ /// finding out the rectangles
+
+ for (i = 0; i < found.size(); ++i){
+ Rect r = found[i];
+ for (j = 0; j < found.size(); ++j)
+ /// removing same identified people
+ if (j != i and (r & found[j]) == r)
+ break;
+
+ /// if no duplicate found
+ if (j == found.size())
+ found_filtered.push_back(r);
+ }
+
+ /// filtering out the rectangles
+ for (i=0; i<found_filtered.size(); i++){
+ Rect r = found_filtered[i];
+
+ r.x += cvRound(r.width*0.1);
+ r.y += cvRound(r.height*0.06);
+
+ r.width = cvRound(r.width*0.8);
+ r.height = cvRound(r.height*0.9);
+
+ answer.push_back(r);
+ }
+
+ /// bboxex[i] = [x y width height];
+ bboxes = (double*)malloc(sizeof(double) * (int)answer.size() * 4);
+
+ int total_boxes = (int)answer.size();
+
+ for(i = 0; i < answer.size(); ++i){
+ Rect temp = answer[i];
+
+ // x coordinate
+ bboxes[i + 0 * total_boxes] = temp.x;
+
+ // y coordinate
+ bboxes[i + 1 * total_boxes] = temp.y;
+
+ // width
+ bboxes[i + 2 * total_boxes] = temp.width;
+
+ // height
+ bboxes[i + 3 * total_boxes] = temp.height;
+ }
+
+
+
+ // rows // columns
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, total_boxes, 4, bboxes);
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_predict.cpp b/sci_gateway1/cpp/opencv_predict.cpp
new file mode 100644
index 0000000..51b9710
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_predict.cpp
@@ -0,0 +1,222 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <iostream>
+#include <opencv2/opencv.hpp>
+#include <opencv2/nonfree/nonfree.hpp>
+#include <opencv2/ml/ml.hpp>
+
+using namespace std;
+using namespace cv;
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+ #include "../common.h"
+ int opencv_predict(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+
+ //------Local variables------//
+ int upright = 1;
+ Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
+ Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor(1, 4, 2, 1, int(upright));
+ BOWImgDescriptorExtractor bowDE(extractor, matcher);
+ SurfFeatureDetector detector(1, 4, 2, 1, int(upright));
+ char *classifierLocation = NULL;
+ Mat dictionary,features;
+ double response;
+ vector<KeyPoint> keyPoints;
+ CvSVM svm;
+ int dictionarySize;
+ int *piAddr = NULL;
+ int *piChild = NULL;
+ int iRows, iCols;
+ char **pstData = NULL;
+ int *piLen = NULL;
+ char **classifierDescription = NULL;
+ int classifierDescriptionCount;
+ char *bagOfFeaturesLocation = NULL;
+ int descriptionCount;
+ Mat input;
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ //------Get input arguments------//
+ retrieveImage(input,2);
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr))
+ {
+ Scierror(999, "Error: The input argument #1 is not of type classifier.\n");
+ return 0;
+ }
+
+ // Extracting object type and checking if type is classifier
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"classifier")==0))
+ {
+ Scierror(999, "Error: The input argument #1 is not of type classifier.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=1 || iCols!=1)
+ {
+ Scierror(999, "1x1 Matrix expected for classifier argument.");
+ return 0;
+ }
+ classifierLocation = pstData[0];
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 3, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 3, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 3, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=1 || iCols!=1)
+ {
+ Scierror(999, "1x1 Matrix expected for bagOfFeatures argument.");
+ return 0;
+ }
+ bagOfFeaturesLocation = pstData[0];
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 4, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 4, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ classifierDescription = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ classifierDescription[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 4, &iRows, &iCols, piLen, classifierDescription);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //------Actual processing------//
+ FileStorage fs(bagOfFeaturesLocation, FileStorage::READ);
+ fs["dictionary"] >> dictionary;
+ fs.release();
+ dictionarySize = dictionary.rows;
+ bowDE.setVocabulary(dictionary);
+ svm.load(classifierLocation);
+ detector.detect(input, keyPoints);
+ bowDE.compute(input, keyPoints, features);
+ response = svm.predict(features);
+ //------Create output arguments------//
+ sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx)+1, 1, 1, &classifierDescription[(int)response]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_projectPoints.cpp b/sci_gateway1/cpp/opencv_projectPoints.cpp
new file mode 100644
index 0000000..d242875
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_projectPoints.cpp
@@ -0,0 +1,256 @@
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/calib3d/calib3d.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_projectPoints(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iComplex = 0;
+ int iType = 0;
+ int *piAddr = NULL;
+ int i,size,j;
+ double *worldPoints=NULL,*rVector=NULL,*tVector=NULL,*intrinsicMatrix=NULL,*distCoefficients=NULL;
+ int wpRows,wpCols,rvRows,rvCols,tvRows,tvCols,imRows,imCols,dcRows,dcCols;
+ double *points=NULL;
+
+ vector<cv::Point3d> objectPoints;
+ vector<cv::Point2d> imagePoints;
+ Mat intrisicMat(3, 3, cv::DataType<double>::type);
+ Mat rVec(3, 1, cv::DataType<double>::type);
+ Mat tVec(3, 1, cv::DataType<double>::type);
+ Mat distCoeffs(5, 1, cv::DataType<double>::type);
+
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &wpRows, &wpCols, &worldPoints);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(wpCols!=2)
+ {
+ Scierror(999, "%s: Wrong value for input argument: World points must be M*2\n");
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &rvRows, &rvCols, &rVector);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(rvCols!=3)
+ {
+
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &tvRows, &tvCols, &tVector);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(tvCols!=3)
+ {
+
+ }
+ if(rvRows!=tvRows)
+ {
+
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &imRows, &imCols, &intrinsicMatrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(imRows!=3 || imCols!=3)
+ {
+
+ }
+
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &dcRows, &dcCols, &distCoefficients);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(dcRows!=1 || dcCols!=3)
+ {
+
+ }
+
+ for(i=0;i<wpRows;++i)
+ {
+ objectPoints.push_back(cv::Point3d(worldPoints[i],worldPoints[i+wpRows],0));
+ }
+
+ intrisicMat.at<double>(0, 0) = intrinsicMatrix[0];
+ intrisicMat.at<double>(1, 0) = 0;
+ intrisicMat.at<double>(2, 0) = 0;
+
+ intrisicMat.at<double>(0, 1) = 0;
+ intrisicMat.at<double>(1, 1) = intrinsicMatrix[4];
+ intrisicMat.at<double>(2, 1) = 0;
+
+ intrisicMat.at<double>(0, 2) = intrinsicMatrix[2];
+ intrisicMat.at<double>(1, 2) = intrinsicMatrix[5];
+ intrisicMat.at<double>(2, 2) = 1;
+
+ rVec.at<double>(0) = rVector[0];
+ rVec.at<double>(1) = rVector[1];
+ rVec.at<double>(2) = rVector[2];
+
+ tVec.at<double>(0) = tVector[0];
+ tVec.at<double>(1) = tVector[1];
+ tVec.at<double>(2) = tVector[2];
+
+ distCoeffs.at<double>(0) = distCoefficients[0];
+ distCoeffs.at<double>(1) = distCoefficients[1];
+ distCoeffs.at<double>(2) = distCoefficients[2];
+ distCoeffs.at<double>(3) = distCoefficients[3];
+ if(dcCols==5)
+ {
+ distCoeffs.at<double>(4) = distCoefficients[4];
+ }
+
+ //Actual process
+ projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, imagePoints);
+ size=imagePoints.size();
+ points = (double*) malloc(sizeof(double) * size * 2);
+ for(i = 0 ; i < size ; i++)
+ {
+ points[i] = imagePoints[i].x;
+ points[i+size] = imagePoints[i].y;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, size , 2, points);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway1/cpp/opencv_puttext.cpp b/sci_gateway1/cpp/opencv_puttext.cpp
new file mode 100644
index 0000000..97bf62c
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_puttext.cpp
@@ -0,0 +1,311 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ return_image = puttext(image ,x1 ,y1 ,fontscale,r_value,g_value,b_value,text,fontface ,thickness,linetype,bottomleft(0/1));
+********************************************************/
+
+#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_puttext(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piLen2 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int *piAddr9 = NULL;
+ int *piAddr10 = NULL;
+ int *piAddr11 = NULL;
+ int *piAddr12 = NULL;
+ int i,j,k , bottom , fontFace;
+ char **fontface = NULL,**text= NULL;
+ double thickness=1 ,linetype=8,bottomleft ;
+ double x1,y1,fontscale,r_value,g_value,b_value;
+ bool bottomLeftOrigin;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 9, 12);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat src;
+ retrieveImage(src,1);
+
+ //for value of x coordinate of point of bootom-left corner of the text string
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2,&x1);
+ if(intErr)
+ return intErr;
+
+ //for value of y coordinate of point of bootom-left corner of the text string
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&y1);
+ if(intErr)
+ return intErr;
+
+ //for value of fontscale
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&fontscale);
+ if(intErr)
+ return intErr;
+
+ //for value of R value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5,&r_value);
+ if(intErr)
+ return intErr;
+
+ //for value of G value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6 ,&g_value);
+ if(intErr)
+ return intErr;
+
+ //for value of Bvalue of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7 ,&b_value);
+ if(intErr)
+ return intErr;
+
+ /// for text to be written on the image
+ //Syntax : SciErr getMatrixOfString(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, int* _piLength, char** _pstStrings)
+ //fisrt call to retrieve dimensions
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr8, &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, piAddr8, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ text = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ text[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr8, &iRows, &iCols, piLen, text);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ///for the fontface of text
+ sciErr = getVarAddressFromPosition(pvApiCtx,9,&piAddr9);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr9, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen2 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr9, &iRows, &iCols, piLen2, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ fontface = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ fontface[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr9, &iRows, &iCols, piLen2, fontface);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // for thickness of text
+ sciErr = getVarAddressFromPosition(pvApiCtx,10,&piAddr10);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr10,&thickness);
+ if(intErr)
+ return intErr;
+
+ //for line type of text default: 8
+ sciErr = getVarAddressFromPosition(pvApiCtx,11,&piAddr11);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr11,&linetype);
+ if(intErr)
+ return intErr;
+
+ // for shift in line defulat : 0
+ sciErr = getVarAddressFromPosition(pvApiCtx,12,&piAddr12);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr12,&bottomleft);
+ if(intErr)
+ return intErr;
+
+
+ if (bottomleft == 0)
+ bottomLeftOrigin = false;
+ else if (bottomleft == 1)
+ bottomLeftOrigin = true;
+ else
+ {
+ bottomLeftOrigin = false;
+ sciprint("Only 0 and 1 acceptable , taking false instead");
+ }
+ /// setting fontface FONT_HERSHEY_SIMPLEX, FONT_HERSHEY_PLAIN, FONT_HERSHEY_DUPLEX, FONT_HERSHEY_COMPLEX, FONT_HERSHEY_TRIPLEX, FONT_HERSHEY_COMPLEX_SMALL,
+ // FONT_HERSHEY_SCRIPT_SIMPLEX, or FONT_HERSHEY_SCRIPT_COMPLEX,
+ if(strcmp(fontface[0],"FONT_HERSHEY_SIMPLEX")==0)
+ fontFace = FONT_HERSHEY_SIMPLEX;
+ else if (strcmp(fontface[0],"FONT_HERSHEY_PLAIN")==0)
+ fontFace= FONT_HERSHEY_PLAIN;
+ else if (strcmp(fontface[0],"FONT_HERSHEY_DUPLEX")==0)
+ fontFace= FONT_HERSHEY_DUPLEX;
+ else if (strcmp(fontface[0],"FONT_HERSHEY_COMPLEX")==0)
+ fontFace= FONT_HERSHEY_COMPLEX;
+ else if (strcmp(fontface[0],"FONT_HERSHEY_TRIPLEX")==0)
+ fontFace = FONT_HERSHEY_TRIPLEX;
+ else if (strcmp(fontface[0],"FONT_HERSHEY_COMPLEX_SMALL")==0)
+ fontFace = FONT_HERSHEY_COMPLEX_SMALL;
+ else if (strcmp(fontface[0],"FONT_HERSHEY_SCRIPT_SIMPLEX")==0)
+ fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX;
+ else if (strcmp(fontface[0],"FONT_HERSHEY_SCRIPT_COMPLEX")==0)
+ fontFace = FONT_HERSHEY_SCRIPT_COMPLEX;
+ else
+ {
+ sciprint("Invalid fontface given. FONT_HERSHEY_PLAIN was used instead");
+ fontFace = FONT_HERSHEY_PLAIN;
+ }
+ //temporary pt variable, to use in function as bottom left corner
+ Point pt1(x1,y1);
+ /// checking the parmeters for correct values
+ if( r_value <0 || r_value >255)
+ {
+ r_value=0;
+ sciprint(" r value of colour should be between 0 and 255 , using 0 instead");
+ }
+ if( g_value <0 || g_value >255)
+ {
+ g_value=0;
+ sciprint(" g value of colour should be between 0 and 255 , using 0 instead");
+ }
+ if( b_value <0 || b_value >255)
+ {
+ b_value=0;
+ sciprint(" b value of colour should be between 0 and 255 , using 0 instead");
+ }
+ if ((linetype!=0) && (linetype!=4)&& (linetype!=8))
+ {
+ linetype=8;
+ sciprint("Only 0/4/8 allowed , using 8 instead");
+ }
+
+
+
+ //syntax: putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin=false )
+ putText( src, text[0], pt1, fontFace, fontscale, Scalar(b_value,g_value,r_value), thickness, linetype, bottomLeftOrigin );
+
+ string tempstring = type2str(src.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,src,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_pyrDown.cpp b/sci_gateway1/cpp/opencv_pyrDown.cpp
new file mode 100644
index 0000000..7a8df72
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_pyrDown.cpp
@@ -0,0 +1,156 @@
+/***************************************************
+Author : Sukul Bagai
+****************************************************
+ return_image = pyrDown(input_image, dstsize_width, distsize_height, border;
+***************************************************/
+
+#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_pyrDown(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piLen = NULL;
+ char **borderType = NULL;
+ double dstsize_width,dstsize_height;
+ int border;
+ int i;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of dstsize_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &dstsize_width);
+ if(intErr)
+ return intErr;
+
+ //for value of dstsize_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&dstsize_height);
+ if(intErr)
+ return intErr;
+
+ //for border
+ sciErr = getVarAddressFromPosition(pvApiCtx,4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &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, piAddr4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //error checks
+ if(dstsize_height<0)
+ {
+ sciprint("Positive Value Required for Height. 1 value was used instead\n");
+ dstsize_height=1;
+ }
+ if(dstsize_width<0)
+ {
+ sciprint("Positive Value Required for Width. 1 value was used instead\n");
+ dstsize_width=1;
+ }
+ if((dstsize_width != image.cols*2) && (dstsize_width != image.cols*2+1) && (dstsize_width != image.cols*2-1))
+ {
+ sciprint("Incorrect dstsize_width value was used. src.cols*2+1 value was calculated and used instead\n");
+ dstsize_width = image.cols*2+1;
+ }
+ if((dstsize_height != image.rows*2) && (dstsize_height != image.rows*2+1) && (dstsize_height != image.rows*2-1))
+ {
+ sciprint("Incorrect dstsize_height value was used. src.rows*2+1 value was calculated and used instead\n");
+ dstsize_height = image.rows*2+1;
+ }
+
+ Mat new_image(dstsize_height,dstsize_width,image.type());
+
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0)
+ border = BORDER_CONSTANT;
+ else if(strcmp(borderType[0], "BORDER_REPLICATE") == 0)
+ border = BORDER_REPLICATE;
+ else if(strcmp(borderType[0], "BORDER_REFLECT") == 0)
+ border = BORDER_REFLECT;
+ else if(strcmp(borderType[0], "BORDER_REFLECT_101") == 0)
+ border = BORDER_REFLECT_101;
+ else if(strcmp(borderType[0], "BORDER_WRAP") == 0)
+ border = BORDER_WRAP;
+ else
+ border = BORDER_DEFAULT;
+
+ pyrDown(image,new_image,Size(dstsize_width,dstsize_height),border);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_pyrUp.cpp b/sci_gateway1/cpp/opencv_pyrUp.cpp
new file mode 100644
index 0000000..18459c3
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_pyrUp.cpp
@@ -0,0 +1,156 @@
+/***************************************************
+Author : Sukul Bagai
+****************************************************
+ return_image = pyrUp(input_image, dstsize_width, distsize_height, border;
+***************************************************/
+
+#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_pyrUp(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piLen = NULL;
+ char **borderType = NULL;
+ double dstsize_width,dstsize_height;
+ int border;
+ int i;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of dstsize_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &dstsize_width);
+ if(intErr)
+ return intErr;
+
+ //for value of dstsize_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&dstsize_height);
+ if(intErr)
+ return intErr;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,4, &piAddr4);
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &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, piAddr4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //error checks
+ if(dstsize_height<0)
+ {
+ sciprint("Positive Value Required for Height. 1 value was used instead\n");
+ dstsize_height=1;
+ }
+ if(dstsize_width<0)
+ {
+ sciprint("Positive Value Required for Width. 1 value was used instead\n");
+ dstsize_width=1;
+ }
+ if((dstsize_width != image.cols*2) && (dstsize_width != image.cols*2+1) && (dstsize_width != image.cols*2-1))
+ {
+ sciprint("Incorrect dstsize_width value was used. src.cols*2+1 value was calculated and used instead\n");
+ dstsize_width = image.cols*2+1;
+ }
+ if((dstsize_height != image.rows*2) && (dstsize_height != image.rows*2+1) && (dstsize_height != image.rows*2-1))
+ {
+ sciprint("Incorrect dstsize_height value was used. src.rows*2+1 value was calculated and used instead\n");
+ dstsize_height = image.rows*2+1;
+ }
+
+ Mat new_image(dstsize_height,dstsize_width,image.type());
+
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0)
+ border = BORDER_CONSTANT;
+ else if(strcmp(borderType[0], "BORDER_REPLICATE") == 0)
+ border = BORDER_REPLICATE;
+ else if(strcmp(borderType[0], "BORDER_REFLECT") == 0)
+ border = BORDER_REFLECT;
+ else if(strcmp(borderType[0], "BORDER_REFLECT_101") == 0)
+ border = BORDER_REFLECT_101;
+ else if(strcmp(borderType[0], "BORDER_WRAP") == 0)
+ border = BORDER_WRAP;
+ else
+ border = BORDER_DEFAULT;
+
+ pyrUp(image,new_image,Size(dstsize_width,dstsize_height),border);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_pyramid.cpp b/sci_gateway1/cpp/opencv_pyramid.cpp
new file mode 100644
index 0000000..a158a93
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_pyramid.cpp
@@ -0,0 +1,134 @@
+/********************************************************
+Author: Diwakar Bhardwaj
+*********************************************************
+Usage :return_image=pyramid(input_image,'direction',level)
+********************************************************/
+
+#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_pyramid(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piLen = NULL;
+ char **direction = NULL;
+ int i,j,k=0,l=0;
+ double alpha, beta,x,n;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ Mat image,new_image;
+
+ retrieveImage(image, 1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,2, &piAddr2);
+
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ direction = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ direction[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, direction);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3 ,&x);
+ if(intErr)
+ return intErr;
+ n=x;
+ k=image.rows;
+ l=image.cols;
+ while(n--)
+ {
+
+ //if expand operation is performed
+ if(strcmp(direction[0], "expand") == 0)
+ {
+ pyrUp(image, new_image, Size( image.cols*2, image.rows*2 ));
+ //Size size((k*2)-1,(l*2)-1);
+ //resize(image,new_image,size);
+ }
+
+
+ //if reduced operation is performed
+ else if(strcmp(direction[0], "reduce") == 0)
+ {
+ pyrDown( image, new_image, Size( image.cols/2, image.rows/2 ));
+ //Size size(k/2,l/2);
+ //resize(image,new_image,size);
+ }
+ image=new_image;
+
+ }
+
+
+
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_rectangle.cpp b/sci_gateway1/cpp/opencv_rectangle.cpp
new file mode 100644
index 0000000..36d24f0
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_rectangle.cpp
@@ -0,0 +1,207 @@
+/********************************************************
+ Author: Sukul Bagai
+*********************************************************
+ return_image = circle(input_image , x_coordinate_of_point1 , y_coordinate_point1, x_coordinate_of_point2 , y_coordinate_point2 , r_value,g_value,b_value,thickness,linetype,shift);
+********************************************************/
+
+#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_rectangle(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int *piAddr9 = NULL;
+ int *piAddr10 = NULL;
+ int *piAddr11 = NULL;
+ int i,j,k;
+ double thickness=1 , linetype=8,shift =0 ,point1_x ,point1_y,point2_x ,point2_y,r_value,g_value,b_value;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 11, 11);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat src;
+ retrieveImage(src,1);
+
+ //for value of x coordinate of point1
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2,&point1_x);
+ if(intErr)
+ return intErr;
+
+
+ //for value of y coordinate of point1
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&point1_y);
+ if(intErr)
+ return intErr;
+
+ //for value of x coordinate of point2
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4,&point2_x);
+ if(intErr)
+ return intErr;
+
+
+ //for value of y coordinate of point2
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5,&point2_y);
+ if(intErr)
+ return intErr;
+
+ //for value of R value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6 ,&r_value);
+ if(intErr)
+ return intErr;
+
+ //for value of G value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7 ,&g_value);
+ if(intErr)
+ return intErr;
+
+ // for B value of colour
+ sciErr = getVarAddressFromPosition(pvApiCtx,8,&piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr8,&b_value);
+ if(intErr)
+ return intErr;
+
+ // for thickness of circle default: 1
+ sciErr = getVarAddressFromPosition(pvApiCtx,9,&piAddr9);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr9,&thickness);
+ if(intErr)
+ return intErr;
+
+ //for line type of circle default: 8
+ sciErr = getVarAddressFromPosition(pvApiCtx,10,&piAddr10);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr10,&linetype);
+ if(intErr)
+ return intErr;
+
+ // for shift in circle defulat : 0
+ sciErr = getVarAddressFromPosition(pvApiCtx,11,&piAddr11);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr11,&shift);
+ if(intErr)
+ return intErr;
+
+ // checking the parmeters for correct values
+ if( r_value <0 || r_value >255)
+ {
+ r_value=0;
+ sciprint(" r value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( g_value <0 || g_value >255)
+ {
+ g_value=0;
+ sciprint(" g value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if( b_value <0 || b_value >255)
+ {
+ b_value=0;
+ sciprint(" b value of colour should be between 0 and 255 , using 0 instead\n");
+ }
+ if ((linetype!=0) && (linetype!=4)&& (linetype!=8))
+ {
+ linetype=8;
+ sciprint("Only 0/4/8 allowed , using 8 instead\n");
+ }
+
+ // Draw the circles detected
+ rectangle( src, Point(point1_x,point1_y), Point(point2_x,point2_y), Scalar(r_value,g_value,b_value), thickness, linetype, shift);
+
+//// sending the image
+ string tempstring = type2str(src.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,src,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+
+}
+
diff --git a/sci_gateway1/cpp/opencv_rectifyStereoImages.cpp b/sci_gateway1/cpp/opencv_rectifyStereoImages.cpp
new file mode 100644
index 0000000..6b26e27
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_rectifyStereoImages.cpp
@@ -0,0 +1,243 @@
+/********************************************************
+Author: Diwakar Bhardwaj
+*********************************************************
+Usage :[image1,image2] = rectifyStereoImages(input_image1,cameramatrix1,Distortion_coff1,input_image2,cameramatrix2,Distortioncoff2,Translationvector,Rotationvector)
+
+********************************************************/
+
+#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_rectifyStereoImages(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0,iRows2=0,iCols2=0,iRows3=0,iCols3=0,iRows4=0,iCols4=0,iRows5=0,iCols5=0;
+ int iRows6=0,iCols6=0,iRows7=0,iCols7=0,iRows8=0,iCols8=0,iRows9=0,iCols9=0,iRows10=0,iCols10=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ int *piAddr9 = NULL;
+ int *piAddr10 = NULL;
+ //stereoParams
+ double * D1real = NULL;//Distortion Matrix 5*1
+ double * M1real = NULL;//Camera Matrix 3*3
+ double * P1real = NULL;//Projection Matrix 3*3
+ double * R1real = NULL;//Rotation Matrix 3*3
+ double * D2real = NULL;//Distortion Matrix 5*1
+ double * M2real = NULL;//Camera Matrix 3*3
+ double * P2real = NULL;//Projection Matrix 3*3
+ double * R2real = NULL;//Rotation Matrix 3*3
+ double * Treal = NULL;//Translation vector 3*1
+ double * Rreal = NULL;//Rotation Matrix 3*3
+
+ Mat D1(5,1,CV_64F);
+ Mat M1(3,3,CV_64F);
+ Mat D2(5,1,CV_64F);
+ Mat M2(3,3,CV_64F);
+ Mat T (3,1,CV_64F);
+ Mat R (3,3,CV_64F);
+
+ CheckInputArgument(pvApiCtx, 8, 8);
+ CheckOutputArgument(pvApiCtx, 2, 2) ;
+
+ Mat image1,image2;
+ retrieveImage(image1,1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows2, &iCols2, &M1real);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows3, &iCols3, &D1real);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ retrieveImage(image2,4);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr5, &iRows5, &iCols5, &M2real);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, 6, &piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr6, &iRows6, &iCols6, &D2real);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, 7, &piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr7, &iRows7, &iCols7, &Treal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, 8, &piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr7, &iRows8, &iCols8, &Rreal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(iRows2!=3 and iCols2!=3 or iRows5!=3 and iCols5!=3)
+ {
+ sciprint("camera matrix must be size of 3*3");
+ }
+
+ if(iRows3!=1 and iCols3!=5 or iRows6!=1 and iCols6!=5)
+ {
+ sciprint("Distortion cofficient matrix must be size of 5*1");
+ }
+ if(iRows7!=1 and iCols7!=3)
+ {
+ sciprint("Translation vector must be 3*1");
+ }
+
+
+ if(iRows8!=3 and iCols8!=3)
+ {
+ sciprint("Rotation Matrix must be 3*3");
+ }
+
+ for(int i=0;i<3;i++)
+ for(int j=0;j<3;j++)
+ M1.at<double>(i,j)=M1real[i+j*3];
+
+ for(int i=0;i<5;i++)
+ for(int j=0; j<1; ++j)
+ D1.at<double>(i,j)=D1real[i+j*5];
+
+ for(int i=0;i<3;i++)
+ for(int j=0;j<3;j++)
+ M2.at<double>(i,j)=M2real[i+j*3];
+
+ for(int i=0;i<5;i++)
+ for(int j=0; j<1; ++j)
+ D2.at<double>(i,j)=D2real[i+j*5];
+
+ for(int i=0; i<3; ++i)
+ for(int j=0; j<1; ++j)
+ T.at<double>(i,j)=Treal[i+j*3];
+
+ for(int i=0;i<3;i++)
+ for(int j=0;j<3;j++)
+ R.at<double>(i,j)=Rreal[i+j*3];
+
+ Size imgSize(image1.rows*2,image1.cols*2);
+ Mat R1,R2,P1,P2,Q;
+
+ stereoRectify(M1,D1,M2,D2, imgSize, R, T, R1, R2,P1, P2, Q);
+
+
+ Mat left, right; //Create matrices for storing input images
+
+ // transformation and rectification maps
+ Mat camera1map1, camera1map2;
+ Mat camera2map1, camera2map2;
+
+ initUndistortRectifyMap(M1, D1, R1, P1, imgSize , CV_32F, camera1map1, camera1map2);
+ initUndistortRectifyMap(M2, D2, R2, P2, imgSize, CV_32F, camera2map1, camera2map2);
+
+ Mat leftStereoUndistorted, rightStereoUndistorted;
+ //Rectify and undistort images
+ remap(image1, left, camera1map1, camera1map2, INTER_LINEAR);
+ remap(image2, right, camera2map1, camera2map2, INTER_LINEAR);
+ /*Size size(image1.rows,image1.cols);
+ resize(image1,left,size);
+ Size size1(image2.rows,image2.cols);
+ resize(image2,right,size1);
+ Combining left and right rectified image in one image plane
+ Size sz1 = left.size();
+ Size sz2 = right.size();
+ Mat final_image (sz1.height, sz1.width+sz2.width, CV_8UC3);
+ final_image.adjustROI(0, 0, 0, -sz2.width);
+ left.copyTo(final_image);
+ final_image.adjustROI(0, 0, -sz1.width, sz2.width);
+ right.copyTo(final_image);
+ final_image.adjustROI(0, 0, sz1.width, 0);*/
+
+ int temp1 = nbInputArgument(pvApiCtx) + 1;
+ string tempstring1 = type2str(left.type());
+ char *checker1;
+ checker1 = (char *)malloc(tempstring1.size() + 1);
+ memcpy(checker1, tempstring1.c_str(), tempstring1.size() + 1);
+ returnImage(checker1,left,1);
+ free(checker1);
+
+ int temp2 = nbInputArgument(pvApiCtx) + 2;
+ string tempstring2 = type2str(right.type());
+ char *checker2;
+ checker2 = (char *)malloc(tempstring2.size() + 2);
+ memcpy(checker2, tempstring2.c_str(), tempstring2.size() + 2);
+ returnImage(checker2,right,2);
+ free(checker2);
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_retrieveImages.cpp b/sci_gateway1/cpp/opencv_retrieveImages.cpp
new file mode 100644
index 0000000..cace204
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_retrieveImages.cpp
@@ -0,0 +1,506 @@
+/********************************************************************************************************************************
+* Author: Umang Agrawal *
+* Code: reteieveImage.cpp *
+* Funtion Call: [ Index, Score, ImageWord ] = retrieveImage( QureyImage, IndexImage, OptionalArgument) *
+* Optional Argument: Name Value *
+* NumResults Any Value greater than 0 *
+* ROI [ x_coordinate y_coordinate width height ] *
+********************************************************************************************************************************/
+#include <iostream>
+#include <numeric>
+#include <vector>
+#include <string>
+#include "opencv2/core/core.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/ml/ml.hpp"
+
+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"
+
+ bool count_based(const vector<int>& a, const vector<int>& b) {
+ return a[1] > b[1];
+ }
+
+ int opencv_retrieveImages(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piChild = NULL;
+ int *piGrandChild = NULL;
+ int *piLen = NULL;
+ char **pstData = NULL;
+ int iRows, iCols;
+ int no_item_list = 0;
+ int no_item_list_2 = 0;
+ int inp_params = 0;
+ char **arg = NULL;
+
+ char ***location_img = NULL;
+ double **WordIndex = NULL;
+ double **Location = NULL;
+ double **Vocab_size = NULL;
+ double **Count = NULL;
+ double *wordFrequency = NULL;
+ char *bagOfFeaturesLocation = NULL;
+ int count_res = 0, count_roi = 0;
+ double numRes = 0;
+ double *roi_arg = NULL;
+ double x, y, width, height;
+
+ Mat image;
+ Mat feature_des;
+ Mat dictionary;
+ Mat des_matched;
+ Mat hist;
+ vector<KeyPoint> keypoints;
+ vector<KeyPoint> valid_key;
+ vector< vector<int> > clusterID;
+ vector<int> WordIndex_size;
+
+ int indx;
+ int search_ind;
+ double *Index_Out = NULL;
+ double *Score = NULL;
+ double **ImageWords = NULL;
+
+ CheckInputArgument(pvApiCtx, 2, 6); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 3); //Check on Number of Output Arguments
+
+ retrieveImage(image, 1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr2))
+ {
+ Scierror(999, "Error: Invalid Second argument. List Expected.\n");
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx, piAddr2, &no_item_list);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!(strcmp(pstData[0],"invertedImageIndex")==0))
+ {
+ Scierror(999, "Error: The input argument 2 is not of type invertedImageIndex.\n");
+ return 0;
+ }
+
+ sciErr = getListItemAddress(pvApiCtx, piAddr2, 2, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getListItemNumber(pvApiCtx, piChild, &no_item_list_2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ WordIndex = (double**)malloc(sizeof(double*)*no_item_list_2);
+ Location = (double**)malloc(sizeof(double*)*no_item_list_2);
+ Vocab_size = (double**)malloc(sizeof(double*)*no_item_list_2);
+ Count = (double**)malloc(sizeof(double*)*no_item_list_2);
+ for( int i=0; i<no_item_list_2; i++)
+ {
+ sciErr = getListItemAddress(pvApiCtx, piChild, i+1, &piGrandChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 1, &iRows, &iCols, &WordIndex[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ WordIndex_size.push_back(iRows);
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 2, &iRows, &iCols, &Location[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 3, &iRows, &iCols, &Vocab_size[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piGrandChild, 4, &iRows, &iCols, &Count[i]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr2, 3, &iRows, &iCols, &wordFrequency);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 4, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr2, 4, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ bagOfFeaturesLocation = pstData[0];
+ if(no_item_list == 5)
+ {
+ location_img = (char***)malloc(sizeof(char**)*1);
+ sciErr = getListItemAddress(pvApiCtx, piAddr2, 5, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ location_img[0] = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int colIter = 0 ; colIter < iRows * iCols ; colIter++)
+ {
+ location_img[0][colIter] = (char*)malloc(sizeof(char) * (piLen[colIter] + 1));//+ 1 for null termination
+ }
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, 1, &iRows, &iCols, piLen, location_img[0]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+
+ inp_params = *getNbInputArgument(pvApiCtx);
+ for( int i=3; i<=inp_params; i++)
+ {
+ if( inp_params%2 != 0)
+ {
+ Scierror(999,"Either Argument Name or its Value missing\n");
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx, i, &piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Check for Argument type
+ if( !isStringType(pvApiCtx, piAddr3))
+ {
+ Scierror(999, "%s: Wrong type of argument for Name of Optional Argument. A string is expected.\n", fname);
+ return 0;
+ }
+ //Matrix of Stings
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve the length of the string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ return 0;
+ }
+ arg = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int j=0;j< iRows * iCols; j++)
+ {
+ arg[j] = (char*)malloc(sizeof(char) * (piLen[j] + 1));
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ free(piLen);
+ free(arg);
+ return 0;
+ }
+
+ if(strcmp(arg[0],"NumResuts") == 0)
+ {
+ if(count_res != 0)
+ {
+ Scierror(999,"NumResults Argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of value
+ if(!(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr4)))
+ {
+ Scierror(999,"Not a valid type of value for NumResults.\n");
+ return 0;
+ }
+ if(getScalarDouble(pvApiCtx, piAddr4, &numRes))
+ {
+ Scierror(999,"Error Reading value of NumResults Argument\n");
+ return 0;
+ }
+ if(numRes < 0)
+ {
+ Scierror(999,"Not a valid value for NumResults\n");
+ return 0;
+ }
+ i++;
+ count_res += 1;
+ }
+ else if(strcmp(arg[0],"ROI") == 0)
+ {
+ if(count_roi != 0)
+ {
+ Scierror(999,"ROI Argument has been called twice.\n");
+ return 0;
+ }
+ free(arg);
+ free(piLen);
+ sciErr = getVarAddressFromPosition(pvApiCtx, i+1, &piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Checking the type of argument
+ if(!(isDoubleType(pvApiCtx, piAddr4)||isIntegerType(pvApiCtx, piAddr4)))
+ {
+ Scierror(999,"Not a valid type of value.\n");
+ return 0;
+ }
+ //Reading the Value of the argument
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &roi_arg);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Assigning the elements of the list to their proper function
+ x = roi_arg[0];
+ y = roi_arg[1];
+ width = roi_arg[2];
+ height = roi_arg[3];
+ i++;
+ count_roi += 1;
+ }
+ else
+ {
+ Scierror(999,"Invalid Argument Name\n");
+ return 0;
+ }
+ }
+
+ if(count_roi != 0)
+ {
+ Rect masker(x, y, width, height);
+ Mat croppedRef(image, masker);
+ image = Mat();
+ croppedRef.copyTo(image);
+ }
+
+ FileStorage fs(bagOfFeaturesLocation, FileStorage::READ);
+ fs["dictionary"] >> dictionary;
+ fs.release();
+
+ SurfFeatureDetector detector(100, 4, 2, 1, 1);
+ Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
+ Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor(100, 4, 2, 1, 1);
+ BOWImgDescriptorExtractor bowDE(extractor, matcher);
+ bowDE.setVocabulary(dictionary);
+ detector.detect(image, keypoints);
+ bowDE.compute(image, keypoints, hist, &clusterID, &des_matched);
+
+ ImageWords = (double**)malloc(sizeof(double*)*4*1);
+ ImageWords[0] = (double*)malloc(sizeof(double)*keypoints.size()*1);
+ ImageWords[1] = (double*)malloc(sizeof(double)*keypoints.size()*2);
+ ImageWords[2] = (double*)malloc(sizeof(double)*1);
+ ImageWords[3] = (double*)malloc(sizeof(double)*1);
+
+ ImageWords[2][0] = Vocab_size[0][0];
+ ImageWords[3][0] = keypoints.size();
+
+ vector<vector<int> > count_index(no_item_list_2 , vector<int>(3));
+
+ for( int i=0; i<keypoints.size(); i++)
+ {
+ ImageWords[1][i] = keypoints[i].pt.x;
+ ImageWords[1][keypoints.size() + i] = keypoints[i].pt.y;
+ }
+ for( int i=0; i<clusterID.size(); i++)
+ {
+ for( int j=0; j<clusterID[i].size(); j++)
+ {
+ indx = clusterID[i][j];
+ ImageWords[0][indx] = i;
+ }
+ }
+
+ for( int i=0; i<no_item_list_2; i++)
+ {
+ int count = 0;
+ for( int j=0; j<keypoints.size(); j++)
+ {
+ search_ind = ImageWords[0][j];
+ for( int k=0; k<WordIndex_size[i]; k++)
+ {
+ if(int(WordIndex[i][k]) == int(search_ind))
+ {
+ count += 1;
+ break;
+ }
+ }
+ }
+ count_index[i][0] = i+1;
+ count_index[i][1] = count;
+ count_index[i][2] = WordIndex_size[i];
+ }
+
+ sort(count_index.begin(), count_index.end(), count_based);
+ if(count_res == 0 || no_item_list_2<numRes)
+ numRes = no_item_list_2;
+ Index_Out = (double*)malloc(sizeof(double)*numRes);
+ Score = (double*)malloc(sizeof(double)*numRes);
+ for( int i=0; i<numRes; i++)
+ {
+ Index_Out[i] = count_index[i][0];
+ Score[i] = double(count_index[i][1])/double(keypoints.size());
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, numRes, 1, Index_Out);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2, numRes, 1, Score);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 3, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 3, piAddr, 1, keypoints.size(), 1, ImageWords[0]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 3, piAddr, 2, keypoints.size(), 2, ImageWords[1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 3, piAddr, 3, 1, 1, ImageWords[2]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 3, piAddr, 4, 1, 1, ImageWords[3]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx)+2;
+ AssignOutputVariable(pvApiCtx, 3) = nbInputArgument(pvApiCtx)+3;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_rotationVectorToMatrix.cpp b/sci_gateway1/cpp/opencv_rotationVectorToMatrix.cpp
new file mode 100644
index 0000000..fab0075
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_rotationVectorToMatrix.cpp
@@ -0,0 +1,205 @@
+/***************************************************
+Author : Tanmay Chaudhari
+ **************************************************/
+
+#include <bits/stdc++.h>
+using namespace std;
+extern "C"
+{
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "BOOL.h"
+#include <localization.h>
+#include "sciprint.h"
+
+ int opencv_rotationVectorToMatrix(char *fname, unsigned long fname_len)
+ {
+
+ //Error management variable
+ SciErr sciErr;
+
+ //Variable declaration
+ int iComplex = 0;
+ int iType = 0;
+ int iRows = 0;
+ int iCols = 0;
+ int *piAddr = NULL;
+ double sinOfangle = 0;
+ double cosOfangle = 0;
+ double t, x, y, z;
+ double theta;
+ double *pdbl = NULL;
+ double *matrix;
+ double *identity;
+ double *A;
+ double *B;
+
+ //Check input output arguments
+ checkInputArgument(pvApiCtx, 1, 1);
+ checkOutputArgument(pvApiCtx, 1, 1);
+
+ //Get variable address of the first input argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Check type
+ sciErr = getVarType(pvApiCtx, piAddr, &iType);
+ if(sciErr.iErr || iType != sci_matrix)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Get complexity
+ iComplex = isVarComplex(pvApiCtx, piAddr);
+
+ //Check complexity
+ if(iComplex)
+ {
+ Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdbl);
+ if(sciErr.iErr || iCols != 3 || iRows != 1)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ x = pdbl[0];
+ y = pdbl[1];
+ z = pdbl[2];
+
+ theta = sqrt(x * x + y * y + z * z);
+
+ sinOfangle = sin(theta);
+ cosOfangle = cos(theta);
+ t = 1 - cosOfangle;
+ x = pdbl[0] / theta;
+ y = pdbl[1] / theta;
+ z = pdbl[2] / theta;
+
+ matrix = (double*)malloc(sizeof(double) * 9);
+ A = (double*)malloc(sizeof(double) * 9);
+ B = (double*)malloc(sizeof(double) * 9);
+ identity = (double*)malloc(sizeof(double) * 9);
+
+ for(int i = 0; i < 3; i++)
+ {
+ for(int j = 0; j < 3; j++)
+ {
+ if(i == 0)
+ {
+ if(j == 0)
+ A[j * 3 + i] = x * x;
+ else if(j == 1)
+ A[j * 3 + i] = x * y;
+ else if(j == 2)
+ A[j * 3 + i] = x * z;
+
+ }
+ else if(i == 1)
+ {
+ if(j == 0)
+ A[j * 3 + i] = x * y;
+ else if(j == 1)
+ A[j * 3 + i] = y * y;
+ else if(j == 2)
+ A[j * 3 + i] = y * z;
+ }
+ else
+ {
+ if(j == 0)
+ A[j * 3 + i] = x * z;
+ else if(j == 1)
+ A[j * 3 + i] = y * z;
+ else if(j == 2)
+ A[j * 3 + i] = z * z;
+ }
+
+ }
+ }
+
+ for(int i = 0; i < 3; i++)
+ {
+ for(int j = 0; j < 3; j++)
+ {
+ if(i == 0)
+ {
+ if(j == 0)
+ B[j * 3 + i] = 0;
+ else if(j == 1)
+ B[j * 3 + i] = -z;
+ else if(j == 2)
+ B[j * 3 + i] = y;
+
+ }
+ else if(i == 1)
+ {
+ if(j == 0)
+ B[j * 3 + i] = z;
+ else if(j == 1)
+ B[j * 3 + i] = 0;
+ else if(j == 2)
+ B[j * 3 + i] = -x;
+ }
+ else
+ {
+ if(j == 0)
+ B[j * 3 + i] = -y;
+ else if(j == 1)
+ B[j * 3 + i] = x;
+ else if(j == 2)
+ B[j * 3 + i] = 0;
+ }
+
+ }
+ }
+
+ for(int i = 0; i < 3; i++)
+ {
+ for(int j = 0;j < 3; j++)
+ {
+ if(i == j)
+ identity[j * 3 + i] = 1;
+ else
+ identity[j * 3 + i] = 0;
+ }
+ }
+
+ for(int i = 0; i < 3; i++)
+ {
+ for(int j = 0; j < 3; j++)
+ {
+ matrix[i * 3 + j] = identity[j * 3 + i] * cosOfangle + t * A[j * 3 + i] + sinOfangle * B[j * 3 + i];
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, 1, 3, 3, matrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Return output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
+
+
+
diff --git a/sci_gateway1/cpp/opencv_scharr.cpp b/sci_gateway1/cpp/opencv_scharr.cpp
new file mode 100644
index 0000000..cb897d0
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_scharr.cpp
@@ -0,0 +1,155 @@
+/********************************************************
+ Author: Sukul Bagai
+*********************************************************
+ return_image = scharr(input_image, ddepth, dx, dy, scale, delta);
+********************************************************/
+
+#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_scharr(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ char **ddepth = NULL;
+ int i,j,k;
+ double dx,dy,scale,delta;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 6, 6);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for ddepth
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ddepth = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ ddepth[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, ddepth);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for value of dx
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &dx);
+ if(intErr)
+ return intErr;
+
+ //for value of dy
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &dy);
+ if(intErr)
+ return intErr;
+
+ //for value of scale
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &scale);
+ if(intErr)
+ return intErr;
+
+ //for value of delta
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &delta);
+ if(intErr)
+ return intErr;
+
+ Mat new_image(image.rows,image.cols,image.type());
+
+ if(strcmp(ddepth[0],"CV_8U")==0)
+ Scharr(image,new_image,CV_8U,dx,dy,scale,delta);
+ else if(strcmp(ddepth[0],"CV_16U")==0)
+ Scharr(image,new_image,CV_16U,dx,dy,scale,delta);
+ else if(strcmp(ddepth[0],"CV_16S")==0)
+ Scharr(image,new_image,CV_16S,dx,dy,scale,delta);
+ else if(strcmp(ddepth[0],"CV_32F")==0)
+ Scharr(image,new_image,CV_32F,dx,dy,scale,delta);
+ else if(strcmp(ddepth[0],"CV_64F")==0)
+ Scharr(image,new_image,CV_64F,dx,dy,scale,delta);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_sepFilter2D.cpp b/sci_gateway1/cpp/opencv_sepFilter2D.cpp
new file mode 100644
index 0000000..cf3db15
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_sepFilter2D.cpp
@@ -0,0 +1,261 @@
+/***************************************************
+Author : Sukul Bagai
+****************************************************
+Usage : return_image = sepFilter2D(input_image,"<ddepth>",kernel_x,kernel_y,anchor_x,anchor_y,delta,"<bordertype>");
+***************************************************/
+
+#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_sepFilter2D(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ int *piAddr8 = NULL;
+ char **ddepth = NULL;
+ char **borderType = NULL;
+ int i,j,k;
+ double *kernelX,*kernelY,anchorX,anchorY,delta,border,actualddepth;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 8, 8);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+cout<<"here1";
+ //for ddepth
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ddepth = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ ddepth[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, ddepth);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for kernel_x matrix
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols ,&kernelX);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ int n;
+
+ if(iRows == 1)
+ n=iCols;
+ else
+ n=iRows;
+ double kernelArray_x[n];
+ //assigning values to actual kernelMatrix
+ for(i=0;i<n;i++)
+ kernelArray_x[i]=kernelX[i];
+ // converting the array to a matrix, so that we can pass it into the filter2D function
+ Mat kernelMatrix_x(1, n, CV_32FC1, &kernelArray_x);
+
+ //for kernel_y matrix
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols ,&kernelY);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows == 1)
+ n=iCols;
+ else
+ n=iRows;
+ double kernelArray_y[n];
+ //assigning values to actual kernelMatrix
+ for(i=0;i<n;i++)
+ kernelArray_y[i]=kernelY[i];
+
+ // converting the array to a matrix, so that we can pass it into the filter2D function
+ Mat kernelMatrix_y(1, n, CV_32FC1, &kernelArray_y);
+
+ //for value of anchorX
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &anchorX);
+ if(intErr)
+ return intErr;
+
+ //for value of anchorY
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &anchorY);
+ if(intErr)
+ return intErr;
+
+ //for value of delta
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7, &delta);
+ if(intErr)
+ return intErr;
+
+ //for border
+ sciErr = getVarAddressFromPosition(pvApiCtx,8, &piAddr8);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr8, &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, piAddr8, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ borderType = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ borderType[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr8, &iRows, &iCols, piLen, borderType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //error check
+ if(anchorX >= n || anchorY >=n)
+ {
+ sciprint("Invalid anchor point given. Centre point (-1,-1) was used instead");
+ anchorY = -1;
+ anchorX = -1;
+ }
+ Mat new_image(image.rows,image.cols,image.type());
+ Point pt(anchorX,anchorY);
+
+ if(strcmp(ddepth[0],"CV_8U")==0)
+ actualddepth=CV_8U;
+ else if(strcmp(ddepth[0],"CV_16U")==0)
+ actualddepth=CV_16U;
+ else if(strcmp(ddepth[0],"CV_16S")==0)
+ actualddepth=CV_16S;
+ else if(strcmp(ddepth[0],"CV_32F")==0)
+ actualddepth=CV_32F;
+ else if(strcmp(ddepth[0],"CV_64F")==0)
+ actualddepth=CV_64F;
+ else
+ {
+ sciprint("Invalid type %s used. CV_8U was used instead by default",ddepth[0]);
+ actualddepth = CV_8U;
+ }
+ if(strcmp(borderType[0], "BORDER_CONSTANT") == 0)
+ border = BORDER_CONSTANT;
+ else if(strcmp(borderType[0], "BORDER_REPLICATE") == 0)
+ border = BORDER_REPLICATE;
+ else if(strcmp(borderType[0], "BORDER_REFLECT") == 0)
+ border = BORDER_REFLECT;
+ else if(strcmp(borderType[0], "BORDER_REFLECT_101") == 0)
+ border = BORDER_REFLECT_101;
+ else if(strcmp(borderType[0], "BORDER_WRAP") == 0)
+ border = BORDER_WRAP;
+ else
+ border = BORDER_DEFAULT;
+
+ //applying function
+ sepFilter2D(image,new_image,actualddepth,kernelMatrix_x,kernelMatrix_y,pt,delta,border);
+
+ //returning image
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_showMatchedFeatures.cpp b/sci_gateway1/cpp/opencv_showMatchedFeatures.cpp
new file mode 100644
index 0000000..ea26e80
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_showMatchedFeatures.cpp
@@ -0,0 +1,275 @@
+/*********************************************************************************
+*Author : Kevin George
+*
+*-> To execute, showMatchedFeatures(I1,I2)
+* where I1 & I2 are images
+*
+*********************************************************************************/
+#include <numeric>
+#include <string.h>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp"
+#include "opencv2/features2d/features2d.hpp"
+#include "opencv2/nonfree/features2d.hpp"
+#include "opencv2/nonfree/nonfree.hpp"
+#include <iostream>
+#include <math.h>
+#include <vector>
+
+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"
+ // # include "../common.cpp"
+
+ int opencv_showMatchedFeatures(char *fname, unsigned long fname_len)
+ {
+
+ //-> Error Management variables
+ SciErr sciErr;
+ int intErr=0;
+
+ //-> Mat containers for images
+ Mat image_1;
+ Mat image_2;
+
+ //-> Address of Various Arguments
+ int *piAddr = NULL;
+
+ //-> Local variables
+ int minHessian = 400; //-> For SURF algorithm
+ int num_InputArgs;
+ //-> KeyPoint is data structure to store a point feature
+ // detected by a keypoint detector(OpenCV)
+ vector<KeyPoint> keypoints_1;
+ vector<KeyPoint> keypoints_2;
+ Mat descriptors_1, descriptors_2;
+ Mat img_matches;
+ vector< DMatch > good_matches;
+ vector< DMatch > matches;
+ double max_dist = 0; double min_dist = 100;
+ int *outList = NULL;
+ unsigned char *red = NULL;
+ unsigned char *green = NULL;
+ unsigned char *blue = NULL;
+ /*double *indexPairs = NULL;
+ double *matchMetric = NULL;
+ double size=1;
+ int iRows, iCols; */
+
+ //KeyPoint *X = new KeyPoint; //-> Remember to free this Kevin
+
+ //-> Checks the number of arguments
+ //-> pvApiCtx is a Scilab environment pointer
+ CheckInputArgument(pvApiCtx, 2, 5); //Check on Number of Input Arguments
+ CheckOutputArgument(pvApiCtx, 1, 5); //Check on Number of Output Arguments
+
+ //-> Read Image
+ retrieveImage( image_1, 1);
+ retrieveImage(image_2, 2);
+
+ //-> Count number of input arguments
+ //num_InputArgs = *getNbInputArgument(pvApiCtx);
+
+ //-> Based on number of input arguments
+
+
+//****************************************************** Retrieval of 3rd,4th,5th args *******************************************************************
+
+ /*
+ /*************** Size of good matches **************
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getScalarDouble(pvApiCtx, piAddr, &size);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(getScalarDouble(pvApiCtx, piAddr, &size))
+ {
+ Scierror(999,"Cannot Read Upright Value\n");
+ return 0;
+ }
+
+ vector <DMatch> good_matches(size);
+
+
+ /*************** For indexPairs *************
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &indexPairs);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //-> Extract X and Ycoordinates of KeyPoints
+
+ //X->pt = Point2f(keypoints[i],keypoints[iRows+i]);
+ //keypoints_1.push_back(*X);
+
+
+ /*************** For matchMetric **************
+ sciErr = getVarAddressFromPosition(pvApiCtx, 5, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &matchMetric);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(int i=0; i< size; i++)
+ {
+ good_matches[i].queryIdx = indexPairs[i];
+ good_matches[i].trainIdx = indexPairs[ static_cast<int>(size)+i];
+ good_matches[i].distance = matchMetric[i];
+
+ }
+ */
+
+//***************************************************** Actual Processing *************************************************************
+
+ //-- Step 1: Calculate keypoints
+ SurfFeatureDetector detector( minHessian );
+ detector.detect( image_1, keypoints_1 );
+ detector.detect( image_2, keypoints_2 );
+
+ //-- Step 2: Calculate descriptors (feature vectors)
+ SurfDescriptorExtractor extractor;
+ extractor.compute( image_1, keypoints_1, descriptors_1 );
+ extractor.compute( image_2, keypoints_2, descriptors_2 );
+
+ //-- Step 3: Matching descriptor vectors using FLANN matcher
+ FlannBasedMatcher matcher;
+ matcher.match( descriptors_1, descriptors_2, matches );
+
+ //-- Quick calculation of max and min distances between keypoints
+ for( int i = 0; i < descriptors_1.rows; i++ )
+ {
+ double dist = matches[i].distance;
+ if( dist < min_dist ) min_dist = dist;
+ if( dist > max_dist ) max_dist = dist;
+ }
+
+ for( int i = 0; i < descriptors_1.rows; i++ )
+ {
+ //if( matches[i].distance <= max(2*min_dist, 0.02) )
+ if( matches[i].distance <= (2*min_dist) )
+ { good_matches.push_back( matches[i]); }
+ }
+
+ //-> Draw only "good" matches
+ drawMatches( image_1, keypoints_1, image_2, keypoints_2,
+ good_matches,img_matches, Scalar::all(-1), Scalar::all(-1),
+ vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
+
+ //-> Show detected matches
+ //imshow( "Good Matches", img_matches );
+ //waitKey(0);
+
+ if( img_matches.channels() == 1)
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ red = (unsigned char *)malloc(sizeof(unsigned char)*img_matches.rows*img_matches.cols);
+
+ for(int k=0;k<img_matches.rows;k++)
+ for(int p=0;p<img_matches.cols;p++)
+ red[k+img_matches.rows*p]=img_matches.at<uchar>(k, p);
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, img_matches.rows, img_matches.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ }
+
+ else
+ {
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &outList);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ red = (unsigned char *)malloc(sizeof(unsigned char)*img_matches.rows*img_matches.cols);
+ green = (unsigned char *)malloc(sizeof(unsigned char)*img_matches.rows*img_matches.cols);
+ blue = (unsigned char *)malloc(sizeof(unsigned char)*img_matches.rows*img_matches.cols);
+
+ for(int k=0;k<img_matches.rows;k++)
+ {
+ for(int p=0;p<img_matches.cols;p++)
+ {
+ Vec3b intensity = img_matches.at<Vec3b>(k, p);
+ red[k+img_matches.rows*p]=intensity.val[2];
+ green[k+img_matches.rows*p]=intensity.val[1];
+ blue[k+img_matches.rows*p]=intensity.val[0];
+ }
+ }
+
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 1, img_matches.rows, img_matches.cols, red);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 2, img_matches.rows, img_matches.cols, green);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger8InList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, outList, 3, img_matches.rows, img_matches.cols, blue);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ free(red);
+ free(green);
+ free(blue);
+
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+}
diff --git a/sci_gateway1/cpp/opencv_sobel.cpp b/sci_gateway1/cpp/opencv_sobel.cpp
new file mode 100644
index 0000000..912be4d
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_sobel.cpp
@@ -0,0 +1,172 @@
+/********************************************************
+ Author: Sukul Bagai
+*********************************************************
+ return_image = sobel(input_image, ddepth, dx, dy, kszie, scale, delta);
+********************************************************/
+
+#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_sobel(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+ int *piAddr6 = NULL;
+ int *piAddr7 = NULL;
+ char **ddepth = NULL;
+ int i,j,k;
+ double dx,dy,ksize,scale,delta;
+
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 7, 7);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of ddepth
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Now, we will retrieve the string from the input parameter. For this, we will require 3 calls
+ //first call to retrieve dimensions
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &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, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ddepth = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ ddepth[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, ddepth);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //for value of dx
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &dx);
+ if(intErr)
+ return intErr;
+
+ //for value of dy
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &dy);
+ if(intErr)
+ return intErr;
+
+ //for value of ksize
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr5, &ksize);
+ if(intErr)
+ return intErr;
+
+ //for value of scale
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr6, &scale);
+ if(intErr)
+ return intErr;
+
+ //for value of delta
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr7, &delta);
+ if(intErr)
+ return intErr;
+
+ Mat new_image(image.rows,image.cols,CV_8UC3);
+ if((int)ksize!=1 && (int)ksize!=3 && (int)ksize!=5 && (int)ksize!=7)
+ {
+ sciprint("Value of 1,3,5,7 Required for ksize. Default value of 3 was used instead");
+ ksize=3;
+ }
+
+ //void Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT )
+ if(strcmp(ddepth[0],"CV_8U")==0)
+ Sobel(image,new_image,CV_8U,dx,dy,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_16U")==0)
+ Sobel(image,new_image,CV_16U,dx,dy,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_16S")==0)
+ Sobel(image,new_image,CV_16S,dx,dy,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_32F")==0)
+ Sobel(image,new_image,CV_32F,dx,dy,ksize,scale,delta);
+ else if(strcmp(ddepth[0],"CV_64F")==0)
+ Sobel(image,new_image,CV_64F,dx,dy,ksize,scale,delta);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_threshold.cpp b/sci_gateway1/cpp/opencv_threshold.cpp
new file mode 100644
index 0000000..1210d47
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_threshold.cpp
@@ -0,0 +1,146 @@
+/********************************************************
+ Author: Abhilasha Sancheti & Sukul Bagai
+*********************************************************
+ [return_image, double] = threshold(input_image, threshold_value, max_value, "<threshold_type>");
+********************************************************/
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#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 <sciprint.h>
+ #include "../common.h"
+
+ int opencv_threshold(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddrNew2 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int i,j,k;
+ double thresh,max_val;
+ int type;
+ char **gettype = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 2, 2) ;
+ Mat image;
+ retrieveImage(image,1);
+ if(no_of_channels(image.type()) != 1)
+ cvtColor( image, image, CV_BGR2GRAY );
+
+
+ //for threshold value (thresh)
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2,&thresh);
+ if(intErr)
+ return intErr;
+
+ //for max_value
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3,&max_val);
+ if(intErr)
+ return intErr;
+
+
+// for type of thresholding (gettype)
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, NULL, NULL);
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ gettype= (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ gettype[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data of each string of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr4, &iRows, &iCols, piLen, gettype);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //for value of type
+
+ Mat new_image(image.rows,image.cols,CV_8UC1);
+ if(strcmp(gettype[0],"THRESH_BINARY")==0)
+ type = 0;
+ else if (strcmp(gettype[0],"THRESH_BINARY_INV")==0)
+ type=1;
+ else if (strcmp(gettype[0],"THRESH_TRUNC")==0)
+ type=2;
+ else if (strcmp(gettype[0],"THRESH_TOZERO")==0)
+ type=3;
+ else if (strcmp(gettype[0],"THRESH_TOZERO_INV")==0)
+ type=4;
+ else
+ {
+ sciprint("Wrong type given. THRESH_BINARY used instead");
+ type=0;
+ }
+ double res = threshold( image ,new_image, thresh, max_val,type);
+ // Converting resultant image to 3D matrix
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ intErr = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 2,res);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ AssignOutputVariable(pvApiCtx, 2) = nbInputArgument(pvApiCtx) + 2;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_trainImageCategoryClassifier.cpp b/sci_gateway1/cpp/opencv_trainImageCategoryClassifier.cpp
new file mode 100644
index 0000000..e2a504a
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_trainImageCategoryClassifier.cpp
@@ -0,0 +1,349 @@
+/***************************************************
+Author : Rohit Suri
+***************************************************/
+#include <iostream>
+#include <opencv2/opencv.hpp>
+#include <opencv2/nonfree/nonfree.hpp>
+#include <opencv2/ml/ml.hpp>
+
+using namespace std;
+using namespace cv;
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+ int opencv_trainImageCategoryClassifier(char *fname, unsigned long fname_len)
+ {
+ // Error management variables
+ SciErr sciErr;
+
+ //------Local variables------//
+ int upright = 1;
+ Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("FlannBased");
+ Ptr<DescriptorExtractor> extractor = new SurfDescriptorExtractor(1, 4, 2, 1, int(upright));
+ BOWImgDescriptorExtractor bowDE(extractor, matcher);
+ SurfFeatureDetector detector(1, 4, 2, 1, int(upright));
+ char *fileName = NULL;
+ Mat dictionary,inp,features;
+ vector<KeyPoint> keyPoints;
+
+
+ int *piAddr = NULL;
+ int *piChild = NULL;
+ int iRows, iCols;
+ char **pstData = NULL;
+ int *piLen = NULL;
+ int *count = NULL;
+ char **description = NULL;
+ char ***location = NULL;
+ char *bagOfFeaturesLocation = NULL;
+ int descriptionCount;
+ char *classifierLocation = "classifier.yml";
+ char *objectType = "classifier";
+ //------Check number of parameters------//
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ //------Get input arguments------//
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr))
+ {
+ Scierror(999, "Error: The input argument #1 is not of type imageSet.\n");
+ return 0;
+ }
+
+ // Extracting object type and checking if type is imageSet
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"imageSet")==0))
+ {
+ Scierror(999, "Error: The input argument #1 is not of type imageSet.\n");
+ return 0;
+ }
+
+ // Extracting Description attribute of input argument
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ description = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ description[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ descriptionCount = iRows;
+
+ // Extracting Count attribute of input argument
+ sciErr = getMatrixOfInteger32InList(pvApiCtx, piAddr, 3, &iRows, &iCols, &count);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ location = (char***) malloc(sizeof(char**) * descriptionCount);
+ sciErr = getListItemAddress(pvApiCtx, piAddr, 4, &piChild);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for(int iter = 1; iter<=descriptionCount; iter++)
+ {
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ location[iter-1] = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int colIter = 0 ; colIter < iRows * iCols ; colIter++)
+ {
+ location[iter-1][colIter] = (char*)malloc(sizeof(char) * (piLen[colIter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piChild, iter, &iRows, &iCols, piLen, location[iter-1]);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ }
+ // Second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!isListType(pvApiCtx, piAddr))
+ {
+ Scierror(999, "Error: The input argument #2 is not of type bagOfFeatures.\n");
+ return 0;
+ }
+
+ // Extracting object type and checking if type is bagOfFeatures
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, NULL, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*)malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**)malloc(sizeof(char*) * iRows * iCols);
+
+ for(int iter = 0 ; iter < iRows * iCols ; iter++)
+ {
+ pstData[iter] = (char*)malloc(sizeof(char) * (piLen[iter] + 1));//+ 1 for null termination
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 1, &iRows, &iCols, piLen, pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!(strcmp(pstData[0],"bagOfFeatures")==0))
+ {
+ Scierror(999, "Error: The input argument #2 is not of type bagOfFeatures.\n");
+ return 0;
+ }
+ // Extracting name of next argument takes three calls to getMatrixOfString
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int iterPstData = 0; iterPstData < iRows * iCols; iterPstData++)
+ {
+ pstData[iterPstData] = (char*) malloc(sizeof(char) * piLen[iterPstData] + 1);
+ }
+
+ sciErr = getMatrixOfStringInList(pvApiCtx, piAddr, 2, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=1 || iCols!=1)
+ {
+ Scierror(999, "1x1 Matrix expected for bagOfFeatures argument.");
+ return 0;
+ }
+ bagOfFeaturesLocation = pstData[0];
+ //------Actual processing------//
+ FileStorage fs(bagOfFeaturesLocation, FileStorage::READ);
+ fs["dictionary"] >> dictionary;
+ fs.release();
+ if(dictionary.rows==0 || dictionary.cols==0)
+ {
+ sciprint("Error: The provided file for bagOfFeatures may be invalid.\n");
+ }
+ sciprint("Training an image category classifier for %d categories.\n",descriptionCount);
+ sciprint("-------------------------------------------------------\n\n");
+ for(int i=0;i<descriptionCount;i++)
+ {
+ sciprint("# Category %d: %s\n",i+1,description[i]);
+ }
+ sciprint("\n");
+ int dictionarySize = dictionary.rows;
+ Mat labels(0, 1, CV_32FC1);
+ Mat trainingData(0, dictionarySize, CV_32FC1);
+ bowDE.setVocabulary(dictionary);
+ for(int i=0; i<descriptionCount;i++)
+ {
+ sciprint("# Encoding features for Category %d ...",i+1);
+ for(int j=0; j<count[i]; j++)
+ {
+ features.release();
+ keyPoints.clear();
+ fileName = location[i][j];
+ inp = imread(fileName);
+ detector.detect(inp,keyPoints);
+ bowDE.compute(inp,keyPoints,features);
+ trainingData.push_back(features);
+ labels.push_back((float) i);
+ }
+ sciprint("done.\n");
+ }
+ sciprint("\n# Training the category classifier...");
+ CvSVMParams params;
+ params.kernel_type=CvSVM::RBF;
+ params.svm_type=CvSVM::C_SVC;
+ params.gamma=0.50625000000000009;
+ params.C=312.50000000000000;
+ params.term_crit=cvTermCriteria(CV_TERMCRIT_ITER,100,0.000001);
+ CvSVM svm;
+ svm.train(trainingData,labels,cv::Mat(),cv::Mat(),params);
+ svm.save(classifierLocation);
+ sciprint("done.\n");
+ //------Create output arguments------//
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 4, &piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 1, 1, 1, &objectType);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 2, 1, 1, &classifierLocation);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 3, 1, 1, &bagOfFeaturesLocation);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfStringInList(pvApiCtx, nbInputArgument(pvApiCtx)+1, piAddr, 4, descriptionCount, 1, description);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //------Return Arguments------//
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx)+1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+ /* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_triangulatePoints.cpp b/sci_gateway1/cpp/opencv_triangulatePoints.cpp
new file mode 100644
index 0000000..4ee38bd
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_triangulatePoints.cpp
@@ -0,0 +1,166 @@
+/***************************************************
+Author : Deepshikha
+***************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/calib3d/calib3d.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_triangulatePoints(char *fname, unsigned long fname_len)
+ {
+ //variables
+ int i,j,n,m;
+ int iRows=0,iCols=0;
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+
+ double *pdblReal = NULL;
+
+ SciErr sciErr;
+
+ /*------------------------------------------- Checking Input Argument ----------------------------------------------------*/
+
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ /*------------------------------------- Projection matrix 1 :- First argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=3 or iCols!=4){
+ Scierror(iRows,"Projection matrix (arg 1) must be a 3 X 4 matrix");
+ return 0;
+ }
+ Mat projMat1(iRows, iCols, CV_64F);
+ for(i = 0; i < iRows; i++)
+ for(j = 0; j < iCols; j++){
+ projMat1.at<double>(i,j) = pdblReal[i + (j * iRows)];
+ }
+
+ /* ------------------------------------ Projection matrix 2 :- Second argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=3 or iCols!=4){
+ Scierror(iRows,"Projection matrix (arg 2) must be a 3 X 4 matrix");
+ return 0;
+ }
+ Mat projMat2(iRows, iCols, CV_64F);
+ for(i=0;i<iRows;i++)
+ for(j=0;j<iCols;j++)
+ projMat2.at<double>(i,j) = pdblReal[i + (j * iRows)];
+
+
+ /* ------------------------------------ Points matrix 1 :- Third argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ n = iCols;
+ if(iRows!=2){
+ Scierror(iRows,"Points matrix (arg 3) must be a 2 X N matrix");
+ return 0;
+ }
+ Mat newPoint1(2, iCols, CV_64F);
+ for(i = 0; i < 2; i++)
+ for(j = 0; j < iCols; j++)
+ newPoint1.at<double>(i,j) = pdblReal[ i + ( j * iRows )];
+
+
+ /* ------------------------------------ Points matrix 2 :- Fourth argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ m = iCols;
+ if(iRows!=2){
+ Scierror(iRows,"Points matrix (arg 4) must be a 2 X N matrix");
+ return 0;
+ }
+ Mat newPoint2(iRows, iCols, CV_64F);
+ for(i = 0; i < iRows; i++)
+ for(j = 0; j < iCols; j++)
+ newPoint2.at<double>(i,j) = pdblReal[ i + ( j * iRows )];
+
+ if(n!=m){
+ Scierror(n,"No of columns of arg 3 and arg 4 must be same");
+ return 0;
+ }
+ Mat new_image(4, n, CV_64F);
+
+ triangulatePoints(projMat1, projMat2, newPoint1, newPoint2, new_image);
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_undistort.cpp b/sci_gateway1/cpp/opencv_undistort.cpp
new file mode 100644
index 0000000..da72d8e
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_undistort.cpp
@@ -0,0 +1,118 @@
+/***************************************************
+Author : Sukul Bagai, Shubheksha Jalan
+***************************************************/
+
+#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 "../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<n;i++)
+ distCoeffs[i]=temp[i];
+ Mat distCoeffsActual(n,1,CV_64F);
+
+//for optional parameter newCameraMatrix
+sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols , &temp);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ for(i=0;i<3;i++)
+ for(j=0;j<3;j++)
+ newCameraMatrix[i][j]=temp[(j*3)+i];
+ Mat newCameraMat(3,3,CV_64F,&newCameraMatrix);
+ Mat new_image;
+
+ undistort(image, new_image, cameraMat, distCoeffsActual, newCameraMat);
+
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,new_image,1);
+ free(checker);
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/opencv_undistortImage.cpp b/sci_gateway1/cpp/opencv_undistortImage.cpp
new file mode 100644
index 0000000..9a02882
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_undistortImage.cpp
@@ -0,0 +1,271 @@
+/********************************************************
+Author: Suraj Prakash
+return_image = undistortImage(image, _cameraMatrix, _distCoeffs, _newCameraMatrix);
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <vector>
+
+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_undistortImage(char *fname, unsigned long fname_len){
+
+ /// Error management variable
+ SciErr sciErr;
+
+ /// Variables
+ int i, j, n = 0;
+
+ int iRows = 0;
+ int iCols = 0;
+ int iRows1 = 0;
+ int iCols1 = 0;
+ int *piLen = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ double *pdblReal = NULL;
+
+ char **pstData = NULL;
+ char *currentArg = NULL;
+ bool *providedArgs = NULL;
+
+ double cameraMatrix[3][3];
+ double *newCameraMatrix = NULL;
+ double *distCoeffs = NULL;
+
+ /// checking input argument
+ // 1-> image
+ // 2-> cameraMatrix
+ // 3-> distCoeffs
+ // 4-> newCameraMatrix
+
+ CheckInputArgument(pvApiCtx, 2, 6);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ /// Take distorted image
+ Mat image;
+ retrieveImage(image, 1);
+
+ newCameraMatrix = (double*)malloc(sizeof(double) * 3 * 3);
+ memset(newCameraMatrix, 0, sizeof(newCameraMatrix));
+
+ /// Taking input for cameraMatrix
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ /// Take input in cameraMatrix
+ Mat _cameraMatrix(3, 3, CV_64F);
+ for(i = 0; i < 3; ++i)
+ for(j = 0;j < 3; ++j)
+ _cameraMatrix.at<double>(i, j) = pdblReal[(j * 3) + i];
+
+
+ int nbInputArguments = *getNbInputArgument(pvApiCtx);
+
+
+ providedArgs = (bool*) malloc(sizeof(bool) * 2);
+ memset(providedArgs, 0, 2);
+
+ for(int iter = 3; iter <= nbInputArguments; ++iter){
+
+ /// Address of next argument
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, iter, &piAddr3);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Three calls to getMatrixOfString
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, NULL, NULL);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ piLen = (int*) malloc(sizeof(int) * iRows * iCols);
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, NULL);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ pstData = (char**) malloc(sizeof(char*) * iRows * iCols);
+ for(int k = 0; k < iRows * iCols; ++k)
+ {
+ pstData[k] = (char*) malloc(sizeof(char) * piLen[k] + 1);
+ }
+
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, pstData);
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ currentArg = pstData[0];
+
+ if(strcmp(currentArg, "distCoeffs") == 0){
+
+ if(iter+1 <= nbInputArguments and !providedArgs[0]){
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr4);
+
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows1, &iCols1, &pdblReal);
+
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows1 == 1 or iCols1 == 1)
+ n = iCols1 * iRows1;
+
+ else{
+ Scierror(999, "Incorrect dimension of vector for argument\n");
+ return 0;
+ }
+
+ // if(n != 4 or n != 5 or n != 8){
+ // Scierror(999, "Incorrect dimension of matrix for argument. Only size of 4, 5, or 8 required\n");
+ // return 0;
+ // }
+
+ distCoeffs = (double*)malloc(sizeof(double) * n);
+
+ for(i = 0; i < n; ++i){
+ distCoeffs[i] = pdblReal[i];
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[0] = 1;
+ }
+ // Send an error message if an argument is provided more than once. Same for all optional arguments.
+
+ else if(providedArgs[0]){
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+
+ // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+
+ else {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+
+ else if(strcmp(currentArg, "newCameraMatrix") == 0){
+
+ if(iter+1 <= nbInputArguments and !providedArgs[1]){
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, ++iter, &piAddr4);
+
+ if (sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows1, &iCols1, &newCameraMatrix);
+
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows1 !=3 and iCols1 != 3){
+ Scierror(999, "Incorrect dimension of matrix for argument\n");
+ return 0;
+ }
+
+ // Checking if values are in proper range. Same for all optional arguments
+ providedArgs[1] = 1;
+ }
+ // Send an error message if an argument is provided more than once. Same for all optional arguments.
+
+ else if(providedArgs[1]){
+ Scierror(999, "Please provide optional arguments only once.\n");
+ return 0;
+ }
+
+ // Send an error message if name of argument is given but type is incorrect. Same for all optional arguments.
+
+ else {
+ Scierror(999, "Incorrect number of arguments provided. Please check the documentation for more information.\n");
+ return 0;
+ }
+ }
+ else{
+ sciprint("Invalid argument provided; Using defalult values\n");
+ }
+
+ }
+
+ Mat _distCoeffs = Mat::zeros(1, n, CV_64F);
+
+ /// if distCoeffs was provided else it will be NULL / empty
+ if(providedArgs[0]){
+ for(i = 0; i < n; ++i)
+ _distCoeffs.at<double>(0, i) = distCoeffs[i];
+ }
+
+ /// By default the _newCameraMatrix has the same value of CameraMatrix
+ Mat _newCameraMatrix(3, 3, CV_64F, &cameraMatrix);
+
+ if(providedArgs[1]){
+ for(i = 0; i < 3; ++i)
+ for(j = 0; j < 3; ++j)
+ _newCameraMatrix.at<double>(i, j) = newCameraMatrix[j * 3 + i];
+ }
+
+ Mat new_image;
+ undistort(image, new_image, _cameraMatrix, _distCoeffs, _newCameraMatrix);
+
+
+ string tempstring = type2str(new_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, new_image, 1);
+ free(checker);
+
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway1/cpp/opencv_undistortPoints.cpp b/sci_gateway1/cpp/opencv_undistortPoints.cpp
new file mode 100644
index 0000000..dff80e4
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_undistortPoints.cpp
@@ -0,0 +1,190 @@
+/***************************************************
+Author : Deepshikha
+***************************************************/
+
+#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_undistortPoints(char *fname, unsigned long fname_len)
+ {
+ //variables
+ int i,j,k,n,m;
+ int iRows=0,iCols=0;
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int *piAddr4 = NULL;
+ int *piAddr5 = NULL;
+
+ double *pdblReal = NULL;
+
+ SciErr sciErr;
+
+ //function varible
+ std::vector< Point2d > Src;
+ std::vector< Point2d > dst;
+ double cameraMatrix [3][3];
+ double newCameraMatrix [3][3];
+ double *distCoeffs = NULL;
+ double RectificationMatrix[3][3];
+
+ /*------------------------------------------- Checking Input Argument ----------------------------------------------------*/
+
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ /*------------------------------------- Source matrix :- First argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ // For 1 X N single channel
+ for(i = 0; i < iRows; ++i)
+ Src.push_back( Point2d(pdblReal[(0 * iRows) + i], pdblReal[(1 * iRows) + i]));
+
+ /* ------------------------------------ Camera matrix :- Second argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ Mat cameraMat(3, 3, CV_64F);
+ for(i=0;i<3;i++)
+ for(j=0;j<3;j++)
+ cameraMat.at<double>(i,j) = pdblReal[(j * 3) + i];
+
+
+ /* ------------------------------------ Distortion Coefficient matrix :- Third argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows== 1)
+ n = iCols;
+ else if (iCols == 1)
+ n = iRows;
+ else{
+ Scierror(1,"Points matrix (arg 4) must be a 2 X N matrix");
+ return 0;
+ }
+ if(n==4 or n==5 or n==8);
+ else{
+ Scierror(1," n must be 4 or 5 or 8");
+ return 0;
+ }
+
+ Mat distCoeffsActual(1,n,CV_64F);
+ for(i=0;i<n;i++)
+ distCoeffsActual.at<double>(0,i) = pdblReal[i];
+
+
+ /* ------------------------------------ Rectification matrix :- Fourth argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ Mat RectMat(3, 3, CV_64F);
+ for(i=0;i<3;i++)
+ for(j=0;j<3;j++)
+ RectMat.at<double>(i,j) =pdblReal[(j*3)+i];
+
+
+ /* ------------------------------------ New Camera matrix :- Fifth argument of the input -------------------------------------*/
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr5, &iRows, &iCols , &pdblReal);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ Mat newCameraMat(3,3,CV_64F);
+ for(i=0;i<3;i++)
+ for(j=0;j<3;j++)
+ newCameraMat.at<double>(i, j) =pdblReal[(j*3)+i];
+
+
+
+ /* opencv function for undistortPoints */
+ undistortPoints(Src, dst, cameraMat, distCoeffsActual, RectMat, newCameraMat);
+
+ /* Writing to Scilab */
+ double *pstdata = NULL;
+ pstdata = (double*)malloc(sizeof(double) * dst.size() * 2);
+
+ for(i = 0; i < dst.size(); i++)
+ {
+ pstdata[i + 0 * dst.size()] = dst[i].x;
+ pstdata[i + 1 * dst.size()] = dst[i].y;
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, dst.size(), 2, pstdata);
+ if(sciErr.iErr){
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway1/cpp/rotationMatrixToVector.cpp b/sci_gateway1/cpp/rotationMatrixToVector.cpp
new file mode 100644
index 0000000..40ef093
--- /dev/null
+++ b/sci_gateway1/cpp/rotationMatrixToVector.cpp
@@ -0,0 +1,139 @@
+/***************************************************
+Author : Shashank Shekhar
+**************************************************/
+
+#include <bits/stdc++.h>
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+
+ int rotationMTV(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int *piAddr = NULL;
+ int iRows = 0;
+ int iCols = 0;
+ int *piLen = 0;
+ char **pstData = NULL;
+ double RotMat[9];
+ double *temp = NULL;
+ int noOfarguments = *getNbInputArgument(pvApiCtx);
+ double outMat[3];
+ double theta;
+ int i;
+
+
+
+ CheckInputArgument(pvApiCtx,1,1);
+ CheckOutputArgument(pvApiCtx,1,1);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&scisErr, 0);
+ return 0;
+ }
+
+ if(!isDoubleType(pvApiCtx, piAddr) || isVarComplex(pvApiCtx, piAddr))
+ {
+ Scierror(999,"A 3x3 Matrix expected.\n");
+ return 0;
+ }
+
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &temp);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(iRows!=3 || iCols!=3)
+ {
+ Scierror(999,"Invalid Argument\n");
+ return 0;
+ }
+
+ for(i=0;i<3;i++)
+ {
+ for(int j=0;j<3;j++)
+ {
+ RotMat[j*3+i]=temp[i*3+j];
+ }
+ }
+
+// ----------------------------------------------------------- Evaluation --------------------------------------------------------
+
+ double myMat[3][3];
+ for(int i=0;i<3;i++)
+ for(int j=0;j<3;j++)
+ myMat[i][j] = RotMat[i*3+j];
+
+ double trace = RotMat[0]+RotMat[4]+RotMat[8];
+ theta = acos((trace-1)/2);
+ outMat[0] = myMat[2][1]-myMat[1][2];
+ outMat[1] = myMat[0][2]-myMat[2][0];
+ outMat[2] = myMat[1][0]-myMat[0][1];
+
+ double element;
+ double threshold = 1e-4;
+ if(sin(theta) >= threshold)
+ {
+ element = theta/(2*sin(theta));
+ for(int i=0;i<3;i++)
+ outMat[i]=outMat[i]*element;
+ }
+ else if (theta-1 > 0)
+ {
+ element = (0.5-(theta-3)/12);
+ for(int i=0;i<3;i++)
+ outMat[i]=outMat[i]*element;
+ }
+ else
+ {
+ double myMax=myMat[0][0];
+ int iter1=0;
+ int iter2,iter3;
+ for(int i=0;i<3;i++)
+ {
+ if(myMat[i][i]>myMax)
+ {
+ myMax=myMat[i][i];
+ iter1=i;
+ }
+ }
+
+ iter2 = (iter1%2) +1;
+ iter3 = ((iter1+1)%2) +1;
+
+ double ev = sqrt(myMat[iter1][iter1] - myMat[iter2][iter2] - myMat[iter3][iter3] + 1);
+ outMat[0] = ev/2;
+ outMat[1] = (myMat[iter2][iter1] + myMat[iter1][iter2])/(2*ev);
+ outMat[2] = (myMat[iter3][iter1] + myMat[iter1][iter3])/(2*ev);
+
+ for(int i=0;i<3;i++)
+ ev+=pow(outMat[i],2);
+ ev = sqrt(ev);
+
+ for(int i=0;i<3;i++)
+ outMat[i]=(outMat[i]/ev)*theta;
+ }
+
+// --------------------------------------------------------Creating 1x3 Mat to Return -------------------------------------------------------------
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3,1,outMat);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+} \ No newline at end of file