summaryrefslogtreecommitdiff
path: root/sci_gateway/cpp
diff options
context:
space:
mode:
authorshamikam2017-01-16 02:56:17 +0530
committershamikam2017-01-16 02:56:17 +0530
commita6df67e8bcd5159cde27556f4f6a315f8dc2215f (patch)
treee806e966b06a53388fb300d89534354b222c2cad /sci_gateway/cpp
downloadFOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.tar.gz
FOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.tar.bz2
FOSSEE_Image_Processing_Toolbox-a6df67e8bcd5159cde27556f4f6a315f8dc2215f.zip
First CommitHEADmaster
Diffstat (limited to 'sci_gateway/cpp')
-rw-r--r--sci_gateway/cpp/builder_gateway_cpp.sce364
-rw-r--r--sci_gateway/cpp/builder_gateway_cpp.sce~364
-rw-r--r--sci_gateway/cpp/cleaner.sce22
-rw-r--r--sci_gateway/cpp/common.cpp890
-rw-r--r--sci_gateway/cpp/common.cpp~890
-rw-r--r--sci_gateway/cpp/common.h9
-rw-r--r--sci_gateway/cpp/dctmtx.cpp96
-rw-r--r--sci_gateway/cpp/lab2xyz.cpp271
-rw-r--r--sci_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.c52
-rwxr-xr-xsci_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.sobin0 -> 99569 bytes
-rw-r--r--sci_gateway/cpp/loader.sce32
-rw-r--r--sci_gateway/cpp/multithresh.cpp208
-rw-r--r--sci_gateway/cpp/opencv_adapthisteq.cpp201
-rw-r--r--sci_gateway/cpp/opencv_affine2d.cpp122
-rw-r--r--sci_gateway/cpp/opencv_applycform.cpp371
-rw-r--r--sci_gateway/cpp/opencv_approxpolyDP.cpp151
-rw-r--r--sci_gateway/cpp/opencv_arclength.cpp130
-rw-r--r--sci_gateway/cpp/opencv_arrowedline.cpp221
-rw-r--r--sci_gateway/cpp/opencv_bilateralfilter.cpp112
-rw-r--r--sci_gateway/cpp/opencv_blur.cpp134
-rw-r--r--sci_gateway/cpp/opencv_borderInterpolate.cpp149
-rw-r--r--sci_gateway/cpp/opencv_boundingRect.cpp82
-rw-r--r--sci_gateway/cpp/opencv_boxfilter.cpp189
-rw-r--r--sci_gateway/cpp/opencv_bwconvhull.cpp129
-rw-r--r--sci_gateway/cpp/opencv_bwdistgeodesic.cpp88
-rw-r--r--sci_gateway/cpp/opencv_bwlookup.cpp180
-rw-r--r--sci_gateway/cpp/opencv_bwulterode.cpp92
-rw-r--r--sci_gateway/cpp/opencv_canny.cpp121
-rw-r--r--sci_gateway/cpp/opencv_circle.cpp203
-rw-r--r--sci_gateway/cpp/opencv_clipline.cpp149
-rw-r--r--sci_gateway/cpp/opencv_contourarea.cpp125
-rw-r--r--sci_gateway/cpp/opencv_convexhull.cpp140
-rw-r--r--sci_gateway/cpp/opencv_convmtx2.cpp129
-rw-r--r--sci_gateway/cpp/opencv_copymakeborder.cpp195
-rw-r--r--sci_gateway/cpp/opencv_corner.cpp166
-rw-r--r--sci_gateway/cpp/opencv_cornerEigenValsAndVecs.cpp127
-rw-r--r--sci_gateway/cpp/opencv_cornerHarris.cpp144
-rw-r--r--sci_gateway/cpp/opencv_cornerMinEigenVal.cpp125
-rw-r--r--sci_gateway/cpp/opencv_cvtColor.cpp183
-rw-r--r--sci_gateway/cpp/opencv_deconvlucy.cpp120
-rw-r--r--sci_gateway/cpp/opencv_decorrstretch.cpp102
-rw-r--r--sci_gateway/cpp/opencv_demosaic.cpp127
-rw-r--r--sci_gateway/cpp/opencv_demosaic.cpp~127
-rw-r--r--sci_gateway/cpp/opencv_dilate.cpp119
-rw-r--r--sci_gateway/cpp/opencv_ellipse.cpp278
-rw-r--r--sci_gateway/cpp/opencv_ellipse2poly.cpp171
-rw-r--r--sci_gateway/cpp/opencv_erode.cpp117
-rw-r--r--sci_gateway/cpp/opencv_fftshift.cpp55
-rw-r--r--sci_gateway/cpp/opencv_fillconvexpoly.cpp173
-rw-r--r--sci_gateway/cpp/opencv_filter2D.cpp184
-rw-r--r--sci_gateway/cpp/opencv_findContours.cpp199
-rw-r--r--sci_gateway/cpp/opencv_fitellipse.cpp125
-rw-r--r--sci_gateway/cpp/opencv_fsamp2.cpp157
-rw-r--r--sci_gateway/cpp/opencv_ftrans2.cpp199
-rw-r--r--sci_gateway/cpp/opencv_gabor.cpp129
-rw-r--r--sci_gateway/cpp/opencv_gaussianblur.cpp132
-rw-r--r--sci_gateway/cpp/opencv_getStructuringElement.cpp147
-rw-r--r--sci_gateway/cpp/opencv_getTextSize.cpp188
-rw-r--r--sci_gateway/cpp/opencv_getgaussiankernel.cpp142
-rw-r--r--sci_gateway/cpp/opencv_getkerneltype.cpp118
-rw-r--r--sci_gateway/cpp/opencv_getrectsubpix.cpp142
-rw-r--r--sci_gateway/cpp/opencv_getrotationmatrix2D.cpp121
-rw-r--r--sci_gateway/cpp/opencv_goodfeaturestotrack.cpp168
-rw-r--r--sci_gateway/cpp/opencv_grayconnected.cpp145
-rw-r--r--sci_gateway/cpp/opencv_graycoprops.cpp408
-rw-r--r--sci_gateway/cpp/opencv_graydiffweight.cpp85
-rw-r--r--sci_gateway/cpp/opencv_graydist.cpp81
-rw-r--r--sci_gateway/cpp/opencv_histeq.cpp63
-rw-r--r--sci_gateway/cpp/opencv_houghcircles.cpp164
-rw-r--r--sci_gateway/cpp/opencv_houghlines.cpp133
-rw-r--r--sci_gateway/cpp/opencv_houghlinesp.cpp134
-rw-r--r--sci_gateway/cpp/opencv_ifftshift.cpp55
-rw-r--r--sci_gateway/cpp/opencv_im2double.cpp56
-rw-r--r--sci_gateway/cpp/opencv_imabsdiff.cpp51
-rw-r--r--sci_gateway/cpp/opencv_imadd.cpp71
-rw-r--r--sci_gateway/cpp/opencv_imattributes.cpp114
-rw-r--r--sci_gateway/cpp/opencv_imboxfilt3.cpp130
-rw-r--r--sci_gateway/cpp/opencv_imcomplement.cpp67
-rw-r--r--sci_gateway/cpp/opencv_imcontour.cpp62
-rw-r--r--sci_gateway/cpp/opencv_imcontrast.cpp100
-rw-r--r--sci_gateway/cpp/opencv_imcrop.cpp130
-rw-r--r--sci_gateway/cpp/opencv_imdivide.cpp71
-rw-r--r--sci_gateway/cpp/opencv_imextendedmax.cpp99
-rw-r--r--sci_gateway/cpp/opencv_imextendedmin.cpp100
-rw-r--r--sci_gateway/cpp/opencv_imfill.cpp192
-rw-r--r--sci_gateway/cpp/opencv_imfindcircles.cpp128
-rw-r--r--sci_gateway/cpp/opencv_imfindcircles.cpp~148
-rw-r--r--sci_gateway/cpp/opencv_imfuse.cpp470
-rw-r--r--sci_gateway/cpp/opencv_imgaborfilt.cpp159
-rw-r--r--sci_gateway/cpp/opencv_imgaussfilt3.cpp138
-rw-r--r--sci_gateway/cpp/opencv_imguidedfilter.cpp227
-rw-r--r--sci_gateway/cpp/opencv_imhistmatch.cpp296
-rw-r--r--sci_gateway/cpp/opencv_imhmax.cpp111
-rw-r--r--sci_gateway/cpp/opencv_imhmin.cpp96
-rw-r--r--sci_gateway/cpp/opencv_imimposemin.cpp89
-rw-r--r--sci_gateway/cpp/opencv_imlincomb.cpp84
-rw-r--r--sci_gateway/cpp/opencv_immultiply.cpp71
-rw-r--r--sci_gateway/cpp/opencv_impixel.cpp122
-rw-r--r--sci_gateway/cpp/opencv_impyramid.cpp103
-rw-r--r--sci_gateway/cpp/opencv_imread.cpp99
-rw-r--r--sci_gateway/cpp/opencv_imrect.cpp110
-rw-r--r--sci_gateway/cpp/opencv_imresize.cpp94
-rw-r--r--sci_gateway/cpp/opencv_imrotate.cpp81
-rw-r--r--sci_gateway/cpp/opencv_imrotate.cpp~81
-rw-r--r--sci_gateway/cpp/opencv_imsharpen.cpp59
-rw-r--r--sci_gateway/cpp/opencv_imshowpair.cpp474
-rw-r--r--sci_gateway/cpp/opencv_imsubtract.cpp71
-rw-r--r--sci_gateway/cpp/opencv_imwarp.cpp104
-rw-r--r--sci_gateway/cpp/opencv_imwrite.cpp85
-rw-r--r--sci_gateway/cpp/opencv_ind2gray.cpp115
-rw-r--r--sci_gateway/cpp/opencv_ind2rgb.cpp146
-rw-r--r--sci_gateway/cpp/opencv_integralImage.cpp145
-rw-r--r--sci_gateway/cpp/opencv_lab2double.cpp130
-rw-r--r--sci_gateway/cpp/opencv_lab2rgb.cpp331
-rw-r--r--sci_gateway/cpp/opencv_lab2uint16.cpp151
-rw-r--r--sci_gateway/cpp/opencv_lab2uint8.cpp174
-rw-r--r--sci_gateway/cpp/opencv_lab2xyz.cpp393
-rw-r--r--sci_gateway/cpp/opencv_laplacian.cpp156
-rw-r--r--sci_gateway/cpp/opencv_line.cpp211
-rw-r--r--sci_gateway/cpp/opencv_makecform.cpp99
-rw-r--r--sci_gateway/cpp/opencv_mean1.cpp64
-rw-r--r--sci_gateway/cpp/opencv_medianblur.cpp81
-rw-r--r--sci_gateway/cpp/opencv_minAreaRect.cpp125
-rw-r--r--sci_gateway/cpp/opencv_minimumenclosingcirlce.cpp108
-rw-r--r--sci_gateway/cpp/opencv_montage.cpp216
-rw-r--r--sci_gateway/cpp/opencv_morphologyEx.cpp232
-rw-r--r--sci_gateway/cpp/opencv_ntsc2rgb.cpp192
-rw-r--r--sci_gateway/cpp/opencv_puttext.cpp311
-rw-r--r--sci_gateway/cpp/opencv_pyrDown.cpp156
-rw-r--r--sci_gateway/cpp/opencv_pyrMeanShiftFiltering.cpp91
-rw-r--r--sci_gateway/cpp/opencv_pyrUp.cpp156
-rw-r--r--sci_gateway/cpp/opencv_rectangle.cpp207
-rw-r--r--sci_gateway/cpp/opencv_regionfill.cpp180
-rw-r--r--sci_gateway/cpp/opencv_rgb2lab.cpp244
-rw-r--r--sci_gateway/cpp/opencv_rgb2ntsc.cpp132
-rw-r--r--sci_gateway/cpp/opencv_rgb2xyz.cpp220
-rw-r--r--sci_gateway/cpp/opencv_roifill.cpp180
-rw-r--r--sci_gateway/cpp/opencv_roipoly.cpp145
-rw-r--r--sci_gateway/cpp/opencv_scharr.cpp155
-rw-r--r--sci_gateway/cpp/opencv_sepFilter2D.cpp261
-rw-r--r--sci_gateway/cpp/opencv_sobel.cpp172
-rw-r--r--sci_gateway/cpp/opencv_ssim.cpp94
-rw-r--r--sci_gateway/cpp/opencv_threshold.cpp146
-rw-r--r--sci_gateway/cpp/opencv_undistort.cpp118
-rw-r--r--sci_gateway/cpp/opencv_viscircles.cpp209
-rw-r--r--sci_gateway/cpp/opencv_watershed.cpp105
-rw-r--r--sci_gateway/cpp/opencv_whitepoint.cpp108
-rw-r--r--sci_gateway/cpp/opencv_wiener2.cpp178
-rw-r--r--sci_gateway/cpp/opencv_xyz2double.cpp159
-rw-r--r--sci_gateway/cpp/opencv_xyz2lab.cpp423
-rw-r--r--sci_gateway/cpp/opencv_xyz2rgb.cpp280
-rw-r--r--sci_gateway/cpp/opencv_xyz2uint16.cpp146
-rw-r--r--sci_gateway/cpp/rgb2gray.cpp46
-rw-r--r--sci_gateway/cpp/rgb2gray.cpp~46
-rw-r--r--sci_gateway/cpp/warpaffine.cpp214
-rw-r--r--sci_gateway/cpp/xyz2lab.cpp189
156 files changed, 25047 insertions, 0 deletions
diff --git a/sci_gateway/cpp/builder_gateway_cpp.sce b/sci_gateway/cpp/builder_gateway_cpp.sce
new file mode 100644
index 0000000..1f16d47
--- /dev/null
+++ b/sci_gateway/cpp/builder_gateway_cpp.sce
@@ -0,0 +1,364 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+
+mode(-1)
+lines(0)
+
+toolbox_title = "FOSSEE_Image_Processing_Toolbox";
+
+Build_64Bits = %t;
+
+
+path_builder = get_absolute_file_path('builder_gateway_cpp.sce');
+Names = [
+// "raw_dctmtx", "dctmtx";
+// "raw_multithresh", "multithresh";
+// "raw_applycform", "opencv_applycform";
+ //"raw_arrowedline", "opencv_arrowedline";
+ "raw_blur", "opencv_blur";
+// "raw_boundingRect", "opencv_boundingRect";
+// "raw_bwconvhull", "opencv_bwconvhull";
+// "raw_bwdistgeodesic", "opencv_bwdistgeodesic";
+// "raw_bwlookup", "opencv_bwlookup";
+// "raw_canny", "opencv_canny";
+ "raw_circle", "opencv_circle";
+// "raw_clipline", "opencv_clipline";
+// "raw_convexhull", "opencv_convexhull";
+// "raw_convmtx2", "opencv_convmtx2";
+// "raw_copymakeborder", "opencv_copymakeborder";
+// "raw_corner", "opencv_corner";
+// "raw_cornerEigenValsAndVecs", "opencv_cornerEigenValsAndVecs";
+// "raw_cornerHarris", "opencv_cornerHarris";
+// "raw_cornerMinEigenVal", "opencv_cornerMinEigenVal";
+// "raw_cvtColor", "opencv_cvtColor";
+// "raw_demosaic", "opencv_demosaic";
+ "raw_dilate", "opencv_dilate";
+// "raw_ellipse", "opencv_ellipse";
+// "raw_ellipse2poly", "opencv_ellipse2poly";
+ "raw_erode", "opencv_erode";
+// "raw_fftshift", "opencv_fftshift";
+// "raw_fillconvexpoly", "opencv_fillconvexpoly";
+// "raw_filter2D", "opencv_filter2D";
+// "raw_findContours", "opencv_findContours";
+// "raw_fsamp2", "opencv_fsamp2";
+
+// "raw_gabor", "opencv_gabor";
+// "raw_gaussianblur", "opencv_gaussianblur";
+// "raw_getStructuringElement", "opencv_getStructuringElement";
+// "getTextSize", "opencv_getTextSize";
+// "raw_getgaussiankernel", "opencv_getgaussiankernel";
+// "raw_getrectsubpix", "opencv_getrectsubpix";
+// "raw_getrotationmatrix2D", "opencv_getrotationmatrix2D";
+// "raw_goodfeaturestotrack", "opencv_goodfeaturestotrack";
+
+// "raw_houghcircles", "opencv_houghcircles";
+// "raw_houghlines", "opencv_houghlines";
+// "raw_houghlinesp", "opencv_houghlinesp";
+// "raw_ifftshift", "opencv_ifftshift";
+// "raw_im2double", "opencv_im2double";
+// "raw_imabsdiff", "opencv_imabsdiff";
+// "raw_imadd", "opencv_imadd";
+// "raw_imattributes", "opencv_imattributes";
+// "raw_imboxfilt3", "opencv_imboxfilt3";
+// "raw_imcomplement", "opencv_imcomplement";
+// "raw_imcontour", "opencv_imcontour";
+// "raw_imcontrast", "opencv_imcontrast";
+ "raw_imcrop", "opencv_imcrop";
+// "raw_imdivide", "opencv_imdivide";
+// "raw_imextendedmax", "opencv_imextendedmax";
+// "raw_imextendedmin", "opencv_imextendedmin";
+// "raw_imfill", "opencv_imfill";
+// "raw_imfindcircles", "opencv_imfindcircles";
+// "raw_imfuse", "opencv_imfuse";
+// "raw_imgaborfilt", "opencv_imgaborfilt";
+// "raw_imgaussfilt3", "opencv_imgaussfilt3";
+// "raw_imguidedfilter", "opencv_imguidedfilter";
+// "raw_imhmax", "opencv_imhmax";
+// "raw_imhmin", "opencv_imhmin";
+// "raw_imimposemin", "opencv_imimposemin";
+// "raw_imlincomb", "opencv_imlincomb";
+// "raw_immultiply", "opencv_immultiply";
+ "raw_impixel", "opencv_impixel";
+// "raw_impyramid", "opencv_impyramid";
+ "raw_imread", "opencv_imread";
+// "raw_imrect", "opencv_imrect";
+ "raw_imresize", "opencv_imresize";
+ "raw_imsharpen", "opencv_imsharpen";
+// "raw_imshowpair", "opencv_imshowpair";
+// "raw_imsubtract", "opencv_imsubtract";
+// "raw_imwarp", "opencv_imwarp";
+ "raw_imwrite", "opencv_imwrite";
+// "raw_ind2gray", "opencv_ind2gray";
+// "raw_ind2rgb", "opencv_ind2rgb";
+// "raw_lab2double", "opencv_lab2double";
+// "raw_lab2rgb", "opencv_lab2rgb";
+// "raw_lab2uint16", "opencv_lab2uint16";
+// "raw_lab2uint8", "opencv_lab2uint8";
+// "raw_lab2xyz", "opencv_lab2xyz";
+// "raw_laplacian", "opencv_laplacian";
+// "raw_line", "opencv_line";
+
+// "raw_medianblur", "opencv_medianblur";
+// "raw_montage", "opencv_montage";
+// "raw_morphologyEx", "opencv_morphologyEx";
+// "raw_ntsc2rgb", "opencv_ntsc2rgb";
+// "raw_puttext", "opencv_puttext";
+// "raw_pyrDown", "opencv_pyrDown";
+// "raw_pyrUp", "opencv_pyrUp";
+// "raw_rectangle", "opencv_rectangle";
+// "raw_regionfill", "opencv_regionfill";
+// "raw_rgb2lab", "opencv_rgb2lab";
+// "raw_rgb2ntsc", "opencv_rgb2ntsc";
+// "raw_rgb2xyz", "opencv_rgb2xyz";
+// "raw_roifill", "opencv_roifill";
+// "raw_roipoly", "opencv_roipoly";
+// "raw_scharr", "opencv_scharr";
+// "raw_sepFilter2D", "opencv_sepFilter2D";
+// "raw_sobel", "opencv_sobel";
+// "raw_ssim", "opencv_ssim";
+// "raw_threshold", "opencv_threshold";
+// "raw_undistort", "opencv_undistort";
+// "raw_viscircles", "opencv_viscircles";
+// "raw_watershed", "opencv_watershed";
+// "raw_whitepoint", "opencv_whitepoint";
+// "raw_wiener2", "opencv_wiener2";
+// "raw_xyz2double", "opencv_xyz2double";
+// "raw_xyz2lab", "opencv_xyz2lab";
+// "raw_xyz2rgb", "opencv_xyz2rgb";
+// "raw_xyz2uint16", "opencv_xyz2uint16";
+
+// "deconvlucy", "opencv_deconvlucy";
+// "imhistmatch", "opencv_imhistmatch";
+// "graycoprops", "opencv_graycoprops";
+// "graydiffweight", "opencv_graydiffweight";
+// "decorrstretch", "opencv_decorrstretch";
+// "adaptf", "opencv_adapthisteq";
+// "affine2d", "opencv_affine2d";
+
+
+// "approxpolyDP","approxpolyDP";
+// "arclenght","arclenght";
+// "bilateralfilter","bilateralfilter";
+// "borderInterpolate","borderInterpolate";
+// "boxfilter","boxfilter";
+// "contourarea","contourarea";
+// "boxfilter","boxfilter";
+// "fitellipse","fitellipse";
+// "getkerneltype","getkerneltype";
+// "histeq","histeq";
+ "raw_imrotate","opencv_imrotate";
+// "mean1","mean1";
+// "minAreaRect","minAreaRect";
+// "minimumenclosingcirlce","minimumenclosingcirlce";
+// "pyrMeanShiftFiltering","pyrMeanShiftFiltering";
+ "raw_rgb2gray","opencv_rgb2gray";
+// "warpaffine","warpaffine";
+
+
+
+ ];
+
+Files = [
+// "dctmtx.cpp",
+
+// "multithresh.cpp",
+// "opencv_applycform.cpp",
+ //"opencv_arrowedline.cpp",
+ "opencv_blur.cpp",
+// "opencv_boundingRect.cpp",
+// "opencv_bwconvhull.cpp",
+// "opencv_bwdistgeodesic.cpp",
+// "opencv_bwlookup.cpp",
+// "opencv_canny.cpp",
+ "opencv_circle.cpp",
+// "opencv_clipline.cpp",
+// "opencv_convexhull.cpp",
+// "opencv_convmtx2.cpp",
+// "opencv_copymakeborder.cpp",
+// "opencv_corner.cpp",
+// "opencv_cornerEigenValsAndVecs.cpp",
+// "opencv_cornerHarris.cpp",
+// "opencv_cornerMinEigenVal.cpp",
+// "opencv_cvtColor.cpp",
+// "opencv_demosaic.cpp",
+ "opencv_dilate.cpp",
+ "opencv_ellipse.cpp",
+// "opencv_ellipse2poly.cpp",
+ "opencv_erode.cpp",
+// "opencv_fftshift.cpp",
+// "opencv_fillconvexpoly.cpp",
+// "opencv_filter2D.cpp",
+// "opencv_findContours.cpp",
+// "opencv_fsamp2.cpp",
+
+// "opencv_gabor.cpp",
+// "opencv_gaussianblur.cpp",
+// "opencv_getStructuringElement.cpp",
+// "opencv_getTextSize.cpp",
+// "opencv_getgaussiankernel.cpp",
+// "opencv_getrectsubpix.cpp",
+// "opencv_getrotationmatrix2D.cpp",
+// "opencv_goodfeaturestotrack.cpp",
+
+// "opencv_houghcircles.cpp",
+// "opencv_houghlines.cpp",
+// "opencv_houghlinesp.cpp",
+// "opencv_ifftshift.cpp",
+// "opencv_im2double.cpp",
+// "opencv_imabsdiff.cpp",
+// "opencv_imadd.cpp",
+// "opencv_imattributes.cpp",
+// "opencv_imboxfilt3.cpp",
+// "opencv_imcomplement.cpp",
+// "opencv_imcontour.cpp",
+// "opencv_imcontrast.cpp",
+ "opencv_imcrop.cpp",
+// "opencv_imdivide.cpp",
+// "opencv_imextendedmax.cpp",
+// "opencv_imextendedmin.cpp",
+// "opencv_imfill.cpp",
+// "opencv_imfindcircles.cpp",
+// "opencv_imfuse.cpp",
+// "opencv_imgaborfilt.cpp",
+// "opencv_imgaussfilt3.cpp",
+// "opencv_imguidedfilter.cpp",
+// "opencv_imhmax.cpp",
+// "opencv_imhmin.cpp",
+// "opencv_imimposemin.cpp",
+// "opencv_imlincomb.cpp",
+// "opencv_immultiply.cpp",
+ "opencv_impixel.cpp",
+// "opencv_impyramid.cpp",
+ "opencv_imread.cpp",
+// "opencv_imrect.cpp",
+ "opencv_imresize.cpp",
+ "opencv_imsharpen.cpp",
+// "opencv_imshowpair.cpp",
+// "opencv_imsubtract.cpp",
+// "opencv_imwarp.cpp",
+ "opencv_imwrite.cpp",
+// "opencv_ind2gray.cpp",
+// "opencv_ind2rgb.cpp",
+// "opencv_lab2double.cpp",
+// "opencv_lab2rgb.cpp",
+// "opencv_lab2uint16.cpp",
+// "opencv_lab2uint8.cpp",
+// "opencv_lab2xyz.cpp",
+// "opencv_laplacian.cpp",
+// "opencv_line.cpp",
+
+// "opencv_medianblur.cpp",
+// "opencv_montage.cpp",
+// "opencv_morphologyEx.cpp",
+// "opencv_ntsc2rgb.cpp",
+// "opencv_puttext.cpp",
+// "opencv_pyrDown.cpp",
+// "opencv_pyrUp.cpp",
+// "opencv_rectangle.cpp",
+// "opencv_regionfill.cpp",
+// "opencv_rgb2lab.cpp",
+// "opencv_rgb2ntsc.cpp",
+// "opencv_rgb2xyz.cpp",
+// "opencv_roifill.cpp",
+// "opencv_roipoly.cpp",
+// "opencv_scharr.cpp",
+// "opencv_sepFilter2D.cpp",
+// "opencv_sobel.cpp",
+// "opencv_ssim.cpp",
+// "opencv_threshold.cpp",
+// "opencv_undistort.cpp",
+// "opencv_viscircles.cpp",
+// "opencv_watershed.cpp",
+// "opencv_whitepoint.cpp",
+// "opencv_wiener2.cpp",
+// "opencv_xyz2double.cpp",
+// "opencv_xyz2lab.cpp",
+// "opencv_xyz2rgb.cpp",
+// "opencv_xyz2uint16.cpp",
+
+
+// "opencv_deconvlucy.cpp",
+// "opencv_integralImage.cpp",
+// "opencv_imhistmatch.cpp",
+// "opencv_graycoprops.cpp",
+// "opencv_graydiffweight.cpp",
+// "opencv_decorrstretch.cpp",
+// "opencv_adapthisteq.cpp",
+// "opencv_affine2d.cpp",
+
+ "rgb2gray.cpp",
+// "warpaffine.cpp",
+// "opencv_pyrMeanShiftFiltering.cpp",
+// "opencv_minimumenclosingcirlce.cpp",
+// "opencv_minAreaRect.cpp",
+// "opencv_mean1.cpp",
+ "opencv_imrotate.cpp",
+// "opencv_getkerneltype.cpp",
+// "opencv_fitellipse.cpp",
+// "opencv_contourarea.cpp",
+// "opencv_boxfilter.cpp",
+// "opencv_borderInterpolate.cpp",
+// "opencv_bilateralfilter.cpp",
+// "opencv_arclength.cpp",
+// "opencv_approxpolyDP.cpp",
+// "opencv_histeq.cpp",
+
+
+
+ ];
+
+ 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);
+
+ [a, opt] = getversion();
+ Version = opt(2);
+
+ 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()+'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=["-D__USE_DEPRECATED_STACK_FUNCTIONS__ -w -fpermissive -I"+path_builder+"-I"+inc_base_dir+" "+"-I"+incl_base_dir+" -Wl,-rpath= "+lib_base_dir+" "+"-L"+lib_base_dir+"libopencv_core"+" "+"-L"+lib_base_dir+"libopencv_highgui"+" "+"-L"+lib_base_dir+"libopencv_imgproc" ]
+
+// export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:"+lib_base_dir
+// unix_s("export LD_LIBRARY_PATH="+lib_base_dir);
+
+// C_Flags=["-I"+inc_base_dir+" "+"-I"+incl_base_dir];
+// Linker_Flag = ["-L"+lib_base_dir+"libopencv_core"+" "+"-L"+lib_base_dir+"libopencv_highgui"+" "+"-L"+lib_base_dir+"libopencv_imgproc" ];
+
+// Linker_Flag = ["-L/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/lib/x64 -lopencv_core -L/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/lib/x64 -lopencv_imgproc -L/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/lib/x64 -lopencv_highgui" ]
+
+
+tools_path = path_builder + "../../thirdparty/linux/";
+unix_s("export LD_LIBRARY_PATH="+tools_path+"lib/"+Version+filesep()+" ");
+C_Flags=["-w -fpermissive -I"+tools_path+"include/opencv -I"+tools_path+"include/opencv2 -Wl,-rpath="+tools_path+"lib/"+Version+filesep()+" "]
+
+Linker_Flag = ["-L"+tools_path+"lib/"+Version+"-lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core "]
+
+end
+
+tbx_build_gateway(toolbox_title,Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags,"g++");
+
+clear toolbox_title 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", ..
+// names, ..
+// files, ..
+// get_absolute_file_path("builder_gateway_cpp.sce"),[],["-L/usr/local/lib -lopencv_core -L/usr/local/lib -lopencv_highgui -L/usr/lib -lopencv_imgproc -L/usr/lib -lopencv_calib3d -L/usr/lib -lopencv_video -L/usr/lib -lopencv_nonfree -L/usr/lib -lopencv_ml -L/usr/lib -lopencv_objdetect"],["-I/usr/include/scilab -I/usr/include/opencv -I/usr/include/opencv2 "],"g++ ");
+//endfunction
+
+//builder_gw_cpp();
+//clear builder_gw_cpp; // remove builder_gw_cpp on stack
+
diff --git a/sci_gateway/cpp/builder_gateway_cpp.sce~ b/sci_gateway/cpp/builder_gateway_cpp.sce~
new file mode 100644
index 0000000..c736288
--- /dev/null
+++ b/sci_gateway/cpp/builder_gateway_cpp.sce~
@@ -0,0 +1,364 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+
+
+mode(-1)
+lines(0)
+
+toolbox_title = "FOSSEE_Image_Processing_Toolbox";
+
+Build_64Bits = %t;
+
+
+path_builder = get_absolute_file_path('builder_gateway_cpp.sce');
+Names = [
+// "raw_dctmtx", "dctmtx";
+// "raw_multithresh", "multithresh";
+// "raw_applycform", "opencv_applycform";
+ //"raw_arrowedline", "opencv_arrowedline";
+ "raw_blur", "opencv_blur";
+// "raw_boundingRect", "opencv_boundingRect";
+// "raw_bwconvhull", "opencv_bwconvhull";
+// "raw_bwdistgeodesic", "opencv_bwdistgeodesic";
+// "raw_bwlookup", "opencv_bwlookup";
+// "raw_canny", "opencv_canny";
+ "raw_circle", "opencv_circle";
+// "raw_clipline", "opencv_clipline";
+// "raw_convexhull", "opencv_convexhull";
+// "raw_convmtx2", "opencv_convmtx2";
+// "raw_copymakeborder", "opencv_copymakeborder";
+// "raw_corner", "opencv_corner";
+// "raw_cornerEigenValsAndVecs", "opencv_cornerEigenValsAndVecs";
+// "raw_cornerHarris", "opencv_cornerHarris";
+// "raw_cornerMinEigenVal", "opencv_cornerMinEigenVal";
+// "raw_cvtColor", "opencv_cvtColor";
+// "raw_demosaic", "opencv_demosaic";
+ "raw_dilate", "opencv_dilate";
+// "raw_ellipse", "opencv_ellipse";
+// "raw_ellipse2poly", "opencv_ellipse2poly";
+ "raw_erode", "opencv_erode";
+// "raw_fftshift", "opencv_fftshift";
+// "raw_fillconvexpoly", "opencv_fillconvexpoly";
+// "raw_filter2D", "opencv_filter2D";
+// "raw_findContours", "opencv_findContours";
+// "raw_fsamp2", "opencv_fsamp2";
+
+// "raw_gabor", "opencv_gabor";
+// "raw_gaussianblur", "opencv_gaussianblur";
+// "raw_getStructuringElement", "opencv_getStructuringElement";
+// "getTextSize", "opencv_getTextSize";
+// "raw_getgaussiankernel", "opencv_getgaussiankernel";
+// "raw_getrectsubpix", "opencv_getrectsubpix";
+// "raw_getrotationmatrix2D", "opencv_getrotationmatrix2D";
+// "raw_goodfeaturestotrack", "opencv_goodfeaturestotrack";
+
+// "raw_houghcircles", "opencv_houghcircles";
+// "raw_houghlines", "opencv_houghlines";
+// "raw_houghlinesp", "opencv_houghlinesp";
+// "raw_ifftshift", "opencv_ifftshift";
+// "raw_im2double", "opencv_im2double";
+// "raw_imabsdiff", "opencv_imabsdiff";
+// "raw_imadd", "opencv_imadd";
+// "raw_imattributes", "opencv_imattributes";
+// "raw_imboxfilt3", "opencv_imboxfilt3";
+// "raw_imcomplement", "opencv_imcomplement";
+// "raw_imcontour", "opencv_imcontour";
+// "raw_imcontrast", "opencv_imcontrast";
+ "raw_imcrop", "opencv_imcrop";
+// "raw_imdivide", "opencv_imdivide";
+// "raw_imextendedmax", "opencv_imextendedmax";
+// "raw_imextendedmin", "opencv_imextendedmin";
+// "raw_imfill", "opencv_imfill";
+// "raw_imfindcircles", "opencv_imfindcircles";
+// "raw_imfuse", "opencv_imfuse";
+// "raw_imgaborfilt", "opencv_imgaborfilt";
+// "raw_imgaussfilt3", "opencv_imgaussfilt3";
+// "raw_imguidedfilter", "opencv_imguidedfilter";
+// "raw_imhmax", "opencv_imhmax";
+// "raw_imhmin", "opencv_imhmin";
+// "raw_imimposemin", "opencv_imimposemin";
+// "raw_imlincomb", "opencv_imlincomb";
+// "raw_immultiply", "opencv_immultiply";
+ "raw_impixel", "opencv_impixel";
+// "raw_impyramid", "opencv_impyramid";
+ "raw_imread", "opencv_imread";
+// "raw_imrect", "opencv_imrect";
+ "raw_imresize", "opencv_imresize";
+ "raw_imsharpen", "opencv_imsharpen";
+// "raw_imshowpair", "opencv_imshowpair";
+// "raw_imsubtract", "opencv_imsubtract";
+// "raw_imwarp", "opencv_imwarp";
+ "raw_imwrite", "opencv_imwrite";
+// "raw_ind2gray", "opencv_ind2gray";
+// "raw_ind2rgb", "opencv_ind2rgb";
+// "raw_lab2double", "opencv_lab2double";
+// "raw_lab2rgb", "opencv_lab2rgb";
+// "raw_lab2uint16", "opencv_lab2uint16";
+// "raw_lab2uint8", "opencv_lab2uint8";
+// "raw_lab2xyz", "opencv_lab2xyz";
+// "raw_laplacian", "opencv_laplacian";
+// "raw_line", "opencv_line";
+
+// "raw_medianblur", "opencv_medianblur";
+// "raw_montage", "opencv_montage";
+// "raw_morphologyEx", "opencv_morphologyEx";
+// "raw_ntsc2rgb", "opencv_ntsc2rgb";
+// "raw_puttext", "opencv_puttext";
+// "raw_pyrDown", "opencv_pyrDown";
+// "raw_pyrUp", "opencv_pyrUp";
+// "raw_rectangle", "opencv_rectangle";
+// "raw_regionfill", "opencv_regionfill";
+// "raw_rgb2lab", "opencv_rgb2lab";
+// "raw_rgb2ntsc", "opencv_rgb2ntsc";
+// "raw_rgb2xyz", "opencv_rgb2xyz";
+// "raw_roifill", "opencv_roifill";
+// "raw_roipoly", "opencv_roipoly";
+// "raw_scharr", "opencv_scharr";
+// "raw_sepFilter2D", "opencv_sepFilter2D";
+// "raw_sobel", "opencv_sobel";
+// "raw_ssim", "opencv_ssim";
+// "raw_threshold", "opencv_threshold";
+// "raw_undistort", "opencv_undistort";
+// "raw_viscircles", "opencv_viscircles";
+// "raw_watershed", "opencv_watershed";
+// "raw_whitepoint", "opencv_whitepoint";
+// "raw_wiener2", "opencv_wiener2";
+// "raw_xyz2double", "opencv_xyz2double";
+// "raw_xyz2lab", "opencv_xyz2lab";
+// "raw_xyz2rgb", "opencv_xyz2rgb";
+// "raw_xyz2uint16", "opencv_xyz2uint16";
+
+// "deconvlucy", "opencv_deconvlucy";
+// "imhistmatch", "opencv_imhistmatch";
+// "graycoprops", "opencv_graycoprops";
+// "graydiffweight", "opencv_graydiffweight";
+// "decorrstretch", "opencv_decorrstretch";
+// "adaptf", "opencv_adapthisteq";
+// "affine2d", "opencv_affine2d";
+
+
+// "approxpolyDP","approxpolyDP";
+// "arclenght","arclenght";
+// "bilateralfilter","bilateralfilter";
+// "borderInterpolate","borderInterpolate";
+// "boxfilter","boxfilter";
+// "contourarea","contourarea";
+// "boxfilter","boxfilter";
+// "fitellipse","fitellipse";
+// "getkerneltype","getkerneltype";
+// "histeq","histeq";
+ "raw_imrotate","opencv_imrotate";
+// "mean1","mean1";
+// "minAreaRect","minAreaRect";
+// "minimumenclosingcirlce","minimumenclosingcirlce";
+// "pyrMeanShiftFiltering","pyrMeanShiftFiltering";
+ "raw_rgb2gray","opencv_rgb2gray";
+// "warpaffine","warpaffine";
+
+
+
+ ];
+
+Files = [
+// "dctmtx.cpp",
+
+// "multithresh.cpp",
+// "opencv_applycform.cpp",
+ //"opencv_arrowedline.cpp",
+ "opencv_blur.cpp",
+// "opencv_boundingRect.cpp",
+// "opencv_bwconvhull.cpp",
+// "opencv_bwdistgeodesic.cpp",
+// "opencv_bwlookup.cpp",
+// "opencv_canny.cpp",
+ "opencv_circle.cpp",
+// "opencv_clipline.cpp",
+// "opencv_convexhull.cpp",
+// "opencv_convmtx2.cpp",
+// "opencv_copymakeborder.cpp",
+// "opencv_corner.cpp",
+// "opencv_cornerEigenValsAndVecs.cpp",
+// "opencv_cornerHarris.cpp",
+// "opencv_cornerMinEigenVal.cpp",
+// "opencv_cvtColor.cpp",
+// "opencv_demosaic.cpp",
+ "opencv_dilate.cpp",
+ "opencv_ellipse.cpp",
+// "opencv_ellipse2poly.cpp",
+ "opencv_erode.cpp",
+// "opencv_fftshift.cpp",
+// "opencv_fillconvexpoly.cpp",
+// "opencv_filter2D.cpp",
+// "opencv_findContours.cpp",
+// "opencv_fsamp2.cpp",
+
+// "opencv_gabor.cpp",
+// "opencv_gaussianblur.cpp",
+// "opencv_getStructuringElement.cpp",
+// "opencv_getTextSize.cpp",
+// "opencv_getgaussiankernel.cpp",
+// "opencv_getrectsubpix.cpp",
+// "opencv_getrotationmatrix2D.cpp",
+// "opencv_goodfeaturestotrack.cpp",
+
+// "opencv_houghcircles.cpp",
+// "opencv_houghlines.cpp",
+// "opencv_houghlinesp.cpp",
+// "opencv_ifftshift.cpp",
+// "opencv_im2double.cpp",
+// "opencv_imabsdiff.cpp",
+// "opencv_imadd.cpp",
+// "opencv_imattributes.cpp",
+// "opencv_imboxfilt3.cpp",
+// "opencv_imcomplement.cpp",
+// "opencv_imcontour.cpp",
+// "opencv_imcontrast.cpp",
+ "opencv_imcrop.cpp",
+// "opencv_imdivide.cpp",
+// "opencv_imextendedmax.cpp",
+// "opencv_imextendedmin.cpp",
+// "opencv_imfill.cpp",
+// "opencv_imfindcircles.cpp",
+// "opencv_imfuse.cpp",
+// "opencv_imgaborfilt.cpp",
+// "opencv_imgaussfilt3.cpp",
+// "opencv_imguidedfilter.cpp",
+// "opencv_imhmax.cpp",
+// "opencv_imhmin.cpp",
+// "opencv_imimposemin.cpp",
+// "opencv_imlincomb.cpp",
+// "opencv_immultiply.cpp",
+ "opencv_impixel.cpp",
+// "opencv_impyramid.cpp",
+ "opencv_imread.cpp",
+// "opencv_imrect.cpp",
+ "opencv_imresize.cpp",
+ "opencv_imsharpen.cpp",
+// "opencv_imshowpair.cpp",
+// "opencv_imsubtract.cpp",
+// "opencv_imwarp.cpp",
+ "opencv_imwrite.cpp",
+// "opencv_ind2gray.cpp",
+// "opencv_ind2rgb.cpp",
+// "opencv_lab2double.cpp",
+// "opencv_lab2rgb.cpp",
+// "opencv_lab2uint16.cpp",
+// "opencv_lab2uint8.cpp",
+// "opencv_lab2xyz.cpp",
+// "opencv_laplacian.cpp",
+// "opencv_line.cpp",
+
+// "opencv_medianblur.cpp",
+// "opencv_montage.cpp",
+// "opencv_morphologyEx.cpp",
+// "opencv_ntsc2rgb.cpp",
+// "opencv_puttext.cpp",
+// "opencv_pyrDown.cpp",
+// "opencv_pyrUp.cpp",
+// "opencv_rectangle.cpp",
+// "opencv_regionfill.cpp",
+// "opencv_rgb2lab.cpp",
+// "opencv_rgb2ntsc.cpp",
+// "opencv_rgb2xyz.cpp",
+// "opencv_roifill.cpp",
+// "opencv_roipoly.cpp",
+// "opencv_scharr.cpp",
+// "opencv_sepFilter2D.cpp",
+// "opencv_sobel.cpp",
+// "opencv_ssim.cpp",
+// "opencv_threshold.cpp",
+// "opencv_undistort.cpp",
+// "opencv_viscircles.cpp",
+// "opencv_watershed.cpp",
+// "opencv_whitepoint.cpp",
+// "opencv_wiener2.cpp",
+// "opencv_xyz2double.cpp",
+// "opencv_xyz2lab.cpp",
+// "opencv_xyz2rgb.cpp",
+// "opencv_xyz2uint16.cpp",
+
+
+// "opencv_deconvlucy.cpp",
+// "opencv_integralImage.cpp",
+// "opencv_imhistmatch.cpp",
+// "opencv_graycoprops.cpp",
+// "opencv_graydiffweight.cpp",
+// "opencv_decorrstretch.cpp",
+// "opencv_adapthisteq.cpp",
+// "opencv_affine2d.cpp",
+
+ "rgb2gray.cpp",
+// "warpaffine.cpp",
+// "opencv_pyrMeanShiftFiltering.cpp",
+// "opencv_minimumenclosingcirlce.cpp",
+// "opencv_minAreaRect.cpp",
+// "opencv_mean1.cpp",
+ "opencv_imrotate.cpp",
+// "opencv_getkerneltype.cpp",
+// "opencv_fitellipse.cpp",
+// "opencv_contourarea.cpp",
+// "opencv_boxfilter.cpp",
+// "opencv_borderInterpolate.cpp",
+// "opencv_bilateralfilter.cpp",
+// "opencv_arclength.cpp",
+// "opencv_approxpolyDP.cpp",
+// "opencv_histeq.cpp",
+
+
+
+ ];
+
+ 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);
+
+ [a, opt] = getversion();
+ Version = opt(2);
+
+ 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()+'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=["-D__USE_DEPRECATED_STACK_FUNCTIONS__ -w -fpermissive -I"+path_builder+"-I"+inc_base_dir+" "+"-I"+incl_base_dir+" -Wl,-rpath= "+lib_base_dir+" "+"-L"+lib_base_dir+"libopencv_core"+" "+"-L"+lib_base_dir+"libopencv_highgui"+" "+"-L"+lib_base_dir+"libopencv_imgproc" ]
+
+// export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:"+lib_base_dir
+// unix_s("export LD_LIBRARY_PATH="+lib_base_dir);
+
+// C_Flags=["-I"+inc_base_dir+" "+"-I"+incl_base_dir];
+// Linker_Flag = ["-L"+lib_base_dir+"libopencv_core"+" "+"-L"+lib_base_dir+"libopencv_highgui"+" "+"-L"+lib_base_dir+"libopencv_imgproc" ];
+
+// Linker_Flag = ["-L/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/lib/x64 -lopencv_core -L/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/lib/x64 -lopencv_imgproc -L/home/fossee/Desktop/FOSSEE_Image_Processing_Toolbox/thirdparty/linux/lib/x64 -lopencv_highgui" ]
+
+unix_s("export LD_LIBRARY_PATH="+tools_path+"lib/"+Version+filesep()+" ");
+tools_path = path_builder + "../../thirdparty/linux/";
+
+C_Flags=["-w -fpermissive -I"+tools_path+"include/opencv -I"+tools_path+"include/opencv2 -Wl,-rpath="+tools_path+"lib/"+Version+filesep()+" "]
+
+Linker_Flag = ["-L"+tools_path+"lib/"+Version+"-lopencv_shape -lopencv_stitching -lopencv_objdetect -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_video -lopencv_photo -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_core "]
+
+end
+
+tbx_build_gateway(toolbox_title,Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags,"g++");
+
+clear toolbox_title 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", ..
+// names, ..
+// files, ..
+// get_absolute_file_path("builder_gateway_cpp.sce"),[],["-L/usr/local/lib -lopencv_core -L/usr/local/lib -lopencv_highgui -L/usr/lib -lopencv_imgproc -L/usr/lib -lopencv_calib3d -L/usr/lib -lopencv_video -L/usr/lib -lopencv_nonfree -L/usr/lib -lopencv_ml -L/usr/lib -lopencv_objdetect"],["-I/usr/include/scilab -I/usr/include/opencv -I/usr/include/opencv2 "],"g++ ");
+//endfunction
+
+//builder_gw_cpp();
+//clear builder_gw_cpp; // remove builder_gw_cpp on stack
+
diff --git a/sci_gateway/cpp/cleaner.sce b/sci_gateway/cpp/cleaner.sce
new file mode 100644
index 0000000..4afc35c
--- /dev/null
+++ b/sci_gateway/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('libFOSSEE_Image_Processing_Toolbox.so') <> [] then
+ mdelete('libFOSSEE_Image_Processing_Toolbox.so');
+end
+// ------------------------------------------------------
+if fileinfo('libFOSSEE_Image_Processing_Toolbox.c') <> [] then
+ mdelete('libFOSSEE_Image_Processing_Toolbox.c');
+end
+// ------------------------------------------------------
+chdir(curdir);
+// ------------------------------------------------------
diff --git a/sci_gateway/cpp/common.cpp b/sci_gateway/cpp/common.cpp
new file mode 100644
index 0000000..c19f58a
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/common.cpp~ b/sci_gateway/cpp/common.cpp~
new file mode 100644
index 0000000..c19f58a
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/common.h b/sci_gateway/cpp/common.h
new file mode 100644
index 0000000..5de6cf7
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/dctmtx.cpp b/sci_gateway/cpp/dctmtx.cpp
new file mode 100644
index 0000000..17683d2
--- /dev/null
+++ b/sci_gateway/cpp/dctmtx.cpp
@@ -0,0 +1,96 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_n*n_matrix=dctmtx(double n) */
+
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define PI 3.14
+
+ int dctmtx(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows=0;
+ int iCols=0;
+ int piRows=0;
+ int piCols=0;
+ int* piAddr2=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen=NULL;
+ char **val;
+ int i,j;
+ int error;
+ double n;
+ Mat img,dst;
+ //checking input and output argument
+ CheckInputArgument(pvApiCtx,1,1);
+ CheckOutputArgument(pvApiCtx,1,1);
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of first argument
+ error=getScalarDouble(pvApiCtx,piAddr1,&n) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ int k=0;
+ double *mat;
+ int s=n;
+ mat=(double *)malloc(sizeof(double)*n*n);
+ for(int i=0;i<n;i++)
+ {
+ for(int j=0;j<n;j++)
+ {
+ if(i==0)
+ {
+ mat[i+s*j]=(1/(sqrt(n)));
+ }
+ else
+ {
+ double temp,temp1;
+ temp1=2/n;
+ temp=(2*j+1)*i*PI;
+ temp=temp/(2*n);
+ temp=(sqrt(temp1))*(cos(temp));
+ mat[i+ s*j]= temp;
+ }
+ }
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,n,n,mat);
+ free(mat);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/lab2xyz.cpp b/sci_gateway/cpp/lab2xyz.cpp
new file mode 100644
index 0000000..28ed422
--- /dev/null
+++ b/sci_gateway/cpp/lab2xyz.cpp
@@ -0,0 +1,271 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* overloaded function */
+/* Syntax : return_matrix_3_xyz_values=lab2xyz(matrix_of_3_labvalues a) */
+/* ==================================================================== */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X 95.047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 100.000;
+ #define REF_Z 108.883;
+
+ struct Color
+ {
+ float R,G,B,X,Y,Z,L,a,b;
+ };
+
+ Color lab2xyz1(float l, float a, float b)
+ {
+ float y = (l + 16) / 116;
+ float x = a / 500 + y;
+ float z = y - b / 200;
+ if(pow(y,3) > 0.008856)
+ {
+ y = pow(y,3);
+ }
+ else
+ {
+ y =(y-16/116)/7.787;
+ }
+ if (pow(x,3) > 0.008856)
+ {
+ x = pow(x,3);
+ }
+ else
+ {
+ x = (x-16/116)/7.787;
+ }
+ if (pow(z,3) > 0.008856)
+ {
+ z = pow(z,3);
+ }
+ else
+ {
+ z =(z-16/ 116 ) / 7.787;
+ }
+
+ Color xyz;
+ xyz.X= x * REF_X;
+ xyz.Y = y * REF_Y;
+ xyz.Z = z * REF_Z;
+ return xyz;
+
+ }
+
+ Color lab2xyz2(float l, float a, float b,char *s)
+ {
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ //if else condition for checking various input arguments and assign values accordingly
+ if(!strcmp(s,"a"))
+ {
+ REF_X1=1.0985;
+ REF_Y1= 1.0000;
+ REF_Z1=0.3558;
+ }
+ else if(!strcmp(s,"c"))
+ {
+ REF_X1=0.9807;
+ REF_Y1= 1.0000;
+ REF_Z1=1.1822;
+ }
+ else if(!strcmp(s,"d50"))
+ {
+ REF_X1=0.9642;
+ REF_Y1= 1.0000;
+ REF_Z1=0.8251;
+ }
+ else if(!strcmp(s,"d65"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(!strcmp(s,"icc"))
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ else if(!strcmp(s,"e"))
+ {
+ REF_X1=1.000;
+ REF_Y1=1.000;
+ REF_Z1=1.000;
+ }
+ float y = (l + 16) / 116;
+ float x = a / 500 + y;
+ float z = y - b / 200;
+ if (pow(y,3) > 0.008856)
+ {
+ y=pow(y,3);
+ }
+ else
+ {
+ y=(y-16/116)/7.787;
+ }
+ if(pow(x,3) > 0.008856)
+ {
+ x=pow(x,3);
+ }
+ else
+ {
+ x=(x-16/116)/7.787;
+ }
+ if (pow(z,3) > 0.008856)
+ {
+ z=pow(z,3);
+ }
+ else
+ {
+ z=(z-16/116)/7.787;
+ }
+ Color xyz;
+ xyz.X= x * REF_X1;
+ xyz.Y = y * REF_Y1;
+ xyz.Z = z * REF_Z1;
+ return xyz;
+ }
+ int lab2xyz(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows=0;
+ int iCols=0;
+ int piRows=0;
+ int piCols=0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen=NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img,dst;
+ float R,G,B;
+ int k=0;
+ int *piAddrNew = NULL;
+ double *pstDataR=NULL;
+ double *pstDataG=NULL;
+ double *pstDataB=NULL;
+ double *r,*g,*b;
+ int m=0;
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //retrive address of the list
+ sciErr=getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr=getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ r=(double *)malloc(sizeof(double)*iRows*iCols);
+ g=(double *)malloc(sizeof(double)*iRows*iCols);
+ b=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ R=(pstDataR[k]);
+ G=(pstDataG[k]);
+ B= (pstDataB[k++]);
+ out=lab2xyz1(R,G,B);
+ r[m]=(out.X)/100;
+ g[m]=(out.Y)/100;
+ b[m++]=(out.Z)/100;
+ }
+ }
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the R value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.c b/sci_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.c
new file mode 100644
index 0000000..99d8ef5
--- /dev/null
+++ b/sci_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.c
@@ -0,0 +1,52 @@
+#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_blur;
+extern Gatefunc opencv_circle;
+extern Gatefunc opencv_dilate;
+extern Gatefunc opencv_erode;
+extern Gatefunc opencv_imcrop;
+extern Gatefunc opencv_impixel;
+extern Gatefunc opencv_imread;
+extern Gatefunc opencv_imresize;
+extern Gatefunc opencv_imsharpen;
+extern Gatefunc opencv_imwrite;
+extern Gatefunc opencv_imrotate;
+extern Gatefunc opencv_rgb2gray;
+static GenericTable Tab[]={
+ {(Myinterfun)sci_gateway,opencv_blur,"raw_blur"},
+ {(Myinterfun)sci_gateway,opencv_circle,"raw_circle"},
+ {(Myinterfun)sci_gateway,opencv_dilate,"raw_dilate"},
+ {(Myinterfun)sci_gateway,opencv_erode,"raw_erode"},
+ {(Myinterfun)sci_gateway,opencv_imcrop,"raw_imcrop"},
+ {(Myinterfun)sci_gateway,opencv_impixel,"raw_impixel"},
+ {(Myinterfun)sci_gateway,opencv_imread,"raw_imread"},
+ {(Myinterfun)sci_gateway,opencv_imresize,"raw_imresize"},
+ {(Myinterfun)sci_gateway,opencv_imsharpen,"raw_imsharpen"},
+ {(Myinterfun)sci_gateway,opencv_imwrite,"raw_imwrite"},
+ {(Myinterfun)sci_gateway,opencv_imrotate,"raw_imrotate"},
+ {(Myinterfun)sci_gateway,opencv_rgb2gray,"raw_rgb2gray"},
+};
+
+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_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.so b/sci_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.so
new file mode 100755
index 0000000..541d4a4
--- /dev/null
+++ b/sci_gateway/cpp/libFOSSEE_Image_Processing_Toolbox.so
Binary files differ
diff --git a/sci_gateway/cpp/loader.sce b/sci_gateway/cpp/loader.sce
new file mode 100644
index 0000000..eedb234
--- /dev/null
+++ b/sci_gateway/cpp/loader.sce
@@ -0,0 +1,32 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce : Please, do not edit this file
+// ----------------------------------------------------------------------------
+//
+libFOSSEE_Image_Pro_path = get_absolute_file_path('loader.sce');
+//
+// ulink previous function with same name
+[bOK, ilib] = c_link('libFOSSEE_Image_Processing_Toolbox');
+if bOK then
+ ulink(ilib);
+end
+//
+list_functions = [ 'raw_blur';
+ 'raw_circle';
+ 'raw_dilate';
+ 'raw_erode';
+ 'raw_imcrop';
+ 'raw_impixel';
+ 'raw_imread';
+ 'raw_imresize';
+ 'raw_imsharpen';
+ 'raw_imwrite';
+ 'raw_imrotate';
+ 'raw_rgb2gray';
+];
+addinter(libFOSSEE_Image_Pro_path + filesep() + 'libFOSSEE_Image_Processing_Toolbox' + getdynlibext(), 'libFOSSEE_Image_Processing_Toolbox', list_functions);
+// remove temp. variables on stack
+clear libFOSSEE_Image_Pro_path;
+clear bOK;
+clear ilib;
+clear list_functions;
+// ----------------------------------------------------------------------------
diff --git a/sci_gateway/cpp/multithresh.cpp b/sci_gateway/cpp/multithresh.cpp
new file mode 100644
index 0000000..05a82f3
--- /dev/null
+++ b/sci_gateway/cpp/multithresh.cpp
@@ -0,0 +1,208 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_matrix_of_threshold_levels=multithresh(InputArray src,int level) */
+/* ==================================================================== */
+/*The function return various threshold levels:*/
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+
+ //global variables
+ float **p,**s,**h;
+ float **as,**ds;
+ float fast(int n,int i,int j,int index[])
+ {
+ int k,index1;
+ float s;
+ float max = INT_MIN;
+ if(i>256)
+ {
+ return INT_MIN;
+ }
+ if(n==0)
+ return h[i][j];
+ if(ds[i][n]!=-1.000000)
+ return ds[i][n];
+ for(k=i;k<=256;k++)
+ {
+ s=h[i][k]+fast(n-1,k+1,j,index);
+ if(s>max)
+ {
+ max=s;
+ as[i][n]=k;
+ index[n]=k;
+
+ }
+ }
+ return ds[i][n]=max;
+ }
+
+ int multithresh(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr2=NULL ;
+ double thresh;
+ float C;
+ int i,j;
+ int error;
+ //checking input argument
+ CheckInputArgument(pvApiCtx,2,2);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //for first argument
+ Mat img;
+ retrieveImage(img,1);
+ //second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of fifth argument
+ error=getScalarDouble(pvApiCtx,piAddr2,&thresh) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //code for histogram calculation
+ Mat imageh;
+ cvtColor(img, imageh, CV_BGR2GRAY);
+ // number of bins
+ int histSize[1] = {256};
+ // min andax pixel value
+ float hranges[2] = {0, 256};
+ const float* ranges[1] = {hranges};
+ int channels[1] = {0}; // only 1 channel used
+ cv::MatND hist;
+ calcHist(&imageh, 1, channels, cv::Mat(), hist, 1, histSize, ranges);
+ //code for ostu method for histogram calculation
+ float *hi;
+ hi=(float *)malloc(sizeof(float)*257);
+ float nPixels = imageh.total();
+ for(i=1;i<257;i++)
+ {
+ hi[i]=(float)(hist.at<float>(i-1));
+ }
+ p=(float **)malloc(sizeof(float *)*257);
+ for(i=0;i<257;i++)
+ {
+ p[i]=(float *)malloc(sizeof(float)*257);
+ }
+ s=(float **)malloc(sizeof(float *)*257);
+ for(i=0;i<257;i++)
+ {
+ s[i]=(float *)malloc(sizeof(float)*257);
+ }
+ h=(float **)malloc(sizeof(float *)*257);
+ for(i=0;i<257;i++)
+ {
+ h[i]=(float *)malloc(sizeof(float)*257);
+ }
+ for(i=0;i<257;i++)
+ {
+ for(j=0;j<257;j++)
+ {
+ p[i][j]=0;
+ s[i][j]=0;
+ h[i][j]=0;
+ }
+ }
+ p[1][0]=0;
+ s[1][0]=0;
+ for(i=0;i<256;i++)
+ {
+ p[1][i+1]=p[1][i]+hi[i+1];
+ s[1][i+1]=s[1][i]+((i+1)*(hi[i+1]));
+ }
+ for(i=2;i<257;i++)
+ {
+ for(j=1;j<257;j++)
+ {
+ p[i][j]=p[1][j]-p[1][i-1];
+ s[i][j]=s[1][j]-s[1][i-1];
+ }
+ }
+ float temp,temp1;
+ for(j=1;j<257;j++)
+ {
+ for(i=1;i<=j;i++)
+ {
+ temp=(s[i][j])*(s[i][j]);
+ temp1=(temp/p[i][j]);
+ h[i][j]=temp1;
+ }
+ }
+ as=(float **)malloc(sizeof(float *)*257);
+ for(i=0;i<257;i++)
+ {
+ as[i]=(float *)malloc(sizeof(float)*257);
+ }
+ ds=(float **)malloc(sizeof(float *)*257);
+ for(i=0;i<257;i++)
+ {
+ ds[i]=(float *)malloc(sizeof(float)*257);
+ }
+ for(i=0;i<257;i++)
+ {
+ for(j=0;j<257;j++)
+ {
+ ds[i][j]=-1.000000;
+ }
+ }
+ int n=(int )thresh;
+ int index[n+1];
+ fast(n,1,256,index);
+ int a=0;
+ double *output=NULL;int k=0;
+ output=( double *)malloc(sizeof(double)*n);
+ for(i=n;i>=1;i--)
+ {
+ a=as[a+1][i];
+ output[k]=a;
+ k++;
+ }
+ for(i=0;i<257;i++)
+ {
+ free(h[i]);
+ free(as[i]);
+ free(ds[i]);
+ }
+ free(h);
+ free(as);
+ free(ds);
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,1,n,output);
+ free(output);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx,1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_adapthisteq.cpp b/sci_gateway/cpp/opencv_adapthisteq.cpp
new file mode 100644
index 0000000..334f529
--- /dev/null
+++ b/sci_gateway/cpp/opencv_adapthisteq.cpp
@@ -0,0 +1,201 @@
+/*************************************************************************************
+Author : Yash S. Bhalgat
+***************************************************************************************
+---------- Performs Contrast Limited Adaptive Histogram Equalisation -------------
+Usage :
+ 1) output_img = adapthisteq(input_img);
+ In this usage, the image itself is used as the guidance image.
+
+ 2) output_img = adapthisteq(input_img, clip_limit);
+Example :
+ img = imread("lena.jpg");
+ imshow(img);
+ output_img = adapthisteq(img, img, 9);
+ imshow(output_img);
+***********************************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <algorithm> // std::max
+
+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_adapthisteq(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int i,j,k;
+ double clip_limit;
+
+ //Default clip limit
+ clip_limit = 0.001;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ int inputarg = *getNbInputArgument(pvApiCtx);
+
+
+ Mat input_img;
+ retrieveImage(input_img,1);
+
+ if(inputarg == 2){
+ //for value of clip_limit
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &clip_limit);
+ if(intErr)
+ return intErr;
+ }
+
+
+ //Main function
+ //cvtColor(input_img, input_img, CV_RGB2GRAY);
+
+ float C[256];
+
+ int row = input_img.rows;
+ int col = input_img.cols;
+
+ int window_x = 90;
+ int window_y = 90;
+
+ int min_x, min_y, max_x, max_y;
+ Mat window_matrix;
+
+ //float clip_limit = 0.001;
+
+ int histSize = 256; //from 0 to 255
+ float range[] = { 0, 256 } ;
+ const float* histRange = { range };
+
+ Mat H;
+ Mat output_img = Mat::zeros(input_img.size(), input_img.type());
+
+ if(input_img.channels()==1){
+ for(int i=0; i<row; i++){
+ for(int j=0; j<col; j++){
+ min_x = max(0,i-window_x);
+ min_y = max(0,j-window_y);
+ max_x = min(row-1,i+window_x);
+ max_y = min(col-1,j+window_y);
+ window_matrix = input_img(Range(min_x, max_x), Range(min_y, max_y));
+ //window_matrix = inputImage(min_x:max_x,min_y:max_y);
+
+ if(input_img.at<uchar>(i,j)==0) output_img.at<uchar>(i,j) =0;
+ else{
+ calcHist(&window_matrix, 1, 0, Mat(), H, 1, &histSize, &histRange);
+
+ int N = window_matrix.rows;
+ int M = window_matrix.cols;
+ H=H/(N*M);
+ // cout<<H<<endl;
+
+ for(int z=0; z<256; z++){
+ if(H.at<float>(0,z) > clip_limit) H.at<float>(0,z) = clip_limit;
+ }
+
+ float contrastArea = 1.0 - cv::sum(H).val[0];
+ float height = contrastArea / 256.00;
+
+ H = H + height;
+ //cout<<cv::sum(H).val[0]<<endl;
+ C[0] = H.at<float>(0,0)*255;
+ for(int k=1; k<256; k++){
+ C[k]= C[k-1] + H.at<float>(0,k)*255;
+ }
+ //cout<<C[255]<<endl;
+ output_img.at<uchar>(i,j) = C[input_img.at<uchar>(i,j)];
+ }
+ }
+ }
+ }
+ else if(input_img.channels()==3){
+ vector<cv::Mat> Ichannels;
+ split(input_img, Ichannels);
+
+ for(int d=0; d<3; d++){
+ for(int i=0; i<row; i++){
+ for(int j=0; j<col; j++){
+ min_x = max(0,i-window_x);
+ min_y = max(0,j-window_y);
+ max_x = min(row-1,i+window_x);
+ max_y = min(col-1,j+window_y);
+
+ window_matrix = Ichannels[d](Range(min_x, max_x), Range(min_y, max_y));
+
+ if(Ichannels[d].at<uchar>(i,j)==0) output_img.at<Vec3b>(i,j)[d] =0;
+ else{
+ calcHist(&window_matrix, 1, 0, Mat(), H, 1, &histSize, &histRange);
+
+ int N = window_matrix.rows;
+ int M = window_matrix.cols;
+ H=H/(N*M);
+ // cout<<H<<endl;
+
+ for(int z=0; z<256; z++){
+ if(H.at<float>(0,z) > clip_limit) H.at<float>(0,z) = clip_limit;
+ }
+
+ float contrastArea = 1.0 - cv::sum(H).val[0];
+ float height = contrastArea / 256.00;
+
+ H = H + height;
+ //cout<<cv::sum(H).val[0]<<endl;
+ C[0] = H.at<float>(0,0)*255;
+ for(int k=1; k<256; k++){
+ C[k]= C[k-1] + H.at<float>(0,k)*255;
+ }
+ //cout<<C[255]<<endl;
+ output_img.at<Vec3b>(i,j)[d] = C[Ichannels[d].at<uchar>(i,j)];
+ }
+ }
+ }
+ }
+
+
+ }
+
+
+
+ //returning image
+ string tempstring = type2str(output_img.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,output_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_gateway/cpp/opencv_affine2d.cpp b/sci_gateway/cpp/opencv_affine2d.cpp
new file mode 100644
index 0000000..8dc1200
--- /dev/null
+++ b/sci_gateway/cpp/opencv_affine2d.cpp
@@ -0,0 +1,122 @@
+/*******************************************************************
+Author : Yash S. Bhalgat
+********************************************************************
+Usage : T = affine2d(A);
+Output: T - 3x3 matrix equivalent to tform.T matrix in Matlab output
+********************************************************************/
+
+#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_affine2d(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piLen = NULL;
+ int *piAddr1 = NULL;
+ char **ddepth = NULL;
+ int i,j,k;
+ double *inpMatrix;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ //for inputMatrix
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols ,&inpMatrix);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ int n=iRows;
+ double inputMatrix[n][n];
+ //assigning values to actual kernelMatrix
+ for(i=0;i<n;i++)
+ for(j=0;j<n;j++)
+ inputMatrix[i][j]=inpMatrix[(i*n)+j];
+ // converting the array to a matrix, so that we can pass it into the filter2D function
+
+ Mat inpMat(n, n, CV_64FC1, &inputMatrix);
+
+ Point2f src[3];
+ Point2f res[3];
+
+ Point3d s1 = Point3d(0,0,1);
+ Point3d s2 = Point3d(10,0,1);
+ Point3d s3 = Point3d(0,5,1);
+ //cout<<s1<<endl;
+
+ Mat s = (Mat)s1;
+ Mat t = inpMat*s;
+ Mat r = t.rowRange(0, t.rows-1);
+ Mat ss = s.rowRange(0, s.rows-1);
+ src[0] = (Point2f)ss;
+ res[0] = (Point2f)r;
+
+ s = (Mat)s2;
+ t = inpMat*s;
+ r = t.rowRange(0, t.rows-1);
+ ss = s.rowRange(0, s.rows-1);
+ src[1] = (Point2f)ss;
+ res[1] = (Point2f)r;
+
+ s = (Mat)s3;
+ t = inpMat*s;
+ r = t.rowRange(0, t.rows-1);
+ ss = s.rowRange(0, s.rows-1);
+ src[2] = (Point2f)ss;
+ res[2] = (Point2f)r;
+
+ Mat warp_mat = getAffineTransform(src, res);
+
+ Mat outputMatrix = Mat::zeros(n, n, warp_mat.type());
+ Mat warp_mat_t = warp_mat.t();
+ for(i=0; i<3; i++)
+ for(j=0; j<2; j++)
+ outputMatrix.at<double>(i,j) = warp_mat_t.at<double>(i,j);
+
+ outputMatrix.at<double>(0,2) = 0;
+ outputMatrix.at<double>(1,2) = 0;
+ outputMatrix.at<double>(2,2) = 1.0;
+
+ //returning image
+ string tempstring = type2str(outputMatrix.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,outputMatrix,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_gateway/cpp/opencv_applycform.cpp b/sci_gateway/cpp/opencv_applycform.cpp
new file mode 100644
index 0000000..ea29604
--- /dev/null
+++ b/sci_gateway/cpp/opencv_applycform.cpp
@@ -0,0 +1,371 @@
+/********************************************************
+Function :applycform
+Syntax :B=applycform(image,string)
+*string : 'xyz2lab' 'lab2xyz' 'srgb2xyz'
+ 'xyz2srgb' 'srgb2lab' 'lab2srgb'
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+ struct Color
+{
+ float R,G,B,X,Y,Z,R1,G1,B1,r,g,b;
+};
+Color rgb2lab(float R, float G, float B)
+{
+
+ float r = R/255.f; //R 0..1
+ float g = G/255.f; //G 0..1
+ float b = B/255.f; //B 0..1
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz;
+ if (r <= 0.04045)
+ r = r/12.92;
+ else
+ r = (float)pow((r+0.055)/1.055,2.4);
+ if (g <= 0.04045)
+ g = g/12.92;
+ else
+ g = (float)pow((g+0.055)/1.055,2.4);
+ if (b <= 0.04045)
+ b = b/12.92;
+ else
+ b = (float)pow((b+0.055)/1.055,2.4);
+ float X = 0.4124*r + 0.3576*g + 0.1805*b;
+ float Y = 0.2126*r + 0.7152 *g + 0.0722 *b;
+ float Z = 0.0193*r + 0.1192*g + 0.9505 *b;
+ float xr = X/REF_X;
+ float yr = Y/REF_Y;
+ float zr = Z/REF_Z;
+ if ( xr > eps )
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if ( yr > eps )
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if ( zr > eps )
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Color rgb;
+ rgb.R1= ( 116 * fy ) - 16;
+ rgb.G1= 500*(fx-fy);
+ rgb.B1= 200*(fy-fz);
+ return rgb;
+
+}
+Color xyz2lab(float R, float G, float B)
+{
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz,Ls,as,bs;
+ float xr=R/REF_X;
+ float yr=G/REF_Y;
+ float zr=B/REF_Z;
+ if ( xr > eps )
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if ( yr > eps )
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if ( zr > eps )
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Ls = ( 116 * fy ) - 16;
+ as = 500*(fx-fy);
+ bs = 200*(fy-fz);
+ Color rgb;
+ rgb.R1 =Ls;
+ rgb.G1 =as;
+ rgb.B1 =bs;
+ return rgb;
+}
+Color rgb2xyz(float R, float G, float B)
+{
+
+ float r = R/255.f; //R 0..1
+ float g = G/255.f; //G 0..1
+ float b = B/255.f; //B 0..1
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz;
+ if (r <= 0.04045)
+ r = r/12.92;
+ else
+ r = (float)pow((r+0.055)/1.055,2.4);
+ if (g <= 0.04045)
+ g = g/12.92;
+ else
+ g = (float)pow((g+0.055)/1.055,2.4);
+ if (b <= 0.04045)
+ b = b/12.92;
+ else
+ b = (float)pow((b+0.055)/1.055,2.4);
+ float X1 = 0.4124*r + 0.3576*g + 0.1805*b;
+ float Y1 = 0.2126*r + 0.7152 *g + 0.0722 *b;
+ float Z1 = 0.0193*r + 0.1192*g + 0.9505 *b;
+ float xr = X1;
+ float yr = Y1;
+ float zr = Z1;
+ Color rgb;
+ rgb.R1= xr;
+ rgb.G1= yr;
+ rgb.B1= zr;
+ return rgb;
+
+}
+Color lab2xyz(float R, float G, float B)
+{
+ float y = (R+ 16) / 116;
+ float x = G / 500 + y;
+ float z = y - B/ 200;
+
+ if ( pow( y , 3 ) > 0.008856 ) { y = pow( y , 3 ); }
+ else { y = ( y - 16 / 116 ) / 7.787; }
+ if ( pow( x , 3 ) > 0.008856 ) { x = pow( x , 3 ); }
+ else { x = ( x - 16 / 116 ) / 7.787; }
+ if ( pow( z , 3 ) > 0.008856 ) { z = pow( z , 3 ); }
+ else { z = ( z - 16 / 116 ) / 7.787; }
+
+ Color rgb;
+ rgb.R1= x * REF_X;
+ rgb.G1= y * REF_Y;
+ rgb.B1= z * REF_Z;
+ return rgb;
+
+
+}
+Color xyz2rgb(float R, float G, float B)
+{
+ float x = R;
+ float y = G;
+ float z = B;
+ float R1 = 3.2404542*x-1.5371385*y-0.4985314*z;
+ float G1 =-0.9692660*x+1.8760108*y+0.0415560 *z;
+ float B1 = 0.0556434*x-0.2040259*y+1.0572252*z;
+ if( R1 > 0.0031308 )
+ R1 = 1.055 * ( pow( R1, 1./2.4 ) ) - 0.055;
+ else
+ R1 = 12.92 * R1;
+ if( G1 > 0.0031308 )
+ G1 = 1.055 * ( pow( G1, 1./2.4 ) ) - 0.055;
+ else
+ G1 = 12.92 * G1;
+ if( B1 > 0.0031308 )
+ B1 = 1.055 * ( pow( B1, 1./2.4 ) ) - 0.055;
+ else
+ B1= 12.92 * B1;
+
+ Color rgb;
+ rgb.R1= R1;
+ rgb.G1= G1;
+ rgb.B1= B1;
+ return rgb;
+
+
+}
+Color lab2rgb(float R, float G, float B)
+{
+ float y = (R + 16) / 116;
+ float x = G / 500 + y;
+ float z = y-B / 200;
+ if ( pow( y , 3 ) > 0.008856 )
+ {
+ y = pow( y , 3 );
+ }
+ else
+ {
+ y = ( y - 16 / 116 ) / 7.787;
+ }
+ if ( pow( x , 3 ) > 0.008856 )
+ {
+ x = pow( x , 3 );
+ }
+ else
+ {
+ x = ( x - 16 / 116 ) / 7.787;
+ }
+ if ( pow( z , 3 ) > 0.008856 )
+ {
+ z = pow( z , 3 );
+ }
+ else
+ {
+ z = ( z - 16 / 116 ) / 7.787;
+ }
+ float X= x *REF_X;
+ float Y= y *REF_Y;
+ float Z = z *REF_Z;
+ float R1=3.240479*X-1.537150*Y -0.498535 *Z;
+ float G1=-0.969256*X+1.875992 *Y+0.041556* Z;
+ float B1=0.055648*X-0.204043*Y +1.057311*Z;
+ if( R1 > 0.0031308 )
+ R1 = 1.055 * ( pow( R1, 1./2.4 ) ) - 0.055;
+ else
+ R1 = 12.92 * R1;
+ if( G1 > 0.0031308 )
+ G1 = 1.055 * ( pow( G1, 1./2.4 ) ) - 0.055;
+ else
+ G1 = 12.92 * G1;
+ if( B1 > 0.0031308 )
+ B1 = 1.055 * ( pow( B1, 1./2.4 ) ) - 0.055;
+ else
+ B1 = 12.92 * B1;
+
+
+ Color rgb;
+ rgb.R1= R1;
+ rgb.G1= G1;
+ rgb.B1= B1;
+ return rgb;
+
+
+}
+ int opencv_applycform(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int* piAddr2=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ int* piaddr=NULL;
+ char *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img;
+ float R,G,B;
+ char* pstData = NULL;
+ int *piAddrNew = NULL;
+ int* piAddr4=NULL;
+ int iRet = 0;
+ CheckInputArgument(pvApiCtx,2,2);
+ CheckOutputArgument(pvApiCtx,1,1);
+ int m=0;
+ retrieveImage(img,1);
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ g1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ b1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isStringType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr2, &pstData);
+ }
+ }
+
+ for(int i=0;i<img.rows;i++)
+ {
+ for(int j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i,j);
+ R= intensity.val[2];
+ G= intensity.val[1];
+ B= intensity.val[0];
+ if(strcasecmp(pstData,"xyz2lab")==0)
+ {
+ out=xyz2lab(R,G,B);
+ }
+ else if(strcasecmp(pstData,"lab2xyz")==0)
+ {
+ out=lab2xyz(R,G,B);
+ }
+ else if(strcasecmp(pstData,"srgb2xyz")==0)
+ {
+ out=rgb2xyz(R,G,B);
+ }
+ else if(strcasecmp(pstData,"xyz2srgb")==0)
+ {
+ out=xyz2rgb(R,G,B);
+ }
+ else if(strcasecmp(pstData,"srgb2lab")==0)
+ {
+ out=rgb2lab(R,G,B);
+ }
+ else if(strcasecmp(pstData,"lab2srgb")==0)
+ {
+ out=rgb2lab(R,G,B);
+ }
+ else
+ {
+ sciprint("Expected input argument 'xyz2lab' 'lab2xyz' 'srgb2xyz' 'xyz2srgb' 'srgb2lab' 'lab2srgb'");
+ return 0;
+ }
+ r1[m]=out.R1;
+ g1[m]=out.G1;
+ b1[m++]=out.B1;
+ }
+ }
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, img.rows,img.cols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, img.rows, img.cols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, img.rows, img.cols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_approxpolyDP.cpp b/sci_gateway/cpp/opencv_approxpolyDP.cpp
new file mode 100644
index 0000000..95cd835
--- /dev/null
+++ b/sci_gateway/cpp/opencv_approxpolyDP.cpp
@@ -0,0 +1,151 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : output_curve=approxpolyDP(input_curve,double epsilon, bool closed)*/
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int approxpolyDP(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double *pstData = NULL;
+ char **pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ int noofitem;
+ double res;
+ double epsilon;
+ int error;
+ //checking input argument
+ CheckInputArgument(pvApiCtx,3,3);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ // get Address of first input
+ sciErr =getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ //check for any error
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrieve input array
+ //SciErr getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols,&pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int k=0;
+ vector<Point> contours;
+ for(int i=0;i<iCols;i++)
+ {
+
+ contours.push_back(Point2f(pstData[i],pstData[i+1])) ;
+ i++;
+ }
+ //retrieving second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of sixth argument
+ error=getScalarDouble(pvApiCtx,piAddr2,&epsilon) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //retriving 3rd argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ 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 of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData2 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ {
+ pstData2[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, piAddr3, &iRows, &iCols, piLen, pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ vector<Point> approx;
+
+ if(!strcmp("True",pstData2[0]))
+ {
+ approxPolyDP(contours, approx,epsilon, true);
+ }
+ else if(!strcmp("False",pstData2[0]))
+ {
+ approxPolyDP(contours, approx,epsilon, false);
+ }
+ double *m=(double *)malloc(2*(approx.size())*sizeof(double));
+ Point a1;
+ int j=0;
+ for(int i=0;i<approx.size();i++)
+ {
+ a1=approx[i];
+ m[j++]=a1.x; //basic concept of classes and constructor
+ m[j++]=a1.y;
+ }
+ //SciErr createMatrixOfUnsignedInteger8(void* _pvCtx, int _iVar, int _iRows, int _iCols, const unsigned char* _pucData8)
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,1,2*approx.size(),m);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ ////////// Return the output arguments to the Scilab engine //////////
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_arclength.cpp b/sci_gateway/cpp/opencv_arclength.cpp
new file mode 100644
index 0000000..764ebfc
--- /dev/null
+++ b/sci_gateway/cpp/opencv_arclength.cpp
@@ -0,0 +1,130 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_doublevalue=arcLength(InputArray curve, bool closed) */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int arclenght(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double *pstData = NULL;
+ char **pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ int noofitem;
+ double res;
+ double *epsilon;
+ int error;
+ //checking input argument
+ CheckInputArgument(pvApiCtx,2,2);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ // get Address of first input
+ sciErr =getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ //check for any error
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrieve input array
+ //SciErr getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols,&pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int k=0;
+ vector<Point> contours;
+ for(int i=0;i<iCols;i++)
+ {
+
+ contours.push_back(Point2f(pstData[i],pstData[i+1])) ;
+ i++;
+ }
+
+ //retriving 2nd argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ 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 of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData2 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ {
+ pstData2[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, piAddr2, &iRows, &iCols, piLen, pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!strcmp("True",pstData2[0]))
+ {
+ res=arcLength(contours,true);
+ }
+ else if(!strcmp("False",pstData2[0]))
+ {
+ res=arcLength(contours,false);
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,res);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ ////////// Return the output arguments to the Scilab engine //////////
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_arrowedline.cpp b/sci_gateway/cpp/opencv_arrowedline.cpp
new file mode 100644
index 0000000..0e1643a
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_bilateralfilter.cpp b/sci_gateway/cpp/opencv_bilateralfilter.cpp
new file mode 100644
index 0000000..d508b78
--- /dev/null
+++ b/sci_gateway/cpp/opencv_bilateralfilter.cpp
@@ -0,0 +1,112 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_image=bilateralFilter(InputArray src, int d, double sigmaColor, double sigmaSpace ) */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include <localization.h>
+ #include "../common.h"
+ int bilateralfilter(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ int* pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ unsigned char *pstDataR = NULL;
+ unsigned char *pstDataG = NULL;
+ unsigned char *pstDataB = NULL;
+ int noofitem;
+ double d;
+ double sigmaColor;
+ double sigmaSpace;
+ int error;
+ // checking input argument
+ CheckInputArgument(pvApiCtx,4,4);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ // get Address of first input
+ Mat img;
+ retrieveImage(img,1);
+ //second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of second argument
+ error=getScalarDouble(pvApiCtx,piAddr2,&d) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //third argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of third argument
+ error=getScalarDouble(pvApiCtx,piAddr3,&sigmaColor) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+
+ //fourth argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+//this function will fetch value of fourth argument
+ error=getScalarDouble(pvApiCtx,piAddr4,&sigmaSpace) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ Mat dst;
+ //calling open cv bilateral filter function
+ bilateralFilter(img,dst,d,sigmaColor,sigmaSpace,BORDER_DEFAULT );
+ string tempstring = type2str(dst.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ //returning output variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+}
+}
diff --git a/sci_gateway/cpp/opencv_blur.cpp b/sci_gateway/cpp/opencv_blur.cpp
new file mode 100644
index 0000000..3db34ca
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_borderInterpolate.cpp b/sci_gateway/cpp/opencv_borderInterpolate.cpp
new file mode 100644
index 0000000..e8f0464
--- /dev/null
+++ b/sci_gateway/cpp/opencv_borderInterpolate.cpp
@@ -0,0 +1,149 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax :return_int=borderInterpolate(int p,int len,int borderType)
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<string>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int borderInterpolate(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr1 = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ char **pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ double p;
+ double len;
+ int borderType;
+ int error;
+ // checking input argument
+ CheckInputArgument(pvApiCtx,3,3);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ // get Address of first input
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ //check for any error
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of first argument
+ error=getScalarDouble(pvApiCtx,piAddr1,&p) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of second argument
+ error=getScalarDouble(pvApiCtx,piAddr2,&len) ;
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //third argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ 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;
+ }
+
+ pstData2 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ {
+ pstData2[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen, pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!strcmp(pstData2[0],"BORDER_REFLECT_101"))
+ {
+ borderType=BORDER_REFLECT_101;
+ }
+ else if(!strcmp(pstData2[0],"BORDER_WRAP"))
+ {
+ borderType=BORDER_WRAP;
+ }
+ else if(!strcmp(pstData2[0]," BORDER_WRAP"))
+ {
+ borderType=BORDER_WRAP;
+ }
+ else if(!strcmp(pstData2[0]," BORDER_TRANSPARENT"))
+ {
+ borderType= BORDER_TRANSPARENT;
+ }
+ else if(!strcmp(pstData2[0]," BORDER_CONSTANT"))
+ {
+ borderType= BORDER_TRANSPARENT;
+ }
+ //calling open cv function for borderInterpolate
+ double result;
+
+ result=borderInterpolate(p,len,borderType) ;
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,result);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ //returning output
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
+
diff --git a/sci_gateway/cpp/opencv_boundingRect.cpp b/sci_gateway/cpp/opencv_boundingRect.cpp
new file mode 100644
index 0000000..5bf8707
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_boxfilter.cpp b/sci_gateway/cpp/opencv_boxfilter.cpp
new file mode 100644
index 0000000..f08ab4f
--- /dev/null
+++ b/sci_gateway/cpp/opencv_boxfilter.cpp
@@ -0,0 +1,189 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_image==boxfilter(InputArray src, int ddepth,size.x,size,y,point.x,point.y, bool normalize)*/
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <string>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int boxfilter(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddr7 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ char** pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ int noofitem;
+ double ddepth;
+ bool normalize;
+ int borderType,i;
+ int error;
+ double sz1,sz2;
+ double pi1,pi2;
+ // checking input argument
+ CheckInputArgument(pvApiCtx,7,7);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ Mat img;
+ retrieveImage(img,1);
+ //second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of second argument
+ error=getScalarDouble(pvApiCtx,piAddr2,&ddepth);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ return 0;
+ }
+ //third argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of third argument
+ error=getScalarDouble(pvApiCtx,piAddr3,&sz1);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ return 0;
+ }
+
+ //fourth argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of fourth argument
+ error=getScalarDouble(pvApiCtx,piAddr4,&sz2);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //fifth argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of fifth argument
+ error=getScalarDouble(pvApiCtx,piAddr5,&pi1);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //sixth argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of sixth argument
+ error=getScalarDouble(pvApiCtx,piAddr6,&pi2);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //seventh argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,7,&piAddr7);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of seventh argument
+ 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;
+ }
+
+ pstData2 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(i = 0 ; i < iRows * iCols ; i++)
+ {
+ pstData2[i] = (char*)malloc(sizeof(char) * (piLen[i] + 1));//+ 1 for null termination
+ }
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr7, &iRows, &iCols, piLen, pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(!strcmp(pstData2[0],"True"))
+ {
+ normalize=true;
+ }
+ else if(!strcmp(pstData2[0],"False"))
+ {
+ normalize=true;
+
+ }
+ //size constructor
+ Size ksize=Size(sz1,sz2);
+ //anchor constructor
+ Point anchor=Point(pi1,pi2);
+ Mat dst;
+ //call to open cv boxfilter
+ boxFilter(img,dst,ddepth,ksize,anchor,normalize,BORDER_DEFAULT);
+ //returning variable to scilab console
+ string tempstring = type2str(dst.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ //returning output variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+}
diff --git a/sci_gateway/cpp/opencv_bwconvhull.cpp b/sci_gateway/cpp/opencv_bwconvhull.cpp
new file mode 100644
index 0000000..7e0a09d
--- /dev/null
+++ b/sci_gateway/cpp/opencv_bwconvhull.cpp
@@ -0,0 +1,129 @@
+/********************************************************
+Function :bwconvexhull
+Syntax :B=bwconvexhull(A)
+ B=bwconvexhull(A,"Object",n)
+ n :4 or 8
+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 "string.h"
+ #include "../common.h"
+
+ int opencv_bwconvhull(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ char* pstData = NULL;
+ int iRet = 0;
+ double n;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ Mat src,src_gray;
+ int thresh = 100,max_thresh = 255;
+ retrieveImage(src, 1);
+ cvtColor( src, src_gray, COLOR_BGR2GRAY );
+ blur( src_gray, src_gray, Size(3,3) );
+ Mat src_copy = src.clone();
+ Mat threshold_output;
+ vector<vector<Point> > contours;
+ vector<Vec4i> hierarchy;
+ threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY );
+ findContours( threshold_output, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE, Point(0, 0) );
+ vector<vector<Point> >hull( contours.size() );
+ for( size_t i = 0; i < contours.size(); i++ )
+ {
+ convexHull( Mat(contours[i]), hull[i], false );
+ }
+ Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
+ for( size_t i = 0; i< contours.size(); i++ )
+ {
+ Scalar color = Scalar(255,255,255);
+ /* if only 1 input argument line connectvity n will take default value 8 */
+ if(nbInputArgument(pvApiCtx)==1)
+ {
+ drawContours( drawing, contours, (int)i, color, 1, 8, vector<Vec4i>(), 0, Point() );
+ drawContours( drawing, hull, (int)i, color,CV_FILLED, 8, vector<Vec4i>(), 0, Point());
+ }
+ else if(nbInputArgument(pvApiCtx)==3)
+ {
+ /* retrieve second argument */
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr2, &pstData);
+ }
+ }
+ else
+ {
+ sciprint(" The second argument should be string ");
+ return 0;
+ }
+ if(strcasecmp(pstData,"Object")==0)
+ {
+ /*retrieve third argument */
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &n);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // The error checks for the function
+ if((n!=4)&&(n!=8))
+ {
+ sciprint("The value of line connectivity must be 8 or 4");
+ return 0;
+ }
+ drawContours( drawing, contours, (int)i, color, 1, n, vector<Vec4i>(), 0, Point() );
+ drawContours( drawing, hull, (int)i, color,CV_FILLED, n, vector<Vec4i>(), 0, Point());
+ }
+ else
+ {
+ sciprint(" The second argument must be 'Object'");
+ return 0;
+ }
+ }
+ }
+ string tempstring = type2str(drawing.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,drawing,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_gateway/cpp/opencv_bwdistgeodesic.cpp b/sci_gateway/cpp/opencv_bwdistgeodesic.cpp
new file mode 100644
index 0000000..7f83652
--- /dev/null
+++ b/sci_gateway/cpp/opencv_bwdistgeodesic.cpp
@@ -0,0 +1,88 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = bwdistgeodesic(input_image, mask)
+********************************************************/
+
+#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_bwdistgeodesic(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat marker, mask;
+ retrieveImage(marker, 1);
+ retrieveImage(mask, 2);
+
+ if (marker.type() != CV_8UC1)
+ {
+ Mat tempM;
+ tempM = marker.clone();
+ cvtColor(tempM, marker, CV_BGR2GRAY);
+ }
+
+ if (mask.type() != CV_8UC1)
+ {
+ Mat tempM;
+ tempM = mask.clone();
+ cvtColor(tempM, mask, CV_8UC1);
+ }
+
+ int i = 1;
+
+ Mat temp0;
+ Mat temp2 = marker.clone();
+ Mat fin_image = marker.clone();
+
+ do {
+ temp0 = temp2.clone();
+ Mat temp1, temp3;
+ dilate(temp0, temp1, Mat());
+ min(temp1, mask, temp2);
+ temp3 = temp2 - temp0;
+ temp3.convertTo(temp3, CV_32F);
+ temp3 = temp3 * ((255 - i)/255.0);
+ temp3.convertTo(temp3, CV_8UC1);
+ max(fin_image, temp3, fin_image);
+ i++;
+ } while((countNonZero(temp0 != temp2) != 0) && (i != 255));
+
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_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_gateway/cpp/opencv_bwlookup.cpp b/sci_gateway/cpp/opencv_bwlookup.cpp
new file mode 100644
index 0000000..5471e55
--- /dev/null
+++ b/sci_gateway/cpp/opencv_bwlookup.cpp
@@ -0,0 +1,180 @@
+/*
+ * bwlookup
+ *
+ * 2*2 and 3*3 non linear filtering of a binary image based on a lookup table -
+ *lut which is taken as input from the user
+ *
+ */
+
+// Created by Samiran Roy, mail: samiranroy@cse.iitb.ac.in
+// An implementation of bwlookup
+// Usage:
+// bwlookup(I,lut)
+
+// I is the input binary grayscale image. If the image is not binary, it is
+// converted to one.
+// lut is a 1*16 double vector [2*2 filtering], or a [1*512] double vector [3*3
+// filtering]
+// The indexing method used is the same as Matlab bwlookup:
+// http://in.mathworks.com/help/images/ref/bwlookup.html
+
+// Known Changes from Matlab:
+/*
+ * 1) None, as of now
+ */
+
+#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_bwlookup(char* fname, unsigned long fname_len) {
+ SciErr sciErr;
+ int intErr = 0;
+
+ int* piAddr = NULL;
+
+ // checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // get input matrix
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ if (image.channels() > 1) {
+ sciprint("The image must be grayscale.");
+ return -1;
+ }
+
+ double* lut;
+
+ int iRows = 0, iCols = 0;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return -1;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &lut);
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return -1;
+ }
+
+ // Error Checking
+
+ if (!((iCols == 16) || (iCols == 512))) {
+ sciprint("Expected LUT (argument 2) to have 16 or 512 elements.\n");
+
+ return -1;
+ }
+
+ if (iRows != 1) {
+ sciprint("Expected input number 2, LUT, to be a vector.\n");
+ return -1;
+ }
+
+ if (image.channels() != 1) {
+ sciprint("Expected input number 1, A, to be two-dimensional.\n");
+ return -1;
+ }
+
+ // temporary copy of image to perform computation
+ // converting the image to a binary image
+ Mat tempimg = Mat::zeros(image.size(), CV_8U);
+
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ if (image.at<double>(i, j) != 0) tempimg.at<uchar>(i, j) = 1;
+ }
+ }
+
+ // pad the temporary copy of the image with zeroes to handle border cases
+ copyMakeBorder(tempimg, tempimg, 1, 1, 1, 1, BORDER_CONSTANT, 0);
+
+ // output images
+ Mat new_image = Mat::zeros(image.size(), CV_32F);
+
+ // temporary variables
+ int ii, jj;
+ int index;
+
+ // 2*2 filtering
+ if (iCols == 16) {
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ ii = i + 1;
+ jj = j + 1;
+
+ index = tempimg.at<uchar>(ii, jj) * 1 +
+ tempimg.at<uchar>(ii, jj + 1) * 2 +
+ tempimg.at<uchar>(ii + 1, jj) * 4 +
+ tempimg.at<uchar>(ii + 1, jj + 1) * 8;
+
+ new_image.at<float>(i, j) = lut[ 0, index ];
+ }
+ }
+ }
+
+ // 3*3 filtering
+ if (iCols == 512) {
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ ii = i + 1;
+ jj = j + 1;
+
+ index = tempimg.at<uchar>(ii - 1, jj - 1) * 1 +
+ tempimg.at<uchar>(ii - 1, jj) * 2 +
+ tempimg.at<uchar>(ii - 1, jj + 1) * 4 +
+ tempimg.at<uchar>(ii, jj - 1) * 8 +
+ tempimg.at<uchar>(ii, jj) * 16 +
+ tempimg.at<uchar>(ii, jj + 1) * 32 +
+ tempimg.at<uchar>(ii + 1, jj - 1) * 64 +
+ tempimg.at<uchar>(ii + 1, jj) * 128 +
+ tempimg.at<uchar>(ii + 1, jj + 1) * 256;
+
+ new_image.at<float>(i, j) = lut[ 0, index ];
+ }
+ }
+ }
+
+ // sciprint("\n");
+
+ // for (int i = 0; i < new_image.rows; i++) {
+ // for (int j = 0; j < new_image.cols; j++) {
+ // sciprint("%i ", new_image.at<uchar>(i,j));
+
+ // }
+
+ // sciprint("\n");
+ // }
+
+ // new_image is sent to scilab as output
+
+ 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_gateway/cpp/opencv_bwulterode.cpp b/sci_gateway/cpp/opencv_bwulterode.cpp
new file mode 100644
index 0000000..e9d0206
--- /dev/null
+++ b/sci_gateway/cpp/opencv_bwulterode.cpp
@@ -0,0 +1,92 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = bwulterode(input_image)
+********************************************************/
+
+#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"
+
+ void bwulterode_imreconstruct(Mat, Mat, Mat&);
+
+ int opencv_bwulterode(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat gray_image, fin_image, m, image;
+ retrieveImage(gray_image, 1);
+
+ for (int i = 0; i < gray_image.cols; i++)
+ {
+ for (int j = 0; j < gray_image.rows; j++)
+ {
+ unsigned char val = gray_image.at<uchar>(i,j);
+ if (!(val == 0 || val == 1 || val == 255))
+ {
+ sciprint("Please enter binary image.");
+ return 0;
+ }
+ }
+ }
+
+ if (gray_image.type() != CV_8UC1)
+ {
+ Mat temp;
+ temp = gray_image.clone();
+ cvtColor(temp, gray_image, CV_BGR2GRAY);
+ }
+
+ distanceTransform(gray_image, image, CV_DIST_L2, DIST_MASK_5);
+ subtract(image, 1, gray_image);
+ bwulterode_imreconstruct(image, gray_image, m);
+ subtract(image, m, gray_image);
+ fin_image = gray_image * 255;
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_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;
+
+ }
+ void bwulterode_imreconstruct(Mat g, Mat f, Mat& dest)
+ {
+ Mat m0, m1, m;
+ m1 = f;
+ do {
+ m0 = m1.clone();
+ dilate(m0, m, Mat());
+ min(g, m, m1);
+ } while(countNonZero(m1 != m0) != 0);
+ dest = m1.clone();
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_canny.cpp b/sci_gateway/cpp/opencv_canny.cpp
new file mode 100644
index 0000000..010d634
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_circle.cpp b/sci_gateway/cpp/opencv_circle.cpp
new file mode 100644
index 0000000..928c251
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_clipline.cpp b/sci_gateway/cpp/opencv_clipline.cpp
new file mode 100644
index 0000000..2e13412
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_contourarea.cpp b/sci_gateway/cpp/opencv_contourarea.cpp
new file mode 100644
index 0000000..ba45b09
--- /dev/null
+++ b/sci_gateway/cpp/opencv_contourarea.cpp
@@ -0,0 +1,125 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_area=contourarea(InputArray contour, bool oriented); */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+//#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>
+ int contourarea(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double *pstData = NULL;
+ char **pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ double res;
+ int error;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx,2,2);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ // get Address of first input
+ sciErr =getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ //check for any error
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrieve input array
+ //SciErr getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols,&pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int k=0;
+ vector<Point> contours;
+ for(int i=0;i<iCols;i++)
+ {
+ contours.push_back(Point2f(pstData[i],pstData[i+1])) ;
+ i++;
+ }
+ // get Address of second input
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ 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 of first argument
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ pstData2 = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ {
+ pstData2[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, piAddr2, &iRows, &iCols, piLen, pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(!strcmp("True",pstData2[0]))
+ {
+ res=contourArea(contours,true);
+ }
+ else if(!strcmp("False",pstData2[0]))
+ {
+ res=contourArea(contours,false);
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,res);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+
+ ////////// Return the output arguments to the Scilab engine //////////
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ ReturnArguments(pvApiCtx);
+
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_convexhull.cpp b/sci_gateway/cpp/opencv_convexhull.cpp
new file mode 100644
index 0000000..934fa20
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_convmtx2.cpp b/sci_gateway/cpp/opencv_convmtx2.cpp
new file mode 100644
index 0000000..81d7473
--- /dev/null
+++ b/sci_gateway/cpp/opencv_convmtx2.cpp
@@ -0,0 +1,129 @@
+/***************************************************
+Author : Yash S. Bhalgat
+****************************************************
+Usage : T = convmtx2(H, m, n);
+Example:
+
+***************************************************/
+
+#include <numeric>
+#include <limits>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <stdio.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_convmtx2(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int i,j,k;
+ double m, n;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat H;
+ retrieveImage(H,1);
+
+ //for value of m
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &m);
+ if(intErr)
+ return intErr;
+
+ //for value of n
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &n);
+ if(intErr)
+ return intErr;
+
+
+ //taking the cases which can lead to an error
+
+ int s1 = H.rows;
+ int s2 = H.cols;
+
+ Mat T;
+ T = Mat::zeros((m-s1+1)*(n-s2+1),m*n,H.type());
+
+ if(m<H.rows)
+ {
+ sciprint("m should be greater than filter height");
+ m = H.rows;
+ }
+ if(n<H.cols)
+ {
+ sciprint("n should be greater than filter width");
+ n = H.cols;
+ }
+
+
+ //my function called
+ //my_convmtx2(H, T, m, n);
+ k = 0;
+
+ for(int i=0;i<m-s1+1;i++){
+ for(int j=0;j<n-s2+1;j++){
+ for(int p=0;p<s1;p++){
+ Mat roiPart1 = H.rowRange(p,p+1).colRange(0,s2);
+ Mat roiPart2 = T.rowRange(k,k+1).colRange((i+p)*n+j,(i+p)*n+j+s2);
+ roiPart1.copyTo(roiPart2);
+// for(int q=0;q<s2;q++)
+// T.at<double>(k,(i+p)*n+j+q)=H.at<double>(p,q);
+ }
+ k++;
+ }
+ }
+
+ //printf("%f %f %f" , H.at<double>(0,0), H.at<double>(1,1), H.at<double>(2,2));
+
+ //namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
+ //imshow( "Display window", T );
+
+ //returning image
+ string tempstring = type2str(T.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,T,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_gateway/cpp/opencv_copymakeborder.cpp b/sci_gateway/cpp/opencv_copymakeborder.cpp
new file mode 100644
index 0000000..51175fb
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_corner.cpp b/sci_gateway/cpp/opencv_corner.cpp
new file mode 100644
index 0000000..7502f96
--- /dev/null
+++ b/sci_gateway/cpp/opencv_corner.cpp
@@ -0,0 +1,166 @@
+/********************************************************
+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 "string.h"
+ #include "../common.h"
+
+ int opencv_corner(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ char* pstData = NULL;
+ char* pstData1 = NULL;
+ int iRet = 0;
+ int iRet1 = 0;
+ CheckInputArgument(pvApiCtx, 1, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ Mat src,src_gray;
+ int thresh = 200;
+ int max_thresh = 255;
+ retrieveImage(src, 1);
+ cvtColor( src, src_gray, COLOR_BGR2GRAY );
+ Mat dst, dst_norm, drawing;
+ dst = Mat::zeros( src.size(), CV_32FC1 );
+ int blockSize = 2;
+ int apertureSize = 3;
+ double k = 0.04;
+ int maxCorners = 23;
+ RNG rng(12345);
+ if(nbInputArgument(pvApiCtx)==1)
+ {
+ cornerHarris( src_gray, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
+ normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
+ convertScaleAbs( dst_norm, drawing );
+ for( int j = 0; j < dst_norm.rows ; j++ )
+ {
+ for( int i = 0; i < dst_norm.cols; i++ )
+ {
+ if( (int) dst_norm.at<float>(j,i) > thresh )
+ {
+ circle( drawing, Point( i, j ), 5, Scalar(0), 2, 8, 0 );
+ }
+ }
+ }
+ }
+ else if(nbInputArgument(pvApiCtx)==3)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr2, &pstData);
+ }
+ }
+ else
+ {
+ sciprint(" The second argument should be string ");
+ return 0;
+ }
+ if(strcasecmp(pstData,"Method")==0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr3))
+ {
+ if(isScalar(pvApiCtx, piAddr3))
+ {
+ iRet1 = getAllocatedSingleString(pvApiCtx, piAddr3, &pstData1);
+ }
+ }
+ else
+ {
+ sciprint(" The third argument should be string ");
+ return 0;
+ }
+ if(strcasecmp(pstData1,"Harris")==0)
+ {
+ cornerHarris( src_gray, dst, blockSize, apertureSize, k, BORDER_DEFAULT );
+ normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() );
+ convertScaleAbs( dst_norm, drawing );
+ for( int j = 0; j < dst_norm.rows ; j++ )
+ {
+ for( int i = 0; i < dst_norm.cols; i++ )
+ {
+ if( (int) dst_norm.at<float>(j,i) > thresh )
+ {
+ circle( drawing, Point( i, j ), 5, Scalar(0), 2, 8, 0 );
+ }
+ }
+ }
+ }
+ else if(strcasecmp(pstData1,"MinEigenvalue")==0)
+ {
+ if( maxCorners < 1 )
+ {
+ maxCorners = 1;
+ }
+ /// Parameters for Shi-Tomasi algorithm
+ vector<Point2f> corners;
+ double qualityLevel = 0.01;
+ double minDistance = 10;
+ int blockSize = 3;
+ bool useHarrisDetector = false;
+ double k = 0.04;
+ /// Copy the source image
+ drawing = src.clone();
+ goodFeaturesToTrack( src_gray,corners,maxCorners,qualityLevel,minDistance,Mat(),blockSize,useHarrisDetector,k );
+ int r = 4;
+ for( int i = 0; i < corners.size(); i++ )
+ {
+ circle( drawing, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255),rng.uniform(0,255)), -1, 8, 0 );
+ }
+ }
+ else
+ {
+ sciprint(" The third argument must be 'Harris' or 'Mineigenvalue' ");
+ return 0;
+ }
+ }
+ else
+ {
+ sciprint(" The second argument must be 'Method' ");
+ return 0;
+ }
+ }
+ string tempstring = type2str(drawing.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,drawing,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_gateway/cpp/opencv_cornerEigenValsAndVecs.cpp b/sci_gateway/cpp/opencv_cornerEigenValsAndVecs.cpp
new file mode 100644
index 0000000..205759d
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_cornerHarris.cpp b/sci_gateway/cpp/opencv_cornerHarris.cpp
new file mode 100644
index 0000000..d517eec
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_cornerMinEigenVal.cpp b/sci_gateway/cpp/opencv_cornerMinEigenVal.cpp
new file mode 100644
index 0000000..19123e5
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_cvtColor.cpp b/sci_gateway/cpp/opencv_cvtColor.cpp
new file mode 100644
index 0000000..2959dda
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_deconvlucy.cpp b/sci_gateway/cpp/opencv_deconvlucy.cpp
new file mode 100644
index 0000000..9523f91
--- /dev/null
+++ b/sci_gateway/cpp/opencv_deconvlucy.cpp
@@ -0,0 +1,120 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = deconvlucy(input_image, PSF)
+ return_image = deconvlucy(input_image, PSF, no_of_iterations)
+********************************************************/
+
+#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_deconvlucy(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+ int i;
+ double h;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat image, psf;
+ retrieveImage(image, 1);
+ retrieveImage(psf, 2);
+
+ // Check if number of arguments are three,
+ // if so, then the number of iterations is also
+ // specified.
+ // If not, then set number of iterations as
+ // ten.
+ if (nbInputArgument(pvApiCtx) == 3)
+ {
+ // Get the address of the iterations scalar
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the no. of iterations scalar
+ intErr = getScalarDouble(pvApiCtx, piAddr, &h);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if (h < 0)
+ {
+ sciprint("Please enter a nonnegative scalar for number of iterations.\n");
+ return 0;
+ }
+ }
+ else
+ h = 10;
+
+ // Check if the input image is grayscale or not,
+ // if not, convert it to grayscale.
+ if (image.type() != CV_8UC1)
+ {
+ Mat temp;
+ temp = image.clone();
+ cvtColor(temp, image, CV_BGR2GRAY);
+ }
+
+ // Check if the PSF is grayscale or not,
+ // if not, convert it to grayscale.
+ if (psf.type() != CV_8UC1)
+ {
+ Mat temp;
+ temp = psf.clone();
+ cvtColor(temp, psf, CV_BGR2GRAY);
+ }
+
+ // Apply the Lucy-Richardson method for deblurring
+ // an image.
+ Mat convRes, convRes2, temp;
+ temp = image.clone();
+ for (i = 0; i < h; i++)
+ {
+ filter2D(temp, convRes, -1, psf);
+ max((temp - convRes), 0, convRes2);
+ min((temp + convRes2), 255, convRes);
+ temp = convRes.clone();
+ }
+ image = temp.clone();
+
+ 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_gateway/cpp/opencv_decorrstretch.cpp b/sci_gateway/cpp/opencv_decorrstretch.cpp
new file mode 100644
index 0000000..a3432a2
--- /dev/null
+++ b/sci_gateway/cpp/opencv_decorrstretch.cpp
@@ -0,0 +1,102 @@
+/***************************************************
+Author : Dhruti Shah
+***************************************************/
+
+#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"
+
+
+ Mat dstretch(Mat& input)
+ {
+ CV_Assert(input.channels() > 1);
+
+ Mat dataMu, dataSigma, eigDataSigma, scale, stretch;
+ Mat targetMean = Mat();
+
+ Mat data = input.reshape(1, input.rows*input.cols);
+
+ meanStdDev(input, dataMu, dataSigma);
+
+ PCA pca(data, Mat(), CV_PCA_DATA_AS_ROW);
+
+ sqrt(pca.eigenvalues, eigDataSigma);
+ scale = Mat::diag(1/eigDataSigma);
+ stretch = Mat::diag(dataSigma);
+
+ stretch.convertTo(stretch, CV_32F);
+
+ Mat zmudata;
+ Mat repMu = repeat(dataMu.t(), data.rows, 1);
+ subtract(data, repMu, zmudata, Mat(), CV_32F);
+
+ Mat transformed = zmudata*(pca.eigenvectors.t()*scale*pca.eigenvectors*stretch);
+ add(transformed, repMu, transformed, Mat(), CV_32F);
+
+ Mat dstr32f = transformed.reshape(input.channels(), input.rows);
+ return dstr32f;
+ }
+
+ int opencv_decorrstretch(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;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ Mat lab;
+ cvtColor(image, lab, CV_BGR2Lab);
+ Mat dstrlab32f = dstretch(lab);
+ Mat dstrlab8u;
+ dstrlab32f.convertTo(dstrlab8u, CV_8UC3);
+ Mat dstrlab2bgr;
+ cvtColor(dstrlab8u, dstrlab2bgr, CV_Lab2BGR);
+ Mat dstrbgr32f = dstretch(image);
+ Mat dstrbgr8u;
+ dstrbgr32f.convertTo(dstrbgr8u, CV_8UC3);
+
+
+ string tempstring = type2str(dstrbgr8u.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dstrbgr8u,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_gateway/cpp/opencv_demosaic.cpp b/sci_gateway/cpp/opencv_demosaic.cpp
new file mode 100644
index 0000000..317e163
--- /dev/null
+++ b/sci_gateway/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, CV_BayerRG2RGB, 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;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_demosaic.cpp~ b/sci_gateway/cpp/opencv_demosaic.cpp~
new file mode 100644
index 0000000..4c2ee4b
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_dilate.cpp b/sci_gateway/cpp/opencv_dilate.cpp
new file mode 100644
index 0000000..44b26f1
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_ellipse.cpp b/sci_gateway/cpp/opencv_ellipse.cpp
new file mode 100644
index 0000000..092ab78
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_ellipse2poly.cpp b/sci_gateway/cpp/opencv_ellipse2poly.cpp
new file mode 100644
index 0000000..e7edef4
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_erode.cpp b/sci_gateway/cpp/opencv_erode.cpp
new file mode 100644
index 0000000..fd12082
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_fftshift.cpp b/sci_gateway/cpp/opencv_fftshift.cpp
new file mode 100644
index 0000000..4f59bd4
--- /dev/null
+++ b/sci_gateway/cpp/opencv_fftshift.cpp
@@ -0,0 +1,55 @@
+/********************************************************
+Function :fftshift
+Syntax :B=fftshift(A)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_fftshift(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ Mat image;
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ retrieveImage(image,1);
+ int cx = floor(image.cols/2);
+ int cy = floor(image.rows/2);
+ Mat q0(image, Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant
+ Mat q1(image, Rect(cx, 0, cx, cy)); // Top-Right
+ Mat q2(image, Rect(0, cy, cx, cy)); // Bottom-Left
+ Mat q3(image, Rect(cx, cy, cx, cy)); // Bottom-Right
+ Mat tmp; // swap quadrants (Top-Left with Bottom-Right)
+ q0.copyTo(tmp);
+ q3.copyTo(q0);
+ tmp.copyTo(q3);
+ q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left)
+ q2.copyTo(q1);
+ tmp.copyTo(q2);
+ 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);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_fillconvexpoly.cpp b/sci_gateway/cpp/opencv_fillconvexpoly.cpp
new file mode 100644
index 0000000..1ce29c6
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_filter2D.cpp b/sci_gateway/cpp/opencv_filter2D.cpp
new file mode 100644
index 0000000..650771b
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_findContours.cpp b/sci_gateway/cpp/opencv_findContours.cpp
new file mode 100644
index 0000000..05da2b3
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_fitellipse.cpp b/sci_gateway/cpp/opencv_fitellipse.cpp
new file mode 100644
index 0000000..5964c62
--- /dev/null
+++ b/sci_gateway/cpp/opencv_fitellipse.cpp
@@ -0,0 +1,125 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : [a,b,c,e,f]=fitellipse((InputArray points);
+a,b,c,d,e are parameters of rotated rect returned
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int fitellipse(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ int* pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ double sigmaSpace;
+ int error;
+ ////checking input argument
+ CheckInputArgument(pvApiCtx,1,1);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,5,5);
+ //for first argument
+ // get Address of first input
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ //check for any error
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrieve input array
+ //SciErr getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols,&pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int k=0;
+ vector<Point> contours;
+ for(int i=0;i<iCols;i++)
+ {
+
+ contours.push_back(Point2f(pstData[i],pstData[i+1])) ;
+ i++;
+ }
+ RotatedRect rect;
+ rect=fitEllipse(contours);
+ double size1,size2,center1,center2,angle;
+ //from rotated rect datatype we can fetch required size,point,angle
+ Size2f sz; //size2f function for floating point values
+ Point2f cen;
+ sz=rect.size;
+ cen=rect.center;
+ angle=rect.angle;
+ size1=sz.width;
+ size2=sz.height;
+ center1=cen.x;
+ center2=cen.y;
+
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,size1);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+2,size2);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+3,center1);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+4,center2);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+5,angle);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ 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;
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+ ReturnArguments(pvApiCtx);
+}
+}
diff --git a/sci_gateway/cpp/opencv_fsamp2.cpp b/sci_gateway/cpp/opencv_fsamp2.cpp
new file mode 100644
index 0000000..02780b6
--- /dev/null
+++ b/sci_gateway/cpp/opencv_fsamp2.cpp
@@ -0,0 +1,157 @@
+/********************************************************
+Author: Vinay
+
+Function: ind2gray(image, colormap)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+using namespace cv;
+using namespace std;
+
+void rotate180(Mat &m) {
+ double temp;
+ for (int i=0; i<(m.rows+1)/2; i++) {
+ int k = m.cols;
+ if ((i+1)>=((m.rows+1)/2) && m.rows%2!=0) {
+ k = (m.cols+1)/2;
+ }
+ for (int j=0; j<k; j++) {
+ temp = m.at<double>(i, j);
+ m.at<double>(i, j) = m.at<double>(m.rows-i-1, m.cols-j-1);
+ m.at<double>(m.rows-i-1, m.cols-j-1) = temp;
+ }
+ }
+
+}
+
+Mat fftshift(Mat m) {
+ int a = m.rows/2;
+ int b = m.cols/2;
+ Mat r = Mat::zeros(m.size(), m.type());
+ for (int i=0; i<m.rows; i++) {
+ for (int j=0; j<m.cols; j++) {
+ r.at<double>((i+a)%m.rows, (j+b)%m.cols) = m.at<double>(i, j);
+ }
+ }
+ return r;
+}
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+ #include "../common.h"
+
+
+ int opencv_fsamp2(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int cRows=0,cCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Mat image, imgcpy;
+ // retrieveImage(image, 1);
+ // string tempstring = type2str(image.type());
+ // char *imtype;
+ // imtype = (char *)malloc(tempstring.size() + 1);
+ // memcpy(imtype, tempstring.c_str(), tempstring.size() + 1);
+ // bool integer = true;
+ // int scale = 1;
+ // double error = 0;
+
+ if (nbInputArgument(pvApiCtx) == 1) {
+ Mat hd, hdcpy;
+ retrieveImage(hdcpy, 1);
+ hdcpy.convertTo(hd, CV_64F);
+ rotate180(hd);
+
+ fftshift(hd).copyTo(hd);
+
+ rotate180(hd);
+
+
+ Mat padded; //expand input image to optimal size
+ int m = getOptimalDFTSize( hd.rows );
+ int n = getOptimalDFTSize( hd.cols ); // on the border add zero values
+ copyMakeBorder(hd, padded, 0, m - hd.rows, 0, n - hd.cols, BORDER_CONSTANT, Scalar::all(0));
+
+ Mat planes[] = {Mat_<double>(padded), Mat::zeros(padded.size(), CV_64F)};
+ Mat complexI;
+ merge(planes, 2, complexI); // Add to the expanded another plane with zeros
+
+ dft(complexI, complexI, DFT_INVERSE | DFT_SCALE); // this way the result may fit in the source matrix
+
+ split(complexI, planes);
+
+ fftshift(planes[0]).copyTo(planes[0]);
+ fftshift(planes[1]).copyTo(planes[1]);
+ rotate180(planes[0]);
+ rotate180(planes[1]);
+
+ double *re = (double *)malloc(planes[0].rows * planes[0].cols * sizeof(double));
+ double *im = (double *)malloc(planes[0].rows * planes[0].cols * sizeof(double));
+
+ for(int i=0;i<planes[0].rows;i++)
+ {
+ for(int j=0;j<planes[0].cols;j++)
+ {
+ re[i+planes[0].rows*j]=planes[0].at<double>(i, j);
+ //cout<<planes[0].at<double>(i, j)<<" ";
+ im[i+planes[0].rows*j]=planes[1].at<double>(i, j);
+ }
+ //cout<<endl;
+ }
+
+
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 1, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createComplexMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, planes[0].rows,planes[0].cols, re, im);
+ free(re);
+ free(im);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ }
+ else if (nbInputArgument(pvApiCtx)==2 || nbInputArgument(pvApiCtx)==3) {
+ sciprint("1 or 4 arguments expected.");
+ 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_gateway/cpp/opencv_ftrans2.cpp b/sci_gateway/cpp/opencv_ftrans2.cpp
new file mode 100644
index 0000000..01ac179
--- /dev/null
+++ b/sci_gateway/cpp/opencv_ftrans2.cpp
@@ -0,0 +1,199 @@
+/********************************************************
+Author: Vinay
+
+Function: h = ftrans2(b, t)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <cmath>
+using namespace cv;
+using namespace std;
+
+void rotate180(Mat &m) {
+ double temp;
+ for (int i=0; i<(m.rows+1)/2; i++) {
+ int k = m.cols;
+ if ((i+1)>=((m.rows+1)/2) && m.rows%2!=0) {
+ k = (m.cols+1)/2;
+ }
+ for (int j=0; j<k; j++) {
+ temp = m.at<double>(i, j);
+ m.at<double>(i, j) = m.at<double>(m.rows-i-1, m.cols-j-1);
+ m.at<double>(m.rows-i-1, m.cols-j-1) = temp;
+ }
+ }
+
+}
+
+Mat fftshift(Mat m) {
+ int a = m.rows/2;
+ int b = m.cols/2;
+ Mat r = Mat::zeros(m.size(), m.type());
+ for (int i=0; i<m.rows; i++) {
+ for (int j=0; j<m.cols; j++) {
+ r.at<double>((i+a)%m.rows, (j+b)%m.cols) = m.at<double>(i, j);
+ }
+ }
+ return r;
+}
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "sciprint.h"
+ #include "../common.h"
+
+ int opencv_ftrans2(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int cRows=0,cCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat b, bcpy, t;
+ Mat P0, P1, P2, h, hh;
+
+ retrieveImage(bcpy, 1);
+ bcpy.convertTo(b, CV_64F);
+
+ if (b.cols == 1) {
+ transpose(b, b);
+ }
+ else if (b.rows == 1) {
+
+ }
+ else {
+ sciprint("b at argument 1 expected to be vector");
+ return 0;
+ }
+
+ if (b.cols%2 == 0) {
+ sciprint("b at argument 1 must be of odd length");
+ return 0;
+ }
+
+ Mat c = b.clone();
+ rotate180(c);
+
+ int zeroCount = 0;
+ double eps = 1.5e-5;
+
+ for (int i=0; i<b.cols; i++) {
+ if (abs(b.at<double>(0, i) - c.at<double>(0, i)) > eps) {
+ zeroCount = b.cols;
+ break;
+ }
+ if (b.at<double>(0, i) == 0) {
+ zeroCount++;
+ }
+ }
+ if (zeroCount == b.cols) {
+ sciprint("b at argument 1 must be nonzero and symmetric");
+ return 0;
+ }
+
+
+ if (nbInputArgument(pvApiCtx) == 2) {
+ Mat tcpy;
+ retrieveImage(tcpy, 2);
+ tcpy.convertTo(t, CV_64F);
+
+ }
+ else {
+ Mat tcpy;
+ double data[3][3] = {{1.0/8, 2.0/8, 1.0/8},{2.0/8, -4.0/8, 2.0/8},{1.0/8, 2.0/8, 1.0/8}};
+ tcpy = Mat(3, 3, CV_64F, &data);
+ t = tcpy.clone();
+ }
+
+ rotate180(b);
+
+ fftshift(b).copyTo(b);
+
+ rotate180(b);
+
+ int inset1 = (t.rows-1)/2;
+ int inset2 = (t.cols-1)/2;
+ int n = (b.cols-1)/2;
+
+ Mat a = Mat::zeros(1, n+1, CV_64F);
+ a.at<double>(0, 0) = b.at<double>(0,0);
+ for (int i=1; i<=n; i++) {
+ a.at<double>(0, i) = 2*b.at<double>(0, i);
+ }
+
+ P0 = Mat::ones(1, 1, CV_64F);
+ t.copyTo(P1);
+ h = (P1*a.at<double>(0, 1));
+
+ h.at<double>(inset1,inset2) = h.at<double>(inset1,inset2) + a.at<double>(0, 0);
+
+ for (int i=2; i<=n; i++) {
+ Mat src = t.clone();
+
+ int additionalRows = P1.rows-1, additionalCols = P1.cols-1;
+
+ copyMakeBorder(src, src, (additionalRows+1)/2, additionalRows/2, (additionalCols+1)/2, additionalCols/2, BORDER_CONSTANT, Scalar(0));
+
+ Point anchor(P1.cols - P1.cols/2 - 1, P1.rows - P1.rows/2 - 1);
+ int borderMode = BORDER_CONSTANT;
+ Mat P11;
+ flip(P1, P11,-1);
+ filter2D(src, P2, src.depth(), P11, anchor, 0, borderMode);
+
+ P2 = P2 * 2;
+
+ for (int x=0; x<P0.rows; x++) {
+ for (int y=0; y<P0.cols; y++) {
+ P2.at<double>(x + 2*inset1, y+ 2*inset2) = P2.at<double>(x + 2*inset1, y+ 2*inset2) - P0.at<double>(x, y);
+ }
+ }
+ h.copyTo(hh);
+ h = (P2*a.at<double>(0, i));
+ for (int x=0; x<P1.rows; x++) {
+ for (int y=0; y<P1.cols; y++) {
+ h.at<double>(x + inset1, y + inset2) = h.at<double>(x + inset1, y + inset2) + hh.at<double>(x, y);
+ }
+ }
+
+ P1.copyTo(P0);
+ P2.copyTo(P1);
+
+ }
+
+ rotate180(h);
+
+ Mat hcopy;
+ h.copyTo(hcopy);
+
+ string tempstring = type2str(hcopy.type());
+ char *imtype;
+ imtype = (char *)malloc(tempstring.size() + 1);
+ memcpy(imtype, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(imtype,hcopy,1);
+ free(imtype);
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
+
diff --git a/sci_gateway/cpp/opencv_gabor.cpp b/sci_gateway/cpp/opencv_gabor.cpp
new file mode 100644
index 0000000..7e218df
--- /dev/null
+++ b/sci_gateway/cpp/opencv_gabor.cpp
@@ -0,0 +1,129 @@
+/*
+ * gabor
+ *
+ * gabor in scilab
+ *
+ */
+
+// Created by Samiran Roy, mail: samiranroy@cse.iitb.ac.in
+// An implementation of gabor method of matlab
+// Usage:
+// gabor(wavelength,orientation) - Generates a gabor kernel with the given wavelength and orientation
+// wavelength: pixels/cycle of the sinusoidal carrier, must be >=2
+// orientation: orientation of the filter in degrees, must be between [0,360]
+
+#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_gabor(char *fname, unsigned long fname_len) {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows = 0, iCols = 0;
+ int *piAddr = NULL;
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+
+ int error;
+
+ double wavelength;
+ double orientation;
+
+ // Get the number of input arguments
+ int inputarg = *getNbInputArgument(pvApiCtx);
+
+ // String holding the second argument
+ int iRet = 0;
+ char *pstData = NULL;
+
+ // Checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Geting the wavelength
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr1, &wavelength);
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return intErr;
+ }
+
+ if (wavelength < 2) {
+ sciprint("Wavelength must be >=2");
+ return 0;
+ }
+ // Getting the orientation
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &orientation);
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return intErr;
+ }
+
+ if ((orientation < 0) || (orientation > 360)) {
+ sciprint("Orientation must be in the range [0,360]");
+ return 0;
+ }
+
+ double sigma = (1 / CV_PI) * sqrt(log(2) / 2) * 3 *
+ wavelength; // calculating sigma following matlab convention
+
+ orientation = (orientation / 360) * 2 * CV_PI; // Converting degree to radian
+ int K_size =
+ 33 +
+ 16 * (wavelength - 2); // size of kernel following matlab convention
+
+ Mat new_image = getGaborKernel(cv::Size(K_size, K_size), sigma, orientation,
+ wavelength, 0.5, 0);
+ // sciprint("\n");
+
+ // for (int i = 0; i < new_image.rows; i++) {
+ // for (int j = 0; j < new_image.cols; j++) {
+ // sciprint("%f ", new_image.at<double>(i,j));
+
+ // }
+
+ // sciprint("\n");
+ // }
+
+ // new_image is sent to scilab as output
+
+ 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_gateway/cpp/opencv_gaussianblur.cpp b/sci_gateway/cpp/opencv_gaussianblur.cpp
new file mode 100644
index 0000000..f81885e
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_getStructuringElement.cpp b/sci_gateway/cpp/opencv_getStructuringElement.cpp
new file mode 100644
index 0000000..8226671
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_getTextSize.cpp b/sci_gateway/cpp/opencv_getTextSize.cpp
new file mode 100644
index 0000000..150b8ec
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_getgaussiankernel.cpp b/sci_gateway/cpp/opencv_getgaussiankernel.cpp
new file mode 100644
index 0000000..99c6d7d
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_getkerneltype.cpp b/sci_gateway/cpp/opencv_getkerneltype.cpp
new file mode 100644
index 0000000..68e72d9
--- /dev/null
+++ b/sci_gateway/cpp/opencv_getkerneltype.cpp
@@ -0,0 +1,118 @@
+//Syntax int getKernelType(InputArray, Px,py)
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : returnkernel_type= getkerneltype(InputArray,point px,point py) */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int getkerneltype(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr1 = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ double* pstData2;
+ double *rrows;
+ double *rcols;
+ int error;
+ double pi1,pi2;
+ // checking input argument
+ CheckInputArgument(pvApiCtx,3,3);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ // get Address of first input
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ //check for any error
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &piRows, &piCols,&pstData2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ Mat kernel=Mat(piRows,piCols,CV_64F);
+ int k=0,m=0;
+ for(int j=0;j<piCols;j++)
+ {
+ for(int i=0;i<piRows;i++)
+ {
+ kernel.at<double>(i,j)=pstData2[k++];
+
+ }
+ }
+ cout<<kernel;
+ //second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of second argument
+ error=getScalarDouble(pvApiCtx,piAddr2,&pi1);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+
+ //third argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of third argument
+ error=getScalarDouble(pvApiCtx,piAddr3,&pi2);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ Point anchor=Point(pi1,pi2);
+ double res;
+ res=getKernelType(kernel, anchor);
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,res);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+}
diff --git a/sci_gateway/cpp/opencv_getrectsubpix.cpp b/sci_gateway/cpp/opencv_getrectsubpix.cpp
new file mode 100644
index 0000000..2f6e835
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_getrotationmatrix2D.cpp b/sci_gateway/cpp/opencv_getrotationmatrix2D.cpp
new file mode 100644
index 0000000..5a54ed2
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_goodfeaturestotrack.cpp b/sci_gateway/cpp/opencv_goodfeaturestotrack.cpp
new file mode 100644
index 0000000..79e614f
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_grayconnected.cpp b/sci_gateway/cpp/opencv_grayconnected.cpp
new file mode 100644
index 0000000..32eba4f
--- /dev/null
+++ b/sci_gateway/cpp/opencv_grayconnected.cpp
@@ -0,0 +1,145 @@
+/***************************************************
+Author : Dhruti Shah
+****************************************************
+Usage : return_image = grayconnected(input_image,row,column,tolerance);
+***************************************************/
+
+#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_grayconnected(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 row, column, tolerance=32;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of row
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &row);
+ if(intErr)
+ return intErr;
+
+ //for value of column
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &column);
+ if(intErr)
+ return intErr;
+
+ if(nbInputArgument(pvApiCtx)==4)
+ {
+ //for value of tolerance
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &tolerance);
+ if(intErr)
+ return intErr;
+ }
+
+
+ if(row<0)
+ {
+ sciprint("Positive Value Required for Row.");
+ return 0;
+ }
+ if(column<0)
+ {
+ sciprint("Positive Value Required for Column.");
+ return 0;
+ }
+ if(tolerance<0)
+ {
+ sciprint("Positive Value Required for tolerance.");
+ return 0;
+ }
+
+
+ Mat gray_image;
+ cvtColor( image, gray_image, CV_BGR2GRAY );
+ Mat temp_image = Mat::zeros( image.size(), image.type() );
+ Mat image_to_display = Mat::zeros( image.size(), image.type() );
+
+ int value = gray_image.at<uchar>(row,column);
+
+ for(int i=0;i<image.cols;i++)
+ {
+ for(int j=0;j<image.rows;j++)
+ {
+ int value1 = gray_image.at<uchar>(i,j);
+ if(value1>=value-tolerance && value1<=tolerance+value)
+ temp_image.at<uchar>(i,j)=255;
+ else
+ temp_image.at<uchar>(i,j)=0;
+ }
+ }
+
+ Mat labelled_image(image.size(), image.type() );
+ int nlabels = connectedComponents(temp_image , labelled_image );
+ int label = labelled_image.at<uchar>(row,column);
+
+ for(int i=0;i<image.cols;i++)
+ {
+ for(int j=0;j<image.rows;j++)
+ {
+ if(labelled_image.at<uchar>(i,j)==label)
+ image_to_display.at<uchar>(i,j)=255;
+ }
+ }
+
+ //returning image
+ string tempstring = type2str(image_to_display.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,image_to_display,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_gateway/cpp/opencv_graycoprops.cpp b/sci_gateway/cpp/opencv_graycoprops.cpp
new file mode 100644
index 0000000..130b261
--- /dev/null
+++ b/sci_gateway/cpp/opencv_graycoprops.cpp
@@ -0,0 +1,408 @@
+/*
+ * graycoprops
+ *
+ * graycoprops in scilab
+ * Please refer to :
+ * http://www.cse.unsw.edu.au/~icml2002/workshops/MLCV02/MLCV02-Bevk.pdf, p.3.
+ */
+
+// Created by Samiran Roy, mail: samiranroy@cse.iitb.ac.in
+// An implementation of graycoprops method of matlab
+// Usage:
+// graycoprops(GLCM,property) : Calculates the Property of the input Gray level co-occurence matrix
+
+// Known Changes from Matlab:
+/*
+ * 1) None, as of now - Matching exactly - but does not use structures - for properties
+ */
+
+#include <numeric>
+#include <math.h>
+#include <vector>
+#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"
+
+double return_contrast(Mat image)
+
+{
+ double contrast = 0;
+
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ contrast = contrast + (pow((i - j), 2) * image.at<double>(i, j));
+ }
+ }
+ return contrast;
+}
+
+double return_correlation(Mat image)
+
+{
+ double correlation = 0;
+
+ std::vector<int> mg_rows;
+ std::vector<int> mg_cols;
+
+ // Meshgrid of row and column indices
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ mg_rows.push_back(j);
+ mg_cols.push_back(i);
+ }
+ }
+
+ // for (int i=0; i<rows.size();i++)
+ // sciprint("%d\n", rows[i]);
+
+ Mat flat_image = image.reshape(1, 1);
+
+ double mean_row = 0;
+ double mean_col = 0;
+ double std_row = 0;
+ double std_col = 0;
+
+ for (int i = 0; i < mg_rows.size(); i++)
+ mean_row = mean_row + mg_rows[i] * flat_image.at<double>(i);
+
+ for (int i = 0; i < mg_cols.size(); i++)
+ mean_col = mean_col + mg_cols[i] * flat_image.at<double>(i);
+
+ for (int i = 0; i < mg_rows.size(); i++)
+ std_row =
+ std_row + (pow(mg_rows[i] - mean_row, 2) * flat_image.at<double>(i));
+
+ std_row = sqrt(std_row);
+
+ for (int i = 0; i < mg_cols.size(); i++)
+ std_col =
+ std_col + (pow(mg_cols[i] - mean_col, 2) * flat_image.at<double>(i));
+
+ std_col = sqrt(std_col);
+
+ for (int i = 0; i < mg_rows.size(); i++)
+ correlation =
+ correlation + ((mg_rows[i] - mean_row) * (mg_cols[i] - mean_col) *
+ flat_image.at<double>(i));
+
+ double denom = std_col * std_row;
+ if (denom != 0) {
+ correlation = correlation / denom;
+ }
+
+ // sciprint("\n");
+
+ // sciprint("MR: %f",mean_row);
+ // sciprint("MC: %f",mean_col);
+
+ // sciprint("SR: %f",std_row);
+ // sciprint("SC: %f",std_col);
+ return correlation;
+}
+
+double return_energy(Mat image)
+
+{
+ double energy = 0;
+
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ energy = energy + pow(image.at<double>(i, j), 2);
+ }
+ }
+ return energy;
+}
+
+double return_homogeneity(Mat image)
+
+{
+ double homogeneity = 0;
+
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ homogeneity = homogeneity + (image.at<double>(i, j) / (1 + abs(i - j)));
+ }
+ }
+ return homogeneity;
+}
+
+int opencv_graycoprops(char *fname, unsigned long fname_len) {
+ SciErr sciErr;
+ int intErr = 0;
+
+ int *piAddr1 = NULL;
+
+ int error;
+
+ // String holding the second argument
+ int iRet = 0;
+ char *pstData = NULL;
+
+ // Checking input argument
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get input image
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ // converting image to float
+
+ image.convertTo(image, CV_64FC1, 1, 0);
+
+ // for (int i = 0; i < image.rows; i++) {
+ // for (int j = 0; j < image.cols; j++) {
+ // sciprint("%f ", image.at<double>(i, j));
+ // }
+
+ // sciprint("\n");
+ // }
+
+ // Error Checks
+
+ if (image.channels() == 1) {
+ // Normalizing image
+
+ double s = cv::sum(image)[0];
+ image = image / s;
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr1);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (isStringType(pvApiCtx, piAddr1)) {
+ if (isScalar(pvApiCtx, piAddr1)) {
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr1, &pstData);
+ }
+ }
+ if (strcmp(pstData, "contrast") == 0) {
+ double contrast = return_contrast(image);
+ intErr =
+ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, contrast);
+ 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;
+ }
+
+ else if (strcmp(pstData, "correlation") == 0) {
+ double correlation = return_correlation(image);
+
+ intErr = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,
+ correlation);
+ 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;
+ } else if (strcmp(pstData, "energy") == 0) {
+ double energy = return_energy(image);
+
+ intErr =
+ createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, energy);
+ 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;
+ }
+
+ else if (strcmp(pstData, "homogeneity") == 0) {
+ double homogeneity = return_homogeneity(image);
+
+ intErr = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,
+ homogeneity);
+ 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;
+ }
+
+ else {
+ sciprint("\nUnknown Parameter Name: %s\n", pstData);
+ return 0;
+ }
+ }
+
+ else if (image.channels() == 3) {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr1);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (isStringType(pvApiCtx, piAddr1)) {
+ if (isScalar(pvApiCtx, piAddr1)) {
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr1, &pstData);
+ }
+ }
+ if (strcmp(pstData, "contrast") == 0) {
+ vector<Mat> rgb;
+ split(image, rgb);
+
+ double *contrast = (double *)malloc(sizeof(double) * 3);
+ double s;
+
+ for (int i = 0; i < 3; i++) {
+ s = cv::sum(rgb[i])[0];
+ rgb[i] = rgb[i] / s;
+ contrast[2-i] = return_contrast(rgb[i]);
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx), 1, 3,
+ contrast);
+
+ free(contrast);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx);
+ // Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+ else if (strcmp(pstData, "correlation") == 0) {
+ vector<Mat> rgb;
+ split(image, rgb);
+
+ double *correlation = (double *)malloc(sizeof(double) * 3);
+ double s;
+
+ for (int i = 0; i < 3; i++) {
+ s = cv::sum(rgb[i])[0];
+ rgb[i] = rgb[i] / s;
+ correlation[2-i] = return_correlation(rgb[i]);
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx), 1, 3,
+ correlation);
+
+ free(correlation);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx);
+ // Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+ else if (strcmp(pstData, "energy") == 0) {
+ vector<Mat> rgb;
+ split(image, rgb);
+
+ double *energy = (double *)malloc(sizeof(double) * 3);
+ double s;
+
+ for (int i = 0; i < 3; i++) {
+ s = cv::sum(rgb[i])[0];
+ rgb[i] = rgb[i] / s;
+ energy[2-i] = return_energy(rgb[i]);
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx), 1, 3,
+ energy);
+
+ free(energy);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx);
+ // Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+
+ else if (strcmp(pstData, "homogeneity") == 0) {
+ vector<Mat> rgb;
+ split(image, rgb);
+
+ double *homogeneity = (double *)malloc(sizeof(double) * 3);
+ double s;
+
+ for (int i = 0; i < 3; i++) {
+ s = cv::sum(rgb[i])[0];
+ rgb[i] = rgb[i] / s;
+ homogeneity[2-i] = return_homogeneity(rgb[i]);
+ }
+
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx), 1, 3,
+ homogeneity);
+
+ free(homogeneity);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx);
+ // Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+ else {
+ sciprint("\nUnknown Parameter Name: %s\n", pstData);
+ return 0;
+ }
+
+ } else {
+ sciprint("Invalid number of channels in the image(must be 1 or 3)\n");
+ return 0;
+ }
+
+ // sciprint("\n");
+
+ // for (int i = 0; i < new_image.rows; i++) {
+ // for (int j = 0; j < new_image.cols; j++) {
+ // sciprint("%f ", new_image.at<double>(i,j));
+
+ // }
+
+ // sciprint("\n");
+ // }
+
+ // new_image is sent to scilab as output
+}
+/* ==================================================================== */
+}
+
diff --git a/sci_gateway/cpp/opencv_graydiffweight.cpp b/sci_gateway/cpp/opencv_graydiffweight.cpp
new file mode 100644
index 0000000..a0ea5e8
--- /dev/null
+++ b/sci_gateway/cpp/opencv_graydiffweight.cpp
@@ -0,0 +1,85 @@
+/********************************************************
+Authors: Dhruti Shah
+********************************************************/
+
+#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_graydiffweight(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 refGrayVal;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+
+ Mat image;
+ retrieveImage(image, 1);
+ cvtColor( image, image, CV_BGR2GRAY );
+
+ //for value of refGrayVal
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &refGrayVal);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ double value1, value2;
+ Mat new_image = Mat::zeros(image.size(),image.type());
+ for(int i=0; i<image.rows; i++)
+ {
+ for(int j=0; j<image.cols; j++)
+ {
+ value1 = image.at<uchar>(i,j);
+ value2 = abs(value1-refGrayVal);
+ new_image.at<uchar>(i,j)=value2;
+ }
+ }
+
+ 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_gateway/cpp/opencv_graydist.cpp b/sci_gateway/cpp/opencv_graydist.cpp
new file mode 100644
index 0000000..af09afd
--- /dev/null
+++ b/sci_gateway/cpp/opencv_graydist.cpp
@@ -0,0 +1,81 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = graydist(input_image, mask)
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <limits>
+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_graydist(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat marker, mask;
+ retrieveImage(marker, 1);
+ retrieveImage(mask, 2);
+
+ // do conversion of marker to gray
+ // do conversion of mask to gray
+
+ vector<Point> sources;
+ Mat distances(mask.size(), CV_32F);
+ Mat sptSet = Mat::zeros(mask.size(), CV_8UC1);
+ for (i = 0; i < mask.cols; i++)
+ {
+ for (j = 0; j < mask.rows; j++)
+ {
+ if (mask.at<uchar>(i,j)) {
+ sources.push_back(Point(i,j));
+ distances.at<float>(i,j) = 0.0;
+ }
+ else
+ distances.at<float>(i,j) = FLT_MAX;
+ }
+ }
+
+ for (c = 0; c < mask.cols * mask.rows; c++)
+ {
+ float l = minDistance(distances, sptSet);
+
+ }
+
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_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_gateway/cpp/opencv_histeq.cpp b/sci_gateway/cpp/opencv_histeq.cpp
new file mode 100644
index 0000000..2770074
--- /dev/null
+++ b/sci_gateway/cpp/opencv_histeq.cpp
@@ -0,0 +1,63 @@
+//histeq function is for grayscale image
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_image=histeq(rgbimage);
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/imgproc/imgproc.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<string.h>
+#include "../common.h"
+int histeq(char *fname, unsigned long fname_len)
+{
+
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ char** pstData = NULL;
+ int * pstData2 = NULL;
+ int* piAddr3 =NULL;
+ int* piAddr4 =NULL;
+ double *rrows;
+ double *rcols;
+ int t;
+ //checking input argument
+ CheckInputArgument(pvApiCtx,1,1);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1) ;
+ //for first argument
+ Mat img;
+ retrieveImage(img,1);
+ Mat dst;
+ ////open cv function to equalize the histogram
+ equalizeHist(img,dst);
+ string tempstring = type2str(dst.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
+/* ==================================================================== */
+
diff --git a/sci_gateway/cpp/opencv_houghcircles.cpp b/sci_gateway/cpp/opencv_houghcircles.cpp
new file mode 100644
index 0000000..4b36aa6
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_houghlines.cpp b/sci_gateway/cpp/opencv_houghlines.cpp
new file mode 100644
index 0000000..28202d1
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_houghlinesp.cpp b/sci_gateway/cpp/opencv_houghlinesp.cpp
new file mode 100644
index 0000000..1e69a09
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_ifftshift.cpp b/sci_gateway/cpp/opencv_ifftshift.cpp
new file mode 100644
index 0000000..8bf6ba2
--- /dev/null
+++ b/sci_gateway/cpp/opencv_ifftshift.cpp
@@ -0,0 +1,55 @@
+/********************************************************
+Function :ifftshift
+Syntax :B=ifftshift(A)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_ifftshift(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ Mat image;
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ retrieveImage(image,1);
+ int cx = floor(image.cols/2);
+ int cy = floor(image.rows/2);
+ Mat q0(image, Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant
+ Mat q1(image, Rect(cx, 0, cx, cy)); // Top-Right
+ Mat q2(image, Rect(0, cy, cx, cy)); // Bottom-Left
+ Mat q3(image, Rect(cx, cy, cx, cy)); // Bottom-Right
+ Mat tmp; // swap quadrants (Top-Left with Bottom-Right)
+ q0.copyTo(tmp);
+ q3.copyTo(q0);
+ tmp.copyTo(q3);
+ q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left)
+ q2.copyTo(q1);
+ tmp.copyTo(q2);
+ 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);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_im2double.cpp b/sci_gateway/cpp/opencv_im2double.cpp
new file mode 100644
index 0000000..45ee009
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_imabsdiff.cpp b/sci_gateway/cpp/opencv_imabsdiff.cpp
new file mode 100644
index 0000000..becb773
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imabsdiff.cpp
@@ -0,0 +1,51 @@
+/********************************************************
+Function :imabsdiff
+Syntax :C=imabsdiff(A,B)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_imabsdiff(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ Mat A,B,C;
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ retrieveImage(A,1);
+ retrieveImage(B,2);
+ Size s1=A.size();
+ Size s2=B.size();
+ if(s1!=s2)
+ {
+ sciprint("\nBoth input should be same size");
+ return 0;
+ }
+ absdiff(A,B,C);
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(C.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,C,1);
+ free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_imadd.cpp b/sci_gateway/cpp/opencv_imadd.cpp
new file mode 100644
index 0000000..b67335d
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imadd.cpp
@@ -0,0 +1,71 @@
+/********************************************************
+Function :imadd
+Syntax :C=imadd(A,B)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_imadd(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ Mat A,B,C;
+ int* piAddr2=NULL;
+ int iType = 0;
+ int iRet = 0;
+ double value= 0;
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ retrieveImage(A,1);
+ sciErr =getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ sciErr = getVarType(pvApiCtx, piAddr2, &iType);
+ if(iType==sci_list)
+ {
+ retrieveImage(B,2);
+ Size s1=A.size();
+ Size s2=B.size();
+ if(s1!=s2)
+ {
+ sciprint("\nBoth input should be same size");
+ return 0;
+ }
+ add(A,B,C);
+ }
+ else
+ {
+ if(isDoubleType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getScalarDouble(pvApiCtx, piAddr2, &value);
+ }
+ }
+ add(A,value,C);
+ }
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(C.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,C,1);
+ free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_imattributes.cpp b/sci_gateway/cpp/opencv_imattributes.cpp
new file mode 100644
index 0000000..51b544e
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imattributes.cpp
@@ -0,0 +1,114 @@
+/********************************************************
+ Author: Dhruti Shah
+*********************************************************
+ void imattributes(image)
+********************************************************/
+
+
+#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_imattributes(char *fname, unsigned long fname_len)
+ {
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1,1) ;
+
+
+ Mat image;
+ retrieveImage(image,1);
+
+ int row = image.rows;
+ int column = image.cols;
+ int type = image.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');
+
+
+ int flag_binary=1;
+
+ for(int i =0; i<row ; i++)
+ {
+ for(int j=0; j<column; j++)
+ {
+ if(image.at<uchar>(i,j)!=0 || image.at<uchar>(i,j)!=255)
+ {
+ flag_binary=0;
+ break;
+ }
+ }
+ if (flag_binary=0)
+ break;
+ }
+
+ string image_type;
+ //uchar chans = 1 + (type >> CV_CN_SHIFT);
+ if (flag_binary==1)
+ image_type = "Binary";
+ else if (chans==1)
+ image_type= "Intensity";
+ else if (chans==3)
+ image_type= "Truecolor";
+
+ char image_type1[100];
+ strcpy(image_type1, image_type.c_str());
+
+ char image_class[100];
+ strcpy(image_class, r.c_str());
+
+ sciprint("Width (columns) \t%d\n",column);
+ sciprint("Height (rows) \t%d\n",row);
+ sciprint("Class \t%s\n",image_class);
+ sciprint("Image Type \t%s\n",image_type1);
+
+ if(flag_binary!=1 && chans==1)
+ {
+ int min_intensity=255,max_intensity=0;
+ for(int i=0; i<row; i++)
+ {
+ for(int j=0; j<column; j++)
+ {
+ if(image.at<uchar>(i,j)<min_intensity)
+ min_intensity=image.at<uchar>(i,j);
+ if (image.at<uchar>(i,j)>max_intensity)
+ max_intensity=image.at<uchar>(i,j);
+ }
+ }
+
+ sciprint("Min intensity \t%d\n",min_intensity);
+ sciprint("Max intensity \t%d\n",max_intensity);
+ }
+
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_imboxfilt3.cpp b/sci_gateway/cpp/opencv_imboxfilt3.cpp
new file mode 100644
index 0000000..1af549f
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imboxfilt3.cpp
@@ -0,0 +1,130 @@
+/***************************************************
+Author : Yash S. Bhalgat
+****************************************************
+Usage :
+ 1) box_filtered_image = imboxfilt3(input_img);
+ In this usage, the default filter size of 3x3 is used.
+
+ 2) box_filtered_image = imboxfilt3(input_img, filter_height, filter_width);
+
+Example :
+ img = imread("lena.jpg");
+ imshow(img);
+ box_filtered_img = imboxfilt3(img, 9, 9);
+ imshow(box_filtered_img);
+***************************************************/
+
+#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_imboxfilt3(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int i,j,k;
+
+ //Default filter size
+ double filter_height = 3;
+ double filter_width = 3;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ int inputarg = *getNbInputArgument(pvApiCtx);
+
+
+ Mat image;
+ retrieveImage(image,1);
+
+
+ if(inputarg >= 2){
+ //for value of filter_height
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &filter_height);
+ if(intErr)
+ return intErr;
+
+ //for value of filter_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &filter_width);
+ if(intErr)
+ return intErr;
+ }
+
+
+ //taking the cases which can lead to an error
+ Mat filtered_image(image.rows,image.cols,image.type());
+
+ if(filter_height<0)
+ {
+ sciprint("Positive Value Required for Height. 3 value was used instead");
+ filter_height=3;
+ }
+ if(filter_width<0)
+ {
+ sciprint("Positive Value Required for Width. 3 value was used instead");
+ filter_width=3;
+ }
+ if((int)filter_height%2==0)
+ {
+ filter_height+=1;
+ sciprint("Odd Value Required for Height. %f value was used instead",&filter_height);
+ }
+ if((int)filter_width%2==0)
+ {
+ filter_width+=1;
+ sciprint("Odd Value Required for Width. %f value was used instead",&filter_width);
+ }
+
+ //temporary size variable, to use in function
+ Size sz(filter_height,filter_width);
+
+ //opencv function called
+ //if both filter_size is not given, default value of 3x3 is used
+ boxFilter(image,filtered_image, -1, sz);
+
+ //returning image
+ string tempstring = type2str(filtered_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,filtered_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_gateway/cpp/opencv_imcomplement.cpp b/sci_gateway/cpp/opencv_imcomplement.cpp
new file mode 100644
index 0000000..efcaa9a
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imcomplement.cpp
@@ -0,0 +1,67 @@
+/********************************************************
+Function :imcomplement
+Syntax :B=imcomplement(A)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_imcomplement(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ Mat A,B,C;
+ int* piAddr2=NULL;
+ int iType = 0;
+ int iRet = 0;
+ double value= 0;
+ CheckInputArgument(pvApiCtx, 1,1);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ retrieveImage(A,1);
+ if(A.channels()==3)
+ {
+ for(int x=0;x< A.rows; x++)
+ {
+ for ( int y=0;y<A.cols;y++)
+ {
+ for(int i=0;i<3;i++)
+ A.at<Vec3b>(x,y)[i]=255-A.at<Vec3b>(x,y)[i];
+ }
+ }
+ }
+ else
+ {
+ for(int x=0;x<A.rows;x++)
+ {
+ for ( int y=0; y< A.cols; y++)
+ {
+ A.at<uchar>(x,y)=255-A.at<uchar>(x,y);
+ }
+ }
+ }
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(A.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,A,1);
+ free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_imcontour.cpp b/sci_gateway/cpp/opencv_imcontour.cpp
new file mode 100644
index 0000000..7d6a83b
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imcontour.cpp
@@ -0,0 +1,62 @@
+/********************************************************
+Function :imcontour
+Syntax :B=imcontour(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_imcontour(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ Mat gray,image;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ retrieveImage(image, 1);
+ cvtColor(image, gray, CV_BGR2GRAY);
+ Canny(gray, gray, 100, 200, 3);
+ /// Find contours
+ vector<vector<Point> > contours;
+ vector<Vec4i> hierarchy;
+ RNG rng(12345);
+ findContours( gray, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
+ /// Draw contours
+ Mat drawing = Mat::zeros( gray.size(), CV_8UC3 );
+ for( int i = 0; i< contours.size(); i++ )
+ {
+ Scalar color = Scalar(rng.uniform(0,255),rng.uniform(0,255),rng.uniform(0,255));
+ drawContours( drawing, contours, i, color, 1, 8, hierarchy, 0, Point());
+ }
+ bitwise_not(drawing,drawing);
+ string tempstring = type2str(drawing.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,drawing,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_gateway/cpp/opencv_imcontrast.cpp b/sci_gateway/cpp/opencv_imcontrast.cpp
new file mode 100644
index 0000000..216228f
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_imcrop.cpp b/sci_gateway/cpp/opencv_imcrop.cpp
new file mode 100644
index 0000000..d180c0a
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_imdivide.cpp b/sci_gateway/cpp/opencv_imdivide.cpp
new file mode 100644
index 0000000..2ede4d2
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imdivide.cpp
@@ -0,0 +1,71 @@
+/********************************************************
+Function :imdivide
+Syntax :C=imdivide(A,B)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_imdivide(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ Mat A,B,C;
+ int* piAddr2=NULL;
+ int iType = 0;
+ int iRet = 0;
+ double value= 0;
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ retrieveImage(A,1);
+ sciErr =getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ sciErr = getVarType(pvApiCtx, piAddr2, &iType);
+ if(iType==sci_list)
+ {
+ retrieveImage(B,2);
+ Size s1=A.size();
+ Size s2=B.size();
+ if(s1!=s2)
+ {
+ sciprint("\nBoth input should be same size");
+ return 0;
+ }
+ divide(A,B,C);
+ }
+ else
+ {
+ if(isDoubleType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getScalarDouble(pvApiCtx, piAddr2, &value);
+ }
+ }
+ C=A/value;
+ }
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(C.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,C,1);
+ free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_imextendedmax.cpp b/sci_gateway/cpp/opencv_imextendedmax.cpp
new file mode 100644
index 0000000..ba457d5
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imextendedmax.cpp
@@ -0,0 +1,99 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = imextendedmax(input_image, h)
+Example:
+ im = imextendedmax(image, 80)
+********************************************************/
+
+#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"
+
+ void imextendedmax_imreconstruct(Mat, Mat, Mat&);
+
+ int opencv_imextendedmax(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+ double h;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Get the input image from the Scilab environment
+ Mat image;
+ retrieveImage(image, 1);
+
+ // Get the address of 2nd argument, the H-Maxima transform scalar
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the H-Maxima transform scalar
+ intErr = getScalarDouble(pvApiCtx, piAddr, &h);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if (h < 0)
+ {
+ sciprint("Please enter a nonnegative scalar for H-maxima transform.\n");
+ return 0;
+ }
+
+ Mat gray_image, dst, fin_image, m, m2;
+ cvtColor(image, gray_image, CV_BGR2GRAY);
+ max((gray_image-h), 0, m);
+ imextendedmax_imreconstruct(gray_image, m, dst);
+ subtract(dst, 1, m2);
+ imextendedmax_imreconstruct(dst, m2, m);
+ subtract(dst, m, m2);
+ fin_image = m2 * 255;
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_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;
+
+ }
+ void imextendedmax_imreconstruct(Mat g, Mat f, Mat& dest)
+ {
+ Mat m0, m1, m;
+ m1 = f;
+ do {
+ m0 = m1.clone();
+ dilate(m0, m, Mat());
+ min(g, m, m1);
+ } while(countNonZero(m1 != m0) != 0);
+ dest = m1.clone();
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_imextendedmin.cpp b/sci_gateway/cpp/opencv_imextendedmin.cpp
new file mode 100644
index 0000000..b5a8fa3
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imextendedmin.cpp
@@ -0,0 +1,100 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = imextendedmin(input_image, h)
+Example:
+ im = imextendedmin(image, 80)
+********************************************************/
+
+#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"
+
+ void imextendedmin_imreconstruct(Mat, Mat, Mat&);
+
+ int opencv_imextendedmin(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+ double h;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Get the input image from the Scilab environment
+ Mat image;
+ retrieveImage(image, 1);
+
+ // Get the address of 2nd argument, the H-Minima transform scalar
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the H-Minima transform scalar
+ intErr = getScalarDouble(pvApiCtx, piAddr, &h);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if (h < 0)
+ {
+ sciprint("Please enter a nonnegative scalar for H-minima transform.\n");
+ return 0;
+ }
+
+ Mat gray_image, dst, fin_image, m, m2;
+ cvtColor(image, gray_image, CV_BGR2GRAY);
+ min((gray_image + h), 255, m);
+ imextendedmin_imreconstruct(gray_image, m, dst);
+ add(dst, 1, m2);
+ imextendedmin_imreconstruct(dst, m2, m);
+ subtract(m, dst, m2);
+ fin_image = m2 * 255;
+
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_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;
+
+ }
+ void imextendedmin_imreconstruct(Mat g, Mat f, Mat& dest)
+ {
+ Mat m0, m1, m;
+ m1 = f;
+ do {
+ m0 = m1.clone();
+ erode(m0, m, Mat());
+ max(g, m, m1);
+ } while(countNonZero(m1 != m0) != 0);
+ dest = m1.clone();
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_imfill.cpp b/sci_gateway/cpp/opencv_imfill.cpp
new file mode 100644
index 0000000..7e0c79d
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imfill.cpp
@@ -0,0 +1,192 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = imfill(image)
+ return_image = imfill(image, 'holes')
+ return_image = imfill(image, points)
+Example:
+ im = imfill(image, [1 1; 10 10; 11 12])
+********************************************************/
+
+#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"
+
+ void imfill_imreconstruct(Mat, Mat, Mat&);
+
+ int opencv_imfill(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+ int i, j;
+ double maxVal;
+ int iRet;
+ int iRows, iCols;
+ double *pstData = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat image, dst;
+ retrieveImage(image, 1);
+
+ if (nbInputArgument(pvApiCtx) == 2)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (image.type() != CV_8UC1)
+ {
+ Mat temp;
+ temp = image.clone();
+ cvtColor(temp, image, CV_BGR2GRAY);
+ }
+
+ if(isStringType(pvApiCtx, piAddr))
+ {
+ char* pstData = NULL;
+
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr, &pstData);
+
+ if(iRet)
+ {
+ freeAllocatedSingleString(pstData);
+ return iRet;
+ }
+
+ if (strcmp(pstData, "holes") == 0)
+ {
+ freeAllocatedSingleString(pstData);
+ // Floodfill from point (0, 0)
+ Mat im_floodfill = image.clone();
+ floodFill(im_floodfill, Point(0,0), Scalar(255));
+
+ // Invert floodfilled image
+ Mat im_floodfill_inv;
+ bitwise_not(im_floodfill, im_floodfill_inv);
+
+ // Combine the two images to get the foreground.
+ Mat dst2 = (image | im_floodfill_inv);
+ erode(dst2, dst, Mat());
+
+ }
+ else
+ {
+ sciprint("Option not identified. Maybe you meant 'holes'.");
+ return 0;
+ }
+ }
+ else
+ {
+
+ // Get the points list in the form of a matrix
+ // No. of columns = 2
+ // No. of rows = No. of points
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iCols != 2)
+ {
+ sciprint("Please enter a valid column and row index.");
+ return 0;
+ }
+
+ for (i = 0; i < iRows*iCols; i += iCols)
+ {
+ if (pstData[i] < 0 || pstData[i+1] < 0)
+ {
+ sciprint("Coordinates cannot be negative.\n");
+ return 0;
+ }
+ else
+ floodFill(image, Point(pstData[i], pstData[i+1]), Scalar(255));
+ }
+
+ dst = image.clone();
+ }
+
+ }
+ else
+ {
+ Mat gray_image;
+ cvtColor(image, gray_image, CV_BGR2GRAY);
+
+ minMaxLoc(gray_image, NULL, &maxVal, NULL, NULL);
+
+ Mat marker = Mat(gray_image.size(), gray_image.type());
+
+ marker = Scalar::all(maxVal);
+
+ for (i = 0; (i == 0 || i == marker.cols-1); i += (marker.cols - 1))
+ {
+ for (j = 0; j < marker.rows; j++)
+ {
+ marker.at<uchar>(i,j) = gray_image.at<uchar>(i,j);
+ }
+ }
+
+ for (i = 1; i < marker.cols-1; i++)
+ {
+ for (j = 0; (j == 0 || j == marker.rows-1); j += (marker.rows - 1))
+ {
+ marker.at<uchar>(i,j) = gray_image.at<uchar>(i,j);
+ }
+ }
+
+ imfill_imreconstruct(gray_image, marker, dst);
+ }
+
+
+
+ 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;
+
+ }
+ void imfill_imreconstruct(Mat g, Mat f, Mat& dest)
+ {
+ Mat m0, m1, m;
+ m1 = f;
+ do {
+ m0 = m1.clone();
+ erode(m0, m, Mat());
+ max(g, m, m1);
+ } while(countNonZero(m1 != m0) != 0);
+ dest = m1.clone();
+ }
+
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway/cpp/opencv_imfindcircles.cpp b/sci_gateway/cpp/opencv_imfindcircles.cpp
new file mode 100644
index 0000000..2569343
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_imfindcircles.cpp~ b/sci_gateway/cpp/opencv_imfindcircles.cpp~
new file mode 100644
index 0000000..7201e7d
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imfindcircles.cpp~
@@ -0,0 +1,148 @@
+/********************************************************
+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, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 2) ;
+ sciprint("here1");
+ 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;
+// }
+ sciprint("here2");
+ 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, 1, src_gray.rows/8, 200, 100,0,0);
+ sciprint("here3");
+ int k=circles.size();
+ if (k==0)
+ {sciprint("zero");}
+ else if (k==1)
+ {sciprint("one");}
+ else if (k==2)
+ {sciprint("two");}
+ else if (k==3)
+ {sciprint("three");}
+ else
+ {sciprint(">3");}
+ 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);
+ sciprint("here4");
+ for( size_t i= 0; i < circles.size(); i++ )
+ {
+ c1[i]=cvRound(circles[i][0]);
+ cout<<c1[i];
+ sciprint("here5");
+ c2[i]=cvRound(circles[i][1]);
+ cout<<c2[i];
+ sciprint("here6");
+ radius[i]=cvRound(circles[i][2]);
+ cout<<radius[i];
+ sciprint("here7");
+ }
+ 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_gateway/cpp/opencv_imfuse.cpp b/sci_gateway/cpp/opencv_imfuse.cpp
new file mode 100644
index 0000000..dfe7e4d
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imfuse.cpp
@@ -0,0 +1,470 @@
+/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+Created By: Riddhish Bhalodia
+Date: 29th September 2015
+
+Usage:
+
+Mat dst = imfuse(Mat image1,Mat image2,String method,String scaling)
+
+1) image1 : Input image1
+2) image2 : Input image2
+3) method : Method for the type of display
+
+ | Method | Function |
+ | | |
+ | "montage" | Display Images side by side |
+ | "blend" | Display the blend of two Images alpha=0.5 |
+ | "diff" | Display the absolute difference between Images |
+ | "falsecolor" | Display image1 by green channel and image2 by red |
+
+4) scaling : The scaling of the images
+
+ | Scaling | Function |
+ | | |
+ | "none" | No scaling to the images |
+ | "joint" | Scale the joint images |
+ | "independent" | Scale the images independently before processing |
+
+
+
+*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+#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_imfuse(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 *piLen1 = NULL;
+ int *piLen2 = NULL;
+ char **method = NULL;
+ char **scaling = NULL;
+
+ Mat image1,image2;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ retrieveImage(image1, 1);
+ retrieveImage(image2, 2);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &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;
+ }
+ piLen1 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen1, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ method = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ method[i] = (char*)malloc(sizeof(char) * (piLen1[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen1, method);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // now the fourth argument which is aging a string
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &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;
+ }
+ piLen2 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen2, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ scaling = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ scaling[i] = (char*)malloc(sizeof(char) * (piLen2[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen2, scaling);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ char x1[15] = "montage";
+ char x2[15] = "diff";
+ char x3[15] = "blend";
+ char x4[15] = "falsecolor";
+ char y1[15] = "joint";
+ char y2[15] = "independent";
+ char y3[15] = "none";
+ // Error check on method
+ if(!(strcmp(method[0],x1)==0 || strcmp(method[0],x2)==0 || strcmp(method[0],x3)==0 || strcmp(method[0],x4)==0 )){
+ sciprint("Method input not correct, choose from 'blend','diff','montage' or 'falsecolor' \n");
+ return 0;
+ }
+ // Error check on scaling
+
+ if(!(strcmp(scaling[0],y1)==0 || strcmp(scaling[0],y2)==0 || strcmp(scaling[0],y3)==0 )){
+ sciprint("Method input not correct, choose from 'none','diff','montage' or 'falsecolor' \n");
+ return 0;
+ }
+
+ int max_rows,max_cols;
+ Mat out;
+ max_rows = max(image1.rows,image2.rows);
+ max_cols = max(image1.cols,image2.cols);
+ if(image1.channels() == 1){ cvtColor(image1,image1,CV_BGR2GRAY);}
+ if(image2.channels() == 1){ cvtColor(image2,image2,CV_BGR2GRAY);}
+
+ vector<Mat> rgbChannels(3);
+ // for montage and no scaling plus joint scaling
+
+ if(strcmp(method[0],x1)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+ out = Mat::zeros(max_rows,2*max_cols,image1.type());
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j + max_cols)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j + max_cols)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j + max_cols)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+ }
+ // for montage and scaling independent
+ if(strcmp(method[0],x1)==0 && strcmp(scaling[0],y2)==0) {
+
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+
+ out = Mat::zeros(max_rows,2*max_cols,image1.type());
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j + max_cols)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j + max_cols)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j + max_cols)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+ }
+
+ // for diff and no scaling plus joint scaling
+ if(strcmp(method[0],x2)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+
+ // cvtColor(image1,image1,CV_BGR2GRAY);
+ // cvtColor(image2,image2,CV_BGR2GRAY);
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = abs((image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2]) - (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2]))/3;
+ out.at<Vec3b>(i,j)[1] = abs((image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2]) - (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2]))/3;
+ out.at<Vec3b>(i,j)[2] = abs((image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2]) - (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2]))/3;
+ }
+ }
+ }
+ // for diff and independent scaling
+ if(strcmp(method[0],x2)==0 && strcmp(scaling[0],y2)==0) {
+
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+
+ // cvtColor(image1,image1,CV_BGR2GRAY);
+ // cvtColor(image2,image2,CV_BGR2GRAY);
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = abs(image1.at<Vec3b>(i,j)[0] - image2.at<Vec3b>(i,j)[0]);
+ out.at<Vec3b>(i,j)[1] = abs(image1.at<Vec3b>(i,j)[1] - image2.at<Vec3b>(i,j)[1]);
+ out.at<Vec3b>(i,j)[2] = abs(image1.at<Vec3b>(i,j)[2] - image2.at<Vec3b>(i,j)[2]);
+ }
+ }
+ }
+
+ // for blend and no scaling[0] plus joint scaling[0]
+ if(strcmp(method[0],x3)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = 0.5*(image1.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[0]);
+ out.at<Vec3b>(i,j)[1] = 0.5*(image1.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[1]);
+ out.at<Vec3b>(i,j)[2] = 0.5*(image1.at<Vec3b>(i,j)[2] + image2.at<Vec3b>(i,j)[2]);
+ }
+ }
+
+ }
+ // for blend and independent scaling[0]
+ if(strcmp(method[0],x3)==0 && strcmp(scaling[0],y2)==0) {
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = 0.5*(image1.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[0]);
+ out.at<Vec3b>(i,j)[1] = 0.5*(image1.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[1]);
+ out.at<Vec3b>(i,j)[2] = 0.5*(image1.at<Vec3b>(i,j)[2] + image2.at<Vec3b>(i,j)[2]);
+ }
+ }
+
+ }
+
+ // for falsecolor and no scaling[0] plus joint scaling[0]
+ if(strcmp(method[0],x4)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ // image 1 green image2 red
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = 0;
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = 0;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ if(image1.at<Vec3b>(i,j) == image2.at<Vec3b>(i,j)){
+ out.at<Vec3b>(i,j)[0] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ else{
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+
+ }
+ }
+
+ }
+ // for falsecolor and independent scaling[0]
+ if(strcmp(method[0],x4)==0 && strcmp(scaling[0],y2)==0) {
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+ //scale image 1 and image 2
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+ // image 1 green image2 red
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = 0;
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = 0;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ if(image1.at<Vec3b>(i,j) == image2.at<Vec3b>(i,j)){
+ out.at<Vec3b>(i,j)[0] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ else{
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+
+ }
+ }
+
+ }
+
+ // for joint scaling[0]
+ if(strcmp(scaling[0],y3)==0){
+ split(out, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,out);
+ }
+
+ if(image1.channels()==1 && image2.channels()==1){
+ cvtColor(out,out,CV_BGR2GRAY);
+ }
+
+ // out is the return image
+ 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);
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/sci_gateway/cpp/opencv_imgaborfilt.cpp b/sci_gateway/cpp/opencv_imgaborfilt.cpp
new file mode 100644
index 0000000..457a4be
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imgaborfilt.cpp
@@ -0,0 +1,159 @@
+/*
+ * imgaborfilt
+ *
+ * imgaborfilt in scilab
+ *
+ */
+
+// Created by Samiran Roy, mail: samiranroy@cse.iitb.ac.in
+// An implementation of imgaborfilt in scilab
+// Usage:
+// imgaborfilt(I,wavelength,orientation) : Perform gabor filtering on a grayscale image with given wavelength and orientation
+// imboxfilt(I,method)
+// method : 'upright' (default)
+// method : 'rotated' The area sums are calulated over a rectangle, which is
+// rotated 45 degrees
+// Known Changes from Matlab:
+/*
+ * 1) None, as of now
+ */
+
+#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_imgaborfilt(char *fname, unsigned long fname_len) {
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows = 0, iCols = 0;
+ int *piAddr = NULL;
+ int *piAddr1 = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+
+ int error;
+
+ double wavelength;
+ double orientation;
+
+ int borderType = BORDER_REPLICATE;
+
+ // Parameters for convolution - Leave these alone
+
+ /* **********************************************************************************
+ */
+
+ Point anchor;
+ double delta;
+ int ddepth;
+
+ anchor = Point(-1, -1); // The center is unchanged
+ delta = 0; // No value is added to output
+ ddepth = -1; // The dimentions of input and output images are the same
+
+ /* **********************************************************************************
+ */
+
+ // Get the number of input arguments
+ int inputarg = *getNbInputArgument(pvApiCtx);
+
+ // String holding the second argument
+ int iRet = 0;
+ char *pstData = NULL;
+
+ // Checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get input image
+
+ Mat image;
+ retrieveImage(image, 1);
+
+ if (image.channels() > 1) {
+ sciprint("The image must be grayscale.");
+ return 0;
+ }
+
+ // Getting the wavelength
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &wavelength);
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return intErr;
+ }
+
+ if (wavelength < 2) {
+ sciprint("Wavelength must be >=2");
+ return 0;
+ }
+ // Getting the orientation
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &orientation);
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return intErr;
+ }
+
+ if ((orientation < 0) || (orientation > 360)) {
+ sciprint("Orientation must be in the range [0,360]");
+ return 0;
+ }
+
+ double sigma = (1 / CV_PI) * sqrt(log(2) / 2) * 3 *
+ wavelength; // calculating sigma following matlab convention
+
+ orientation = (orientation / 360) * 2 * CV_PI; // Converting degree to radian
+ int K_size =
+ 33 +
+ 16 * (wavelength - 2); // size of kernel following matlab convention
+
+ Mat kernel = getGaborKernel(cv::Size(K_size, K_size), sigma, orientation,
+ wavelength, 0.5, 0);
+
+ Mat floatimage;
+ image.convertTo(floatimage, CV_32F); // Converting image to float type
+
+ Mat dst;
+ Mat new_image;
+ filter2D(floatimage, new_image, CV_32F, kernel); // Performing convolution
+
+ 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_gateway/cpp/opencv_imgaussfilt3.cpp b/sci_gateway/cpp/opencv_imgaussfilt3.cpp
new file mode 100644
index 0000000..f07076f
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imgaussfilt3.cpp
@@ -0,0 +1,138 @@
+/***************************************************
+Author : Yash S. Bhalgat
+****************************************************
+Usage : filtered_image = imgaussfilt3(input_img, filter_height, filter_width, sigmaX, sigmaY);
+Example :
+ img = imread("lena.jpg");
+ imshow(img);
+ filtered_img = imgaussfilt3(img, 9, 9, 3, 3);
+ imshow(filtered_img);
+***************************************************/
+
+#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_imgaussfilt3(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 filter_width,filter_height,sigmaX,sigmaY;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 5, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of filter_height
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &filter_height);
+ if(intErr)
+ return intErr;
+
+ //for value of filter_width
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &filter_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;
+
+ //taking the cases which can lead to an error
+ Mat filtered_image(image.rows,image.cols,CV_8UC3);
+ if(filter_height<0)
+ {
+ sciprint("Positive Value Required for Height. 1 value was used instead");
+ filter_height=1;
+ }
+ if(filter_width<0)
+ {
+ sciprint("Positive Value Required for Width. 1 value was used instead");
+ filter_width=1;
+ }
+ if((int)filter_height%2==0)
+ {
+ filter_height+=1;
+ sciprint("Odd Value Required for Height. %f value was used instead",&filter_height);
+ }
+ if((int)filter_width%2==0)
+ {
+ filter_width+=1;
+ sciprint("Odd Value Required for Width. %f value was used instead",&filter_width);
+ }
+
+ //temporary size variable, to use in function
+ Size sz(filter_height,filter_width);
+
+ //opencv function called
+ //if both sigmaX, sigmaY are set to zero, they are calaulated from the filter_size
+ GaussianBlur(image,filtered_image,sz,sigmaX,sigmaY);
+
+ //returning image
+ string tempstring = type2str(filtered_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,filtered_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_gateway/cpp/opencv_imguidedfilter.cpp b/sci_gateway/cpp/opencv_imguidedfilter.cpp
new file mode 100644
index 0000000..6d4df43
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imguidedfilter.cpp
@@ -0,0 +1,227 @@
+/*************************************************************************************
+Author : Yash S. Bhalgat
+
+References : Kaiming He, Jian Sun, Xiaoou Tang, "Guided Image Filtering", IEEE Transactions
+ on Pattern Analysis & Machine Intelligence, vol.35, no. 6,
+ pp. 1397-1409, June 2013, doi:10.1109/TPAMI.2012.213
+***************************************************************************************
+Usage :
+ Covers all the cases of I and p being grayscale and RGB
+
+ 1) guidedFiltered_image = imguidedfilter(input_img);
+ In this usage, the image itself is used as the guidance image.
+
+ 2) guidedFiltered_image = imguidedfilter(input_img, guidance_img);
+
+ The following two functionalities are not provided in Matlab in this way:
+ 3) guidedFiltered_image = imguidedfilter(input_img, guidance_img, r);
+ 4) guidedFiltered_image = imguidedfilter(input_img, guidance_img, r, eps);
+
+Example :
+ img = imread("lena.jpg");
+ imshow(img);
+ guidedFiltered_image = imguidedfilter(img, img, 9);
+ imshow(guidedFiltered_image);
+***********************************************************************/
+
+#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_imguidedfilter(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 i,j,k;
+
+ //Default filter size
+ double r= 4;
+ double eps= 0.2 * 0.2 * 255 * 255;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ int inputarg = *getNbInputArgument(pvApiCtx);
+
+
+ Mat I;
+ retrieveImage(I,1);
+
+ Mat p=I;
+
+ if(inputarg > 1){
+ //for value of filter_height
+ //sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ //if (sciErr.iErr)
+ //{
+ // printError(&sciErr, 0);
+ // return 0;
+ //}
+ //intErr = getScalarDouble(pvApiCtx, piAddr2, &filter_height);
+ //if(intErr)
+ // return intErr;
+ Mat G;
+ retrieveImage(G,1);
+ p=G;
+
+ if(inputarg > 2){
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &r);
+ if(intErr)
+ return intErr;
+ }
+ if(inputarg > 3){
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &eps);
+ if(intErr)
+ return intErr;
+ }
+ }
+
+
+ Mat guidedFiltered_image;
+
+
+ //Main function
+ //if both filter_size is not given, default value of 3x3 is used
+ if(I.channels() == 1){
+ Mat mean_p;
+ blur(p, mean_p, Size(r, r));
+
+ Mat mean_Ip;
+ blur(I.mul(p), mean_Ip, Size(r, r));
+
+ Mat mean_I;
+ blur(I, mean_I, Size(r, r));
+
+ Mat mean_II;
+ blur(I.mul(I), mean_II, Size(r,r));
+
+ Mat var_I = mean_II - mean_I.mul(mean_I);
+
+ Mat cov_Ip = mean_Ip - mean_I.mul(mean_p); //covariance of (I, p) in each local patch.
+
+ Mat a = cov_Ip / (var_I + eps);
+ Mat b = mean_p - a.mul(mean_I);
+
+ Mat mean_a;
+ blur(a, mean_a, Size(r, r));
+ Mat mean_b;
+ blur(b, mean_b, Size(r, r));
+
+ guidedFiltered_image = mean_a.mul(I) + mean_b;
+ }
+ else if(I.channels()==3 && p.channels()==1){
+ vector<cv::Mat> Ichannels, channels;
+ split(I, Ichannels);
+ guidedFiltered_image = I;
+ //split(guidedFiltered_image, channels);
+
+ Mat mean_p, mean_I, mean_Ip;
+ Mat mean_II, var_I, cov_Ip, a, b;
+ Mat mean_a, mean_b;
+
+ for(i=0; i<3; i++){
+ blur(p, mean_p, Size(r, r));
+
+ blur(Ichannels[i].mul(p), mean_Ip, Size(r, r));
+
+ blur(Ichannels[i], mean_I, Size(r, r));
+
+ blur(Ichannels[i].mul(Ichannels[i]), mean_II, Size(r,r));
+
+ var_I = mean_II - mean_I.mul(mean_I);
+
+ cov_Ip = mean_Ip - mean_I.mul(mean_p); //covariance of (Ichannels[i], p) in each local patch.
+
+ a = cov_Ip / (var_I + eps);
+ b = mean_p - a.mul(mean_I);
+
+ blur(a, mean_a, Size(r, r));
+ blur(b, mean_b, Size(r, r));
+
+ channels.push_back(mean_a.mul(Ichannels[i]) + mean_b);
+ }
+ merge(channels,guidedFiltered_image);
+ }
+ else if(I.channels()==3 && p.channels()==3){
+ vector<cv::Mat> Ichannels, channels, pchannels;
+
+ split(I, Ichannels);
+ guidedFiltered_image = I;
+ //split(guidedFiltered_image, channels);
+ split(p, pchannels);
+
+ Mat mean_p, mean_I, mean_Ip;
+ Mat mean_II, var_I, cov_Ip, a, b;
+ Mat mean_a, mean_b;
+
+ for(i=0; i<3; i++){
+ blur(pchannels[i], mean_p, Size(r, r));
+
+ blur(Ichannels[i].mul(pchannels[i]), mean_Ip, Size(r, r));
+
+ blur(Ichannels[i], mean_I, Size(r, r));
+
+ blur(Ichannels[i].mul(Ichannels[i]), mean_II, Size(r,r));
+
+ var_I = mean_II - mean_I.mul(mean_I);
+
+ cov_Ip = mean_Ip - mean_I.mul(mean_p); //covariance of (Ichannels[i], pchannels[i]) in each local patch.
+
+ a = cov_Ip / (var_I + eps);
+ b = mean_p - a.mul(mean_I);
+
+ blur(a, mean_a, Size(r, r));
+ blur(b, mean_b, Size(r, r));
+
+ channels.push_back(mean_a.mul(Ichannels[i]) + mean_b);
+ }
+ merge(channels,guidedFiltered_image);
+ }
+
+ //returning image
+ string tempstring = type2str(guidedFiltered_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,guidedFiltered_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_gateway/cpp/opencv_imhistmatch.cpp b/sci_gateway/cpp/opencv_imhistmatch.cpp
new file mode 100644
index 0000000..146b0b3
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imhistmatch.cpp
@@ -0,0 +1,296 @@
+/*
+ * imhistmatch
+ *
+ * histogram matching in scilab
+ *
+ */
+
+// Created by Samiran Roy, mail: samiranroy@cse.iitb.ac.in
+// An implementation of imhistmatch method
+// Usage:
+// 1) imhistmatch(image,referenceimage)
+// 2) imhistmatch(image,referenceimage,outputbins)
+
+// Known Changes from Matlab:
+/*
+ * Default number of bins is 256 - for both input and output
+ */
+
+#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"
+
+// Matches the input image histogram with the reference image histogram,
+// returning the output in n bins
+
+Mat match(Mat image, Mat ref, int bins) {
+ Mat dst, hist;
+ Mat input_image = Mat::zeros(image.size(), CV_8U);
+ Mat refhist;
+
+ int inputbins = 256;
+
+ Mat cdf = Mat(inputbins, 1, CV_8U, cvScalar(0));
+
+ Mat refcdf = Mat(bins, 1, CV_8U, cvScalar(0));
+
+ // Calculating histogram of image
+ image.convertTo(dst, CV_8U, 1, 0);
+
+ calcHist(&dst, 1, 0, Mat(), hist, 1, &inputbins, 0);
+
+ // Calculating histogram of reference image
+
+ ref.convertTo(dst, CV_8U, 1, 0);
+ calcHist(&dst, 1, 0, Mat(), refhist, 1, &bins, 0);
+
+ hist.copyTo(cdf);
+ refhist.copyTo(refcdf);
+
+ // calculate cdf
+ for (int h = 1; h < inputbins; h++) {
+ float binVal = hist.at<float>(h, 0);
+
+ cdf.at<float>(h, 0) = cdf.at<float>(h, 0) + cdf.at<float>(h - 1, 0);
+ }
+
+ // normalize histogram
+ for (int h = 0; h < inputbins; h++) {
+ cdf.at<float>(h, 0) = cdf.at<float>(h, 0) / cdf.at<float>(inputbins - 1, 0);
+ }
+
+ // for reference image
+
+ // calculate cdf
+ for (int h = 1; h < bins; h++) {
+ float binVal = refhist.at<float>(h, 0);
+
+ refcdf.at<float>(h, 0) =
+ refcdf.at<float>(h, 0) + refcdf.at<float>(h - 1, 0);
+ }
+
+ // normalize histogram
+ for (int h = 0; h < bins; h++) {
+ refcdf.at<float>(h, 0) =
+ refcdf.at<float>(h, 0) / refcdf.at<float>(bins - 1, 0);
+ }
+
+ // for( int h = 0; h < bins; h++ )
+ // {
+ // sciprint("%f\n",refcdf.at<float>(h,0));
+
+ // }
+
+ // sciprint("\n");
+
+ // for( int h = 0; h < bins; h++ )
+ // {
+ // sciprint("%f\n",cdf.at<float>(h,0));
+
+ // }
+
+ float observed_cdf, minval;
+ float minindex;
+
+ for (int i = 0; i < input_image.rows; i++)
+ for (int j = 0; j < input_image.cols; j++) {
+ observed_cdf = cdf.at<float>(image.at<uchar>(i, j), 0);
+
+ minval = 1000; // will be overwritten
+
+ for (int h = 0; h < bins; h++) {
+ if ((abs(refcdf.at<float>(h, 0) - observed_cdf)) < minval) {
+ minval = abs(refcdf.at<float>(h, 0) - observed_cdf);
+ minindex = h;
+ }
+ // sciprint("%d\n",minindex);
+ }
+
+ input_image.at<uchar>(i, j) = minindex;
+ }
+ transpose(input_image, input_image);
+
+ return input_image;
+}
+
+int opencv_imhistmatch(char *fname, unsigned long fname_len) {
+ SciErr sciErr;
+ int intErr = 0;
+
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+
+ double num_bins = 256; // default number of bins for histogram calculation
+
+ // checking input argument
+ CheckInputArgument(pvApiCtx, 2, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the number of input arguments
+ int inputarg = *getNbInputArgument(pvApiCtx);
+
+ // get input matrix
+
+ Mat image, new_image, r, g, b;
+ retrieveImage(image, 1);
+
+ Mat ref;
+ retrieveImage(ref, 2);
+
+ int case1 = 0;
+ if (image.channels() == 1)
+
+ {
+ if (ref.channels() != 1) {
+ sciprint(
+ "If A is a grayscale image, the ref image must also be grayscale\n");
+ return 0;
+
+ } else {
+ case1 = 1;
+ }
+ }
+
+ else if (image.channels() == 3)
+
+ {
+ if (ref.channels() == 1) {
+ case1 = 2;
+ }
+ if (ref.channels() == 3) {
+ case1 = 3;
+ }
+ }
+
+ else {
+ sciprint("Invalid Image\n");
+ return 0;
+ }
+
+ if (!((image.channels() == 3) || (image.channels() == 1))) {
+ sciprint("Invalid Image\n");
+ return 0;
+ }
+
+ if (!((ref.channels() == 3) || (ref.channels() == 1))) {
+ sciprint("Invalid Reference Image\n");
+ return 0;
+ }
+
+ if (inputarg == 3) {
+ // Get the number of bins for histogram calculation
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr3);
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &num_bins);
+ if (sciErr.iErr) {
+ return intErr;
+ }
+
+ if (num_bins < 1) {
+ sciprint("Invalid number of histogram bins\n");
+ return 0;
+ }
+ }
+
+ int bins = (int)num_bins;
+
+ if (case1 == 1) {
+ new_image = match(image, ref, bins);
+
+ }
+
+ else if (case1 == 2) {
+ Mat rgb[3];
+
+ split(image, rgb);
+
+ r = match(rgb[0], ref, bins);
+
+ g = match(rgb[1], ref, bins);
+
+ b = match(rgb[2], ref, bins);
+
+ vector<Mat> channels;
+
+ channels.push_back(r);
+ channels.push_back(g);
+ channels.push_back(b);
+
+ merge(channels, new_image);
+
+ transpose(new_image, new_image);
+
+ }
+
+ else if (case1 == 3) {
+ Mat rgb[3];
+ Mat rgbref[3];
+
+ split(ref, rgbref);
+ split(image, rgb);
+
+ r = match(rgb[0], rgbref[0], bins);
+
+ g = match(rgb[1], rgbref[1], bins);
+
+ b = match(rgb[2], rgbref[2], bins);
+
+ vector<Mat> channels;
+
+ channels.push_back(r);
+ channels.push_back(g);
+ channels.push_back(b);
+
+ merge(channels, new_image);
+
+ transpose(new_image, new_image);
+ }
+
+ // Normalizing the final image
+ cv::normalize(new_image, new_image, 0, 255, NORM_MINMAX, CV_8U);
+
+ // sciprint("\n");
+
+ // for (int i = 0; i < new_image.rows; i++) {
+ // for (int j = 0; j < new_image.cols; j++) {
+ // sciprint(" %i ", new_image.at<uchar>(i,j));
+
+ // }
+
+ // sciprint("\n");
+ // }
+
+ 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_gateway/cpp/opencv_imhmax.cpp b/sci_gateway/cpp/opencv_imhmax.cpp
new file mode 100644
index 0000000..3b1d486
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imhmax.cpp
@@ -0,0 +1,111 @@
+/***************************************************
+Author : Yash S. Bhalgat
+****************************************************
+Usage : transformed_image = imhmax(input_img, threshold, conn);
+ input is a 2-D array
+ conn must be equal to 4 or 8
+***************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <algorithm>
+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_imhmax(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int *piAddr2 = NULL;
+ int *piAddr3 = NULL;
+ int i,j,k;
+ double maximum, minimum;
+ double threshold, conn;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image,1);
+
+ //for value of threshold
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &threshold);
+ if(intErr)
+ return intErr;
+
+ //for value of conn
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &conn);
+ if(intErr)
+ return intErr;
+
+
+ //taking the cases which can lead to an error
+ if(threshold<0)
+ {
+ sciprint("Positive Value Required for threshold. 1 value was used instead");
+ threshold=1;
+ }
+
+ if(conn!=8) conn=8;
+
+ //connectivity taken is 8
+ //main computations
+ Mat transformed_image(image.rows,image.cols,image.type());
+ transformed_image = image;
+
+ for(int x=1; x<image.rows-1; x++){
+ for(int y=1; y<image.cols-1; y++){
+ double myarray[] = {image.at<double>(x-1,y-1),image.at<double>(x,y-1),image.at<double>(x+1,y-1),image.at<double>(x-1,y),image.at<double>(x+1,y),image.at<double>(x-1,y+1),image.at<double>(x,y+1),image.at<double>(x+1,y+1)};
+ maximum = *max_element(myarray, myarray+8);
+ minimum = *min_element(myarray, myarray+8);
+ if(image.at<double>(x,y) >= maximum){
+ if(image.at<double>(x,y)-minimum < threshold) transformed_image.at<double>(x,y) = minimum;
+ }
+ }
+ }
+
+ sciprint("Threshold is: %f", &threshold);
+
+ //returning image
+ string tempstring = type2str(transformed_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,transformed_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_gateway/cpp/opencv_imhmin.cpp b/sci_gateway/cpp/opencv_imhmin.cpp
new file mode 100644
index 0000000..0a87246
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imhmin.cpp
@@ -0,0 +1,96 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = imhmin(input_image, h)
+Example:
+ im = imhmin(image, 80)
+********************************************************/
+
+#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"
+
+ void imhmin_imreconstruct(Mat, Mat, Mat&);
+
+ int opencv_imhmin(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+ double h;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Get the input image from the Scilab environment
+ Mat image;
+ retrieveImage(image, 1);
+
+ // Get the address of 2nd argument, the H-Minima transform scalar
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the H-Minima transform scalar
+ intErr = getScalarDouble(pvApiCtx, piAddr, &h);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ if (h < 0)
+ {
+ sciprint("Please enter a nonnegative scalar for H-minima transform.\n");
+ return 0;
+ }
+
+ Mat gray_image, m, dst;
+ cvtColor(image, gray_image, CV_BGR2GRAY);
+ min((gray_image+h), 255, m);
+ imhmin_imreconstruct(gray_image, m, dst);
+
+ 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;
+
+ }
+ void imhmin_imreconstruct(Mat g, Mat f, Mat& dest)
+ {
+ Mat m0, m1, m;
+ m1 = f;
+ do {
+ m0 = m1.clone();
+ erode(m0, m, Mat());
+ max(g, m, m1);
+ } while(countNonZero(m1 != m0) != 0);
+ dest = m1.clone();
+ }
+
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_imimposemin.cpp b/sci_gateway/cpp/opencv_imimposemin.cpp
new file mode 100644
index 0000000..b610158
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imimposemin.cpp
@@ -0,0 +1,89 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = imimposemin(mask, marker)
+********************************************************/
+
+#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"
+
+ void imimposemin_imreconstruct(Mat, Mat, Mat&);
+
+ int opencv_imimposemin(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr = NULL;
+ int i, j;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Get the input image from the Scilab environment
+ Mat mask, marker;
+ retrieveImage(mask, 1);
+ retrieveImage(marker, 2);
+
+ Mat gray_mask, gray_marker;
+ cvtColor(mask, gray_mask, CV_BGR2GRAY);
+ cvtColor(marker, gray_marker, CV_BGR2GRAY);
+
+ for (i = 0; i < marker.cols; i++)
+ {
+ for (j = 0; j < marker.rows; j++)
+ {
+ if (!(marker.at<uchar>(i,j) == 0 || marker.at<uchar>(i,j) == 1 || marker.at<uchar>(i,j) == 255))
+ {
+ sciprint("Please ensure marker image (second argument) is binary.");
+ return 0;
+ }
+ }
+ }
+
+ Mat m, dst;
+ min((gray_mask + 1), gray_marker, m);
+ imimposemin_imreconstruct(m, gray_marker, dst);
+
+ 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;
+
+ }
+ void imimposemin_imreconstruct(Mat g, Mat f, Mat& dest)
+ {
+ Mat m0, m1, m;
+ m1 = f;
+ do {
+ m0 = m1.clone();
+ erode(m0, m, Mat());
+ max(g, m, m1);
+ } while(countNonZero(m1 != m0) != 0);
+ dest = m1.clone();
+ }
+
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway/cpp/opencv_imlincomb.cpp b/sci_gateway/cpp/opencv_imlincomb.cpp
new file mode 100644
index 0000000..a3d9a9a
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imlincomb.cpp
@@ -0,0 +1,84 @@
+/********************************************************
+Function :imlincomb
+Syntax :C=imlincomb(x1,A1,x2,A2...xn,An)
+ A1...An image matrix,x1...xn double values
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_imlincomb(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ Mat A,B,C,tmp;
+ int* piAddr2=NULL;
+ int* piAddr4=NULL;
+ int iType = 0;
+ int iRet = 0;
+ double value= 0;
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ for(int i=1;i<=Rhs;i=i+2)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,i,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isDoubleType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getScalarDouble(pvApiCtx, piAddr2, &value);
+ }
+ }
+ if(i!=Rhs)
+ {
+ retrieveImage(A,i+1);
+ A.convertTo(A,CV_64F);
+ C=A*value;
+ if((i+1)==2)
+ {
+ C.copyTo(tmp);
+ A.copyTo(B);
+ }
+ else
+ {
+ add(C,tmp,tmp);
+
+ }
+ }
+ else
+ {
+ add(tmp,value,tmp);
+ }
+ A.release();
+ C.release();
+ }
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(tmp.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,tmp,1);
+ free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_immultiply.cpp b/sci_gateway/cpp/opencv_immultiply.cpp
new file mode 100644
index 0000000..ce104a5
--- /dev/null
+++ b/sci_gateway/cpp/opencv_immultiply.cpp
@@ -0,0 +1,71 @@
+/********************************************************
+Function :immultiply
+Syntax :C=immultiply(A,B)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_immultiply(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ Mat A,B,C;
+ int* piAddr2=NULL;
+ int iType = 0;
+ int iRet = 0;
+ double value= 0;
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ retrieveImage(A,1);
+ sciErr =getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ sciErr = getVarType(pvApiCtx, piAddr2, &iType);
+ if(iType==sci_list)
+ {
+ retrieveImage(B,2);
+ Size s1=A.size();
+ Size s2=B.size();
+ if(s1!=s2)
+ {
+ sciprint("\nBoth input should be same size");
+ return 0;
+ }
+ multiply(A,B,C);
+ }
+ else
+ {
+ if(isDoubleType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getScalarDouble(pvApiCtx, piAddr2, &value);
+ }
+ }
+ C=A*value;
+ }
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(C.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,C,1);
+ free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_impixel.cpp b/sci_gateway/cpp/opencv_impixel.cpp
new file mode 100644
index 0000000..464efde
--- /dev/null
+++ b/sci_gateway/cpp/opencv_impixel.cpp
@@ -0,0 +1,122 @@
+/********************************************************
+Function :impixel
+Syntax :C=impixel(A,[1 2 3],[1 2 3])
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_impixel(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr = 0;
+ Mat image;
+ int* piAddr2=NULL;
+ int* piAddr3=NULL;
+ double *value1= 0;
+ double *value2= 0;
+ int iRows1 = 0;
+ int iCols1 = 0;
+ int iRows2 = 0;
+ int iCols2 = 0;
+ double n1,n2;
+ CheckInputArgument(pvApiCtx, 3,3);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ retrieveImage(image,1);
+ //retrieve coordinates
+ sciErr =getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows1, &iCols1,&value1);
+ 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, &iRows2, &iCols2,&value2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if((iRows1!=iRows2)||(iCols1!=iCols2))
+ {
+ sciprint("\n Give proper number of coordinates");
+ return 0;
+ }
+ for(int i=0;i<iRows1;i++)
+ {
+ for(int j=0;j<iCols1;j++)
+ {
+ n1=value1[i + iRows1 * j];
+ if(n1!=round(n1)||n1<=0)
+ {
+ sciprint("The value of coordinates must be integer\n");
+ return 0;
+ }
+ }
+ }
+ for(int i=0;i<iRows2;i++)
+ {
+ for(int j=0;j<iCols2;j++)
+ {
+ n2=value2[i + iRows2 * j];
+ if(n2!=round(n2)||n2<=0)
+ {
+ sciprint("The value of coordinates must be integer\n");
+ return 0;
+ }
+ }
+ }
+ int m=0;
+ double* output=NULL;
+ output=( double *)malloc(sizeof(double)*iCols1*3);
+ for(int i=0;i<iRows1;i++)
+ {
+ for(int j=0;j<iCols1;j++)
+ {
+ Vec3b intensity = image.at<Vec3b>(value1[j-1],value2[j-1]);
+ float R= intensity.val[2];
+ float G= intensity.val[1];
+ float B= intensity.val[0];
+ output[m]=R;
+ output[m+1]=G;
+ output[m+2]=B;
+ m=m+3;
+ }
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,3,iCols1,output);
+ free(output); // Data have been copied into Scilab memory
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_impyramid.cpp b/sci_gateway/cpp/opencv_impyramid.cpp
new file mode 100644
index 0000000..ecd0f7c
--- /dev/null
+++ b/sci_gateway/cpp/opencv_impyramid.cpp
@@ -0,0 +1,103 @@
+/********************************************************
+Function :impyramid
+Syntax :B=impyramid(A,direction)
+*direction :expand or reduce
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_impyramid(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr2=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j,k=0,l=0;
+ int error;
+ String s;
+ int iRet = 0;
+ char* pstData = NULL;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image;
+ retrieveImage(image, 1);
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2,&piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isStringType(pvApiCtx, piAddr3))
+ {
+ if(isScalar(pvApiCtx, piAddr3))
+ {
+
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr3, &pstData);
+ }
+ }
+
+
+ k=image.rows;
+ l=image.cols;
+ Mat new_image;
+ if(strcmp(pstData,"expand")==0)
+ {
+ Size size((k*2)-1,(l*2)-1);
+ resize(image,new_image,size);
+ }
+ else if(strcmp(pstData,"reduce")==0)
+ {
+ Size size(k/2,l/2);
+ resize(image,new_image,size);
+ }
+ else
+ {
+ sciprint("Not valid 2nd argument");
+ }
+
+
+
+ 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_gateway/cpp/opencv_imread.cpp b/sci_gateway/cpp/opencv_imread.cpp
new file mode 100644
index 0000000..6e7e7b9
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_imrect.cpp b/sci_gateway/cpp/opencv_imrect.cpp
new file mode 100644
index 0000000..d19f58e
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imrect.cpp
@@ -0,0 +1,110 @@
+/********************************************************
+Author: Dhruti Shah
+********************************************************
+Usage: return_image = imrect(input_image, x_list, y_list)
+Example:
+ im = imrect(image, [x1 x2], [y1 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_imrect(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRowsR=0,iColsR=0,iColsC=0,iRowsC=0;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ double *pstDataY = NULL;
+ double *pstDataX = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Get the input image from the Scilab environment
+ Mat image;
+ retrieveImage(image, 1);
+
+ // Get the address of 2nd argument, the x-coordinate list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the address of the 3rd agument, the y-coordinate list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the x-coordinate list in the form of a matrix
+ // No. of columns = 2
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRowsC, &iColsC, &pstDataX);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the y-coordinate list in the form of a matrix
+ // No. of columns = 2
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRowsR, &iColsR, &pstDataY);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ Point points[1][2];
+
+ for (int i = 0; i < 2 ; i++)
+ {
+ if (pstDataY[i] < 0 || pstDataX[i] < 0)
+ {
+ sciprint("Coordinates cannot be negative.\n");
+ return 0;
+ }
+ else
+ points[0][i] = Point(pstDataX[i], pstDataY[i]);
+ }
+
+ rectangle(image,points[0][0],points[0][1],Scalar(0,0,0),2);
+
+ 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;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway/cpp/opencv_imresize.cpp b/sci_gateway/cpp/opencv_imresize.cpp
new file mode 100644
index 0000000..190ab5e
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_imrotate.cpp b/sci_gateway/cpp/opencv_imrotate.cpp
new file mode 100644
index 0000000..074101c
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imrotate.cpp
@@ -0,0 +1,81 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : rotated_image=imrotate(sourcrimage,angle); */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int opencv_imrotate(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double pstData;
+ int* pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ int error;
+ //function to check number of input variable
+ CheckInputArgument(pvApiCtx, 2, 2);
+ //function to check number of output variable
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ // get Address of first input
+ Mat img;
+ retrieveImage(img,1);
+ //second argument
+ //fetching address of second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch second argument i.e angle
+ error=getScalarDouble(pvApiCtx,piAddr2,&pstData);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //creating distination matrix
+ Mat dst;
+ //following set of functions for image rotation
+ Point2f pt((img.cols)/2., (img.rows)/2.);
+ Mat r1 = getRotationMatrix2D(pt, pstData, 1.0);
+ warpAffine(img, dst, r1, Size(dst.cols, dst.rows));
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ string tempstring = type2str(dst.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ //returning output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+
+ }
+}
diff --git a/sci_gateway/cpp/opencv_imrotate.cpp~ b/sci_gateway/cpp/opencv_imrotate.cpp~
new file mode 100644
index 0000000..a2b0e54
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imrotate.cpp~
@@ -0,0 +1,81 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : rotated_image=imrotate(sourcrimage,angle); */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int imrotate(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double pstData;
+ int* pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ int error;
+ //function to check number of input variable
+ CheckInputArgument(pvApiCtx, 2, 2);
+ //function to check number of output variable
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ // get Address of first input
+ Mat img;
+ retrieveImage(img,1);
+ //second argument
+ //fetching address of second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch second argument i.e angle
+ error=getScalarDouble(pvApiCtx,piAddr2,&pstData);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //creating distination matrix
+ Mat dst;
+ //following set of functions for image rotation
+ Point2f pt((img.cols)/2., (img.rows)/2.);
+ Mat r1 = getRotationMatrix2D(pt, pstData, 1.0);
+ warpAffine(img, dst, r1, Size(dst.cols, dst.rows));
+ //Since we need to pass a single pointer as an arguement, for a 2-D matrix, we define it in this manner
+ string tempstring = type2str(dst.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ //returning output arguments
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+
+ }
+}
diff --git a/sci_gateway/cpp/opencv_imsharpen.cpp b/sci_gateway/cpp/opencv_imsharpen.cpp
new file mode 100644
index 0000000..ad0a593
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_imshowpair.cpp b/sci_gateway/cpp/opencv_imshowpair.cpp
new file mode 100644
index 0000000..7feb00a
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imshowpair.cpp
@@ -0,0 +1,474 @@
+/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+Created By: Riddhish Bhalodia
+Date: 30th September 2015
+
+Usage:
+
+imshowpair(Mat image1,Mat image2,String method,String scaling)
+
+1) image1 : Input image1
+2) image2 : Input image2
+3) method : Method for the type of display
+
+ | Method | Function |
+ | | |
+ | "montage" | Display Images side by side |
+ | "blend" | Display the blend of two Images alpha=0.5 |
+ | "diff" | Display the absolute difference between Images |
+ | "falsecolor" | Display image1 by green channel and image2 by red |
+
+4) scaling : The scaling of the images
+
+ | Scaling | Function |
+ | | |
+ | "none" | No scaling to the images |
+ | "joint" | Scale the joint images |
+ | "independent" | Scale the images independently before processing |
+
+
+
+*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+
+#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_imshowpair(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 *piLen1 = NULL;
+ int *piLen2 = NULL;
+ char **method = NULL;
+ char **scaling = NULL;
+
+ Mat image1,image2;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 4, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ retrieveImage(image1, 1);
+ retrieveImage(image2, 2);
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &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;
+ }
+ piLen1 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen1, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ method = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ method[i] = (char*)malloc(sizeof(char) * (piLen1[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr2, &iRows, &iCols, piLen1, method);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // now the fourth argument which is aging a string
+
+ sciErr = getVarAddressFromPosition(pvApiCtx, 4, &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;
+ }
+ piLen2 = (int*)malloc(sizeof(int) * iRows * iCols);
+ //second call to retrieve length of each string
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen2, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ scaling = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ scaling[i] = (char*)malloc(sizeof(char) * (piLen2[i] + 1));//+ 1 for null termination
+
+ //third call to retrieve data
+ sciErr = getMatrixOfString(pvApiCtx, piAddr3, &iRows, &iCols, piLen2, scaling);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ char x1[15] = "montage";
+ char x2[15] = "diff";
+ char x3[15] = "blend";
+ char x4[15] = "falsecolor";
+ char y1[15] = "joint";
+ char y2[15] = "independent";
+ char y3[15] = "none";
+ // Error check on method
+ if(!(strcmp(method[0],x1)==0 || strcmp(method[0],x2)==0 || strcmp(method[0],x3)==0 || strcmp(method[0],x4)==0 )){
+ sciprint("Method input not correct, choose from 'blend','diff','montage' or 'falsecolor' \n");
+ return 0;
+ }
+ // Error check on scaling
+
+ if(!(strcmp(scaling[0],y1)==0 || strcmp(scaling[0],y2)==0 || strcmp(scaling[0],y3)==0 )){
+ sciprint("Method input not correct, choose from 'none','diff','montage' or 'falsecolor' \n");
+ return 0;
+ }
+
+ int max_rows,max_cols;
+ Mat out;
+ max_rows = max(image1.rows,image2.rows);
+ max_cols = max(image1.cols,image2.cols);
+ if(image1.channels() == 1){ cvtColor(image1,image1,CV_BGR2GRAY);}
+ if(image2.channels() == 1){ cvtColor(image2,image2,CV_BGR2GRAY);}
+
+ vector<Mat> rgbChannels(3);
+ // for montage and no scaling plus joint scaling
+
+ if(strcmp(method[0],x1)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+ out = Mat::zeros(max_rows,2*max_cols,image1.type());
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j + max_cols)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j + max_cols)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j + max_cols)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+ }
+ // for montage and scaling independent
+ if(strcmp(method[0],x1)==0 && strcmp(scaling[0],y2)==0) {
+
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+
+ out = Mat::zeros(max_rows,2*max_cols,image1.type());
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j + max_cols)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j + max_cols)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j + max_cols)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+ }
+
+ // for diff and no scaling plus joint scaling
+ if(strcmp(method[0],x2)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+
+ // cvtColor(image1,image1,CV_BGR2GRAY);
+ // cvtColor(image2,image2,CV_BGR2GRAY);
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = abs((image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2]) - (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2]))/3;
+ out.at<Vec3b>(i,j)[1] = abs((image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2]) - (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2]))/3;
+ out.at<Vec3b>(i,j)[2] = abs((image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2]) - (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2]))/3;
+ }
+ }
+ }
+ // for diff and independent scaling
+ if(strcmp(method[0],x2)==0 && strcmp(scaling[0],y2)==0) {
+
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+
+ // cvtColor(image1,image1,CV_BGR2GRAY);
+ // cvtColor(image2,image2,CV_BGR2GRAY);
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = abs(image1.at<Vec3b>(i,j)[0] - image2.at<Vec3b>(i,j)[0]);
+ out.at<Vec3b>(i,j)[1] = abs(image1.at<Vec3b>(i,j)[1] - image2.at<Vec3b>(i,j)[1]);
+ out.at<Vec3b>(i,j)[2] = abs(image1.at<Vec3b>(i,j)[2] - image2.at<Vec3b>(i,j)[2]);
+ }
+ }
+ }
+
+ // for blend and no scaling[0] plus joint scaling[0]
+ if(strcmp(method[0],x3)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = 0.5*(image1.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[0]);
+ out.at<Vec3b>(i,j)[1] = 0.5*(image1.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[1]);
+ out.at<Vec3b>(i,j)[2] = 0.5*(image1.at<Vec3b>(i,j)[2] + image2.at<Vec3b>(i,j)[2]);
+ }
+ }
+
+ }
+ // for blend and independent scaling[0]
+ if(strcmp(method[0],x3)==0 && strcmp(scaling[0],y2)==0) {
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image1.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image1.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image1.at<Vec3b>(i,j)[2];
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = image2.at<Vec3b>(i,j)[0];
+ out.at<Vec3b>(i,j)[1] = image2.at<Vec3b>(i,j)[1];
+ out.at<Vec3b>(i,j)[2] = image2.at<Vec3b>(i,j)[2];
+ }
+ }
+
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ out.at<Vec3b>(i,j)[0] = 0.5*(image1.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[0]);
+ out.at<Vec3b>(i,j)[1] = 0.5*(image1.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[1]);
+ out.at<Vec3b>(i,j)[2] = 0.5*(image1.at<Vec3b>(i,j)[2] + image2.at<Vec3b>(i,j)[2]);
+ }
+ }
+
+ }
+
+ // for falsecolor and no scaling[0] plus joint scaling[0]
+ if(strcmp(method[0],x4)==0 && ((strcmp(scaling[0],y1)==0)||(strcmp(scaling[0],y3)==0))) {
+
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+
+ // image 1 green image2 red
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = 0;
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = 0;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ if(image1.at<Vec3b>(i,j) == image2.at<Vec3b>(i,j)){
+ out.at<Vec3b>(i,j)[0] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ else{
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+
+ }
+ }
+
+ }
+ // for falsecolor and independent scaling[0]
+ if(strcmp(method[0],x4)==0 && strcmp(scaling[0],y2)==0) {
+ out = Mat::zeros(max_rows,max_cols,image1.type());
+ //scale image 1 and image 2
+
+ split(image1, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image1);
+ split(image2, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,image2);
+ // image 1 green image2 red
+ for(int i=0;i<image1.rows;i++){
+ for(int j=0;j<image1.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = 0;
+ }
+ }
+ for(int i=0;i<image2.rows;i++){
+ for(int j=0;j<image2.cols;j++){
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = 0;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ }
+ for(int i=0;i<min(image1.rows,image2.rows);i++){
+ for(int j=0;j<min(image1.cols,image2.cols);j++){
+ if(image1.at<Vec3b>(i,j) == image2.at<Vec3b>(i,j)){
+ out.at<Vec3b>(i,j)[0] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[1] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+ else{
+ out.at<Vec3b>(i,j)[0] = 0;
+ out.at<Vec3b>(i,j)[1] = (image1.at<Vec3b>(i,j)[0] + image1.at<Vec3b>(i,j)[1] + image1.at<Vec3b>(i,j)[2])/3;
+ out.at<Vec3b>(i,j)[2] = (image2.at<Vec3b>(i,j)[0] + image2.at<Vec3b>(i,j)[1] + image2.at<Vec3b>(i,j)[2])/3;
+ }
+
+ }
+ }
+
+ }
+
+ // for joint scaling[0]
+ if(strcmp(scaling[0],y3)==0){
+ split(out, rgbChannels);
+ normalize(rgbChannels[0],rgbChannels[0],0,255,CV_MINMAX);
+ normalize(rgbChannels[1],rgbChannels[1],0,255,CV_MINMAX);
+ normalize(rgbChannels[2],rgbChannels[2],0,255,CV_MINMAX);
+ merge(rgbChannels,out);
+ }
+
+ if(image1.channels()==1 && image2.channels()==1){
+ cvtColor(out,out,CV_BGR2GRAY);
+ }
+
+ // out is the return image
+ namedWindow("Output",CV_WINDOW_AUTOSIZE);
+ imshow("Output",out);
+ // waitKey(0);
+ 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);
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+} \ No newline at end of file
diff --git a/sci_gateway/cpp/opencv_imsubtract.cpp b/sci_gateway/cpp/opencv_imsubtract.cpp
new file mode 100644
index 0000000..1d7f3bd
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imsubtract.cpp
@@ -0,0 +1,71 @@
+/********************************************************
+Function :imsubtract
+Syntax :C=imsubtract(A,B)
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_imsubtract(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ Mat A,B,C;
+ int* piAddr2=NULL;
+ int iType = 0;
+ int iRet = 0;
+ double value= 0;
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ retrieveImage(A,1);
+ sciErr =getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ sciErr = getVarType(pvApiCtx, piAddr2, &iType);
+ if(iType==sci_list)
+ {
+ retrieveImage(B,2);
+ Size s1=A.size();
+ Size s2=B.size();
+ if(s1!=s2)
+ {
+ sciprint("\nBoth input should be same size");
+ return 0;
+ }
+ subtract(A,B,C);
+ }
+ else
+ {
+ if(isDoubleType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getScalarDouble(pvApiCtx, piAddr2, &value);
+ }
+ }
+ subtract(A,value,C);
+ }
+
+ int temp = nbInputArgument(pvApiCtx) + 1;
+ string tempstring = type2str(C.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,C,1);
+ free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_imwarp.cpp b/sci_gateway/cpp/opencv_imwarp.cpp
new file mode 100644
index 0000000..d5bc6df
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imwarp.cpp
@@ -0,0 +1,104 @@
+/********************************************************
+ Author: V Srinivas
+*********************************************************
+ imwarp(image,matrix(2*3))=output.
+********************************************************/
+
+#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_imwarp(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int intErr=0;
+ int iRows=0,iCols=0;
+ int *piAddr1 = NULL;
+ //int *piAddr2 = NULL;
+ double *tform;
+ int maxx,maxy,minx,miny;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);//two arguments 1 takes the image and the other takes the transformation matrix
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //retieve Image
+ Mat image;
+ retrieveImage(image,1);
+ //retreive the transformation matrix
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr1);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return -1;
+ }
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols,&tform);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return -1;
+ }
+ if(iRows!=2 || iCols!=3)//checking if the transformation matrix is of the desired size
+ {
+ sciprint("Please enter a valid transformation matrix");
+ return -1;
+ }
+ Mat dst;
+ //This and the next few lines are dedicated to finding the size of the frame in which the whole transformed image can be viewed.
+ double x [4]={0,0,image.cols-1,image.cols-1};
+ double y [4]={0,image.rows-1,0,image.rows-1};
+ int modx[4];
+ int mody[4];
+ for(int i=0;i<4;i++)// the modifications performed by the matrix is performed on the edges of the image to find the optimum size. This works as the transformation is linear so the edges always are on the extreme points.
+ {
+ modx[i]=(int)(tform[0] * x[i] + tform[1] * y[i] + tform[4]);
+ mody[i]=(int)(tform[2] * x[i] + tform[3] * y[i] + tform[5]);
+ //cout<<*(modx+i)<<" "<<*(mody+i)<<endl;
+ }
+ Mat trans=(Mat_<double>(2,3)<<tform[0],tform[1],tform[4],tform[2],tform[3],tform[5]);//creating a matrix of type Mat.
+ minx=modx[0];maxx=modx[0];miny=mody[0];maxy=mody[0];
+ for(int i=0;i<4;i++)//used to find the maximum and minimum of image coordinates.
+ {
+ if(modx[i]<minx)
+ {minx=modx[i];}
+ if(modx[i]>maxx)
+ {maxx=modx[i];}
+ if(mody[i]<miny)
+ {miny=mody[i];}
+ if(mody[i]>maxy)
+ {maxy=mody[i];}
+ }
+ warpAffine(image,dst,trans,Size(maxx-minx,maxy-miny));
+ 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_gateway/cpp/opencv_imwrite.cpp b/sci_gateway/cpp/opencv_imwrite.cpp
new file mode 100644
index 0000000..2815ac9
--- /dev/null
+++ b/sci_gateway/cpp/opencv_imwrite.cpp
@@ -0,0 +1,85 @@
+/********************************************************
+Author: Sukul Bagai
+********************************************************/
+
+#include <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_gateway/cpp/opencv_ind2gray.cpp b/sci_gateway/cpp/opencv_ind2gray.cpp
new file mode 100644
index 0000000..60c45ba
--- /dev/null
+++ b/sci_gateway/cpp/opencv_ind2gray.cpp
@@ -0,0 +1,115 @@
+/********************************************************
+Author: Vinay
+
+Function: ind2gray(image, colormap)
+********************************************************/
+
+#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_ind2gray(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int cRows=0,cCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image, imgcpy;
+ retrieveImage(image, 1);
+ string tempstring = type2str(image.type());
+ char *imtype;
+ imtype = (char *)malloc(tempstring.size() + 1);
+ memcpy(imtype, tempstring.c_str(), tempstring.size() + 1);
+ bool integer = true;
+ int scale = 1;
+ double error = 0;
+
+ if (strcmp(imtype,"8U")==0) {
+ integer = true;
+ scale = 255;
+ error = 0.5;
+ }
+ else if (strcmp(imtype,"16U")==0) {
+ integer = true;
+ scale = 65535;
+ error = 0.5;
+ }
+ else if (strcmp(imtype,"32F")==0 || strcmp(imtype,"64F")==0) {
+ integer = false;
+ scale = 1;
+ error = 0;
+ }
+ else {
+ sciprint("Invalid image");
+ return 0;
+ }
+ iRows = image.rows;
+ iCols = image.cols;
+ image.convertTo(imgcpy, CV_64F);
+
+ Mat cmap, cmapcpy;
+ retrieveImage(cmap, 2);
+ cRows = cmap.rows;
+ cCols = cmap.cols;
+ cmap.convertTo(cmapcpy, CV_64F);
+
+ for (int i=0; i<cRows; i++) {
+ for (int j=0; j<cCols; j++) {
+ if (cmapcpy.at<double>(i,j)<0 || cmapcpy.at<double>(i,j)>1) {
+ sciprint("Invalid colormap");
+ return 0;
+ }
+ }
+ }
+
+ Mat gray = Mat::zeros(image.size(), CV_64F);
+
+
+ for (int i=0; i<iRows; i++) {
+ for (int j=0; j<iCols; j++) {
+ unsigned int temp = (unsigned int)imgcpy.at<double>(i, j);
+ if (temp >= cRows) {
+ temp = cRows - 1;
+ }
+ if (!integer) {
+ if (temp!=0) {temp-=1;}
+ }
+ gray.at<double>(i,j) = (0.2989 * cmapcpy.at<double>(temp, 0) + 0.5870 * cmapcpy.at<double>(temp, 1) + 0.1140 * cmapcpy.at<double>(temp, 2)) ;
+
+ }
+ }
+
+ Mat grayimage;
+ gray.convertTo(grayimage, image.type(), scale, error);
+ returnImage(imtype,grayimage,1);
+ free(imtype);
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ //Returning the Output Variables as arguments to the Scilab environment
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_ind2rgb.cpp b/sci_gateway/cpp/opencv_ind2rgb.cpp
new file mode 100644
index 0000000..872cbfb
--- /dev/null
+++ b/sci_gateway/cpp/opencv_ind2rgb.cpp
@@ -0,0 +1,146 @@
+/********************************************************
+Author: Vinay
+
+Function: ind2rgb(image, colormap)
+********************************************************/
+
+#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_ind2rgb(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRows=0,iCols=0;
+ int cRows=0,cCols=0;
+ int *piAddr = NULL;
+ int *piAddrNew = NULL;
+ int *piAddr2 = NULL;
+ //unsigned short int *image = NULL;
+ double *map = NULL;
+ int i,j,k;
+ double x, y, width, height;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ Mat image, imgcpy;
+ retrieveImage(image, 1);
+ string tempstring = type2str(image.type());
+ char *imtype;
+ imtype = (char *)malloc(tempstring.size() + 1);
+ memcpy(imtype, tempstring.c_str(), tempstring.size() + 1);
+ bool integer;
+
+ if (strcmp(imtype,"8U")==0 || strcmp(imtype,"16U")==0) {
+ integer = true;
+ }
+ else if (strcmp(imtype,"32F")==0 || strcmp(imtype,"64F")==0) {
+ integer = false;
+ }
+ else {
+ sciprint("Invalid image");
+ return 0;
+ }
+ iRows = image.rows;
+ iCols = image.cols;
+ image.convertTo(imgcpy, CV_64F);
+
+ Mat cmap, cmapcpy;
+ retrieveImage(cmap, 2);
+ cRows = cmap.rows;
+ cCols = cmap.cols;
+ cmap.convertTo(cmapcpy, CV_64F);
+
+ for (int i=0; i<cRows; i++) {
+ for (int j=0; j<cCols; j++) {
+ if (cmapcpy.at<double>(i,j)<0 || cmapcpy.at<double>(i,j)>1) {
+ sciprint("Invalid colormap");
+ return 0;
+ }
+ }
+ }
+
+
+ double *r,*g,*b;
+ r=(double *)malloc(sizeof(double)*iRows*iCols);
+ g=(double *)malloc(sizeof(double)*iRows*iCols);
+ b=(double *)malloc(sizeof(double)*iRows*iCols);
+ int m = 0;
+
+
+ for (int i=0; i<iRows; i++) {
+ for (int j=0; j<iCols; j++) {
+ unsigned int temp = (unsigned int)imgcpy.at<double>(i, j);
+ if (temp >= cRows) {
+ temp = cRows - 1;
+ }
+ if (!integer) {
+ if (temp!=0) {temp-=1;}
+ }
+ r[i + iRows*j] = cmapcpy.at<double>(temp, 0);
+ g[i + iRows*j] = cmapcpy.at<double>(temp, 1);
+ b[i + iRows*j] = cmapcpy.at<double>(temp, 2);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1,iRows, iCols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2,iCols, iRows, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iCols, iRows, b);
+ free(b);
+ 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_gateway/cpp/opencv_integralImage.cpp b/sci_gateway/cpp/opencv_integralImage.cpp
new file mode 100644
index 0000000..46e0082
--- /dev/null
+++ b/sci_gateway/cpp/opencv_integralImage.cpp
@@ -0,0 +1,145 @@
+/*
+ * integralImage
+ *
+ * integralImage in scilab
+ *
+ */
+
+// Created by Samiran Roy, mail: samiranroy@cse.iitb.ac.in
+// An implementation of integralImage method of matlab
+// Usage:
+// integralImage(I) : Calculate the integral image of I, I must be grayscale
+
+// method : 'upright' (default)
+// method : 'rotated' The area sums are calulated over a rectangle, which is rotated 45 degrees
+
+
+// Known Changes from Matlab:
+/*
+ * 1) None, as of now
+ */
+
+#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_integralImage(char *fname, unsigned long fname_len) {
+ SciErr sciErr;
+ int intErr = 0;
+
+
+ int *piAddr1 = NULL;
+
+ int error;
+
+// String holding the second argument
+ int iRet = 0;
+ char* pstData = NULL;
+
+// Checking input argument
+ CheckInputArgument(pvApiCtx, 1, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+// Get input image
+
+ Mat image;
+ retrieveImage(image, 1);
+
+
+
+ for (int i = 0; i < image.rows; i++) {
+ for (int j = 0; j < image.cols; j++) {
+ sciprint("%f ", image.at<double>(i,j));
+
+ }
+
+ sciprint("\n");
+ }
+
+// Error Checks
+
+ if (image.channels() > 1) {
+ sciprint("The image must be grayscale.");
+ return 0;
+ }
+
+// Output variables holding integralImage, squared integralImage, integralImage over rectangle rotated by 45 degrees
+ Mat new_image, integralimage, squaredimage, rotatedimage;
+
+ integral(image, integralimage, squaredimage, rotatedimage, -1);
+
+// Get the number of input arguments
+ int inputarg = *getNbInputArgument(pvApiCtx);
+
+ if (inputarg == 1)
+ integralimage.copyTo(new_image);
+
+ if (inputarg == 2)
+
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr1);
+
+ if (sciErr.iErr) {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (isStringType(pvApiCtx, piAddr1)) {
+ if (isScalar(pvApiCtx, piAddr1)) {
+
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr1, &pstData);
+ }
+ }
+ if (strcmp(pstData, "rotated") == 0) {
+ rotatedimage.copyTo(new_image);
+ } else if (strcmp(pstData, "upright") == 0) {
+ integralimage.copyTo(new_image);
+ } else {
+ sciprint("Unknown Parameter Name:%s\n", pstData);
+
+ }
+
+ }
+
+ // sciprint("\n");
+
+ // for (int i = 0; i < new_image.rows; i++) {
+ // for (int j = 0; j < new_image.cols; j++) {
+ // sciprint("%f ", new_image.at<double>(i,j));
+
+ // }
+
+ // sciprint("\n");
+ // }
+
+ // new_image is sent to scilab as output
+
+ 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_gateway/cpp/opencv_lab2double.cpp b/sci_gateway/cpp/opencv_lab2double.cpp
new file mode 100644
index 0000000..c4eeeb3
--- /dev/null
+++ b/sci_gateway/cpp/opencv_lab2double.cpp
@@ -0,0 +1,130 @@
+/*--------------------------------------
+ function-lab2double
+ Author :Tess Zacharias
+------------------------------------- */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+ int opencv_lab2double(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int iRows = 0;
+ int iCols = 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ int i,j;
+ int error;
+ float L,a,b;
+ int *piAddrNew = NULL;
+ CheckOutputArgument(pvApiCtx,1,1);
+ int k=0;
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 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 = getMatrixOfDoubleInList(pvApiCtx, piAddr, 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 = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*iRows*iCols);
+ g1=(double *)malloc(sizeof(double)*iRows*iCols);
+ b1=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ L= (pstDataR[k]);
+ a= (pstDataG[k]);
+ b= (pstDataB[k++]);
+ r1[m]=L;
+ g1[m]=a;
+ b1[m++]=b;
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
+
diff --git a/sci_gateway/cpp/opencv_lab2rgb.cpp b/sci_gateway/cpp/opencv_lab2rgb.cpp
new file mode 100644
index 0000000..5de6b2d
--- /dev/null
+++ b/sci_gateway/cpp/opencv_lab2rgb.cpp
@@ -0,0 +1,331 @@
+/* ==================================================================== */
+/* Author :Tess Zacharias */
+/* ==================================================================== */
+/* overloaded function */
+/* Syntax : return_matrix_3_xyz_values=lab2xyz(matrix_of_3_labvalues a) */
+/* Syntax : return_matrix_3_xyz_values=lab2xyz(matrix_of_3_labvalues a,String1 Name,String2 value) */
+/* ==================================================================== */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ // #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+#define REF_Y 1.00000;
+#define REF_Z 1.08883;
+
+struct Color
+{
+ float R,G,B,X,Y,Z,L,a,b;
+};
+
+Color lab2rgb1(float L, float a, float b)
+{
+
+
+ float y = (L + 16) / 116;
+ float x = a / 500 + y;
+ float z = y - b / 200;
+ if ( pow( y , 3 ) > 0.008856 )
+ {
+ y = pow( y , 3 );
+ }
+ else
+ {
+ y = ( y - 16 / 116 ) / 7.787;
+ }
+ if ( pow( x , 3 ) > 0.008856 )
+ {
+ x = pow( x , 3 );
+ }
+ else
+ {
+ x = ( x - 16 / 116 ) / 7.787;
+ }
+ if ( pow( z , 3 ) > 0.008856 )
+ {
+ z = pow( z , 3 );
+ }
+ else
+ {
+ z = ( z - 16 / 116 ) / 7.787;
+ }
+ float X= x *REF_X;
+ float Y= y *REF_Y;
+ float Z = z *REF_Z;
+ //X = X/100.f; //R 0..1
+ //Y= Y/100.f; //G 0..1
+ //Z= Z/100.f; //B 0..1
+ float R1=3.240479*X-1.537150*Y -0.498535 *Z;
+ float G1=-0.969256*X+1.875992 *Y+0.041556* Z;
+ float B1=0.055648*X-0.204043*Y +1.057311*Z;
+ if( R1 > 0.0031308 )
+ R1 = 1.055 * ( pow( R1, 1./2.4 ) ) - 0.055;
+ else
+ R1 = 12.92 * R1;
+ if( G1 > 0.0031308 )
+ G1 = 1.055 * ( pow( G1, 1./2.4 ) ) - 0.055;
+ else
+ G1 = 12.92 * G1;
+ if( B1 > 0.0031308 )
+ B1 = 1.055 * ( pow( B1, 1./2.4 ) ) - 0.055;
+ else
+ B1 = 12.92 * B1;
+
+
+ Color rgb;
+ rgb.R= R1;
+ rgb.G= G1;
+ rgb.B= B1;
+ return rgb;
+
+}
+ Color lab2rgb2(float L, float a, float b,char *s)
+{
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(!strcmp(s,"a"))
+ {
+ REF_X1=1.0985;
+ REF_Y1= 1.0000;
+ REF_Z1=0.3558;
+ }
+ else if(!strcmp(s,"c"))
+ {
+ REF_X1=0.9807;
+ REF_Y1= 1.0000;
+ REF_Z1=1.1822;
+ }
+ else if(!strcmp(s,"d50"))
+ {
+ REF_X1=0.9642;
+ REF_Y1= 1.0000;
+ REF_Z1=0.8251;
+ }
+ else if(!strcmp(s,"d65"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(!strcmp(s,"icc"))
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ else if(!strcmp(s,"e"))
+ {
+ REF_X1=1.000;
+ REF_Y1=1.000;
+ REF_Z1=1.000;
+ }
+
+ float y = (L + 16) / 116;
+ float x = a / 500 + y;
+ float z = y - b / 200;
+ if ( pow( y , 3 ) > 0.008856 )
+ {
+ y = pow( y , 3 );
+ }
+ else
+ {
+ y = ( y - 16 / 116 ) / 7.787;
+ }
+ if ( pow( x , 3 ) > 0.008856 )
+ {
+ x = pow( x , 3 );
+ }
+ else
+ {
+ x = ( x - 16 / 116 ) / 7.787;
+ }
+ if ( pow( z , 3 ) > 0.008856 )
+ {
+ z = pow( z , 3 );
+ }
+ else
+ {
+ z = ( z - 16 / 116 ) / 7.787;
+ }
+ float X= x *REF_X;
+ float Y= y *REF_Y;
+ float Z = z *REF_Z;
+ X = X/100.f; //R 0..1
+ Y= Y/100.f; //G 0..1
+ Z= Z/100.f; //B 0..1
+ float R1=3.240479*X-1.537150*Y -0.498535 *Z;
+ float G1=-0.969256*X+1.875992 *Y+0.041556* Z;
+ float B1=0.055648*X-0.204043*Y +1.057311*Z;
+ if( R1 > 0.0031308 )
+ R1 = 1.055 * ( pow( R1, 1./2.4 ) ) - 0.055;
+ else
+ R1 = 12.92 * R1;
+ if( G1 > 0.0031308 )
+ G1 = 1.055 * ( pow( G1, 1./2.4 ) ) - 0.055;
+ else
+ G1 = 12.92 * G1;
+ if( B1 > 0.0031308 )
+ B1 = 1.055 * ( pow( B1, 1./2.4 ) ) - 0.055;
+ else
+ B1 = 12.92 * B1;
+
+
+ Color rgb;
+ rgb.R= R1*100;
+ rgb.G= G1*100;
+ rgb.B= B1*100;
+ return rgb;
+
+}
+ int opencv_lab2rgb(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img,dst;
+ float L,a,b;
+ int *piAddrNew = NULL;
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //checking if number of input arguments are 3
+
+ int k=0;
+ // SciErr getMatrixOfDoubleInList(void* _pvCtx, int* _piParent, int _iItemPos, int* _piRows, int* _piCols, double** _pdblReal)
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*iRows*iCols);
+ g1=(double *)malloc(sizeof(double)*iRows*iCols);
+ b1=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ // Vec3d intensity = img.at<Vec3d>(i,j);
+ L= (pstDataR[k]);
+ a= (pstDataG[k]);
+ b= (pstDataB[k++]);
+ out=lab2rgb1(L,a,b);
+ //cout<<R<<"\n";
+ //cout<<G<<"\n";
+ //cout<<B<<"\n";
+ r1[m]=(out.R);
+ g1[m]=(out.G);
+ b1[m++]=(out.B);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_lab2uint16.cpp b/sci_gateway/cpp/opencv_lab2uint16.cpp
new file mode 100644
index 0000000..b14d147
--- /dev/null
+++ b/sci_gateway/cpp/opencv_lab2uint16.cpp
@@ -0,0 +1,151 @@
+/*--------------------------------------
+ function-lab2uint16
+ Author :Tess Zacharias
+------------------------------------- */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ struct Color
+ {
+ float R,G,B,L,a,b;
+ };
+ Color lab2uint16(float L, float a, float b)
+ {
+ /* lab to uint16 conversion */
+ float R1=round((65535 * L) / (100 + (25500/65280)));
+ float G1=round(65535 * ((128 + a) / (255 + (255/256))));
+ float B1=round(65535 * ((128 + b) / (255 + (255/256))));
+ if((R1<0)||(R1>65535))
+ R1=65535;
+ if((G1<0)||(G1>65535))
+ G1=65535;
+ if((B1<0)||(B1>65535))
+ B1=65535;
+ Color rgb;
+ rgb.R= (R1-142);
+ rgb.G = (G1-142);
+ rgb.B = (B1-142);
+ return rgb;
+ }
+ int opencv_lab2uint16(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int iRows= 0;
+ int iCols= 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ int i,j;
+ int error;
+ Color out;
+ float L,a,b;
+ int *piAddrNew = NULL;
+ CheckOutputArgument(pvApiCtx,1,1);
+ int k=0;
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 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 = getMatrixOfDoubleInList(pvApiCtx, piAddr, 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 = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ unsigned short *r1,*g1,*b1;
+ r1=(unsigned short *)malloc(sizeof(unsigned short )*iRows*iCols);
+ g1=(unsigned short *)malloc(sizeof(unsigned short )*iRows*iCols);
+ b1=(unsigned short *)malloc(sizeof(unsigned short )*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ L= (pstDataR[k]);
+ a= (pstDataG[k]);
+ b= (pstDataB[k++]);
+ out=lab2uint16(L,a,b);
+ r1[m]=(out.R);
+ g1[m]=(out.G);
+ b1[m++]=(out.B);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
+
diff --git a/sci_gateway/cpp/opencv_lab2uint8.cpp b/sci_gateway/cpp/opencv_lab2uint8.cpp
new file mode 100644
index 0000000..12ff4e5
--- /dev/null
+++ b/sci_gateway/cpp/opencv_lab2uint8.cpp
@@ -0,0 +1,174 @@
+/*Function-lab2uint8
+Author :Tess Zacharias */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+
+struct Color
+{
+ float R,G,B,X,Y,Z,L,a,b;
+};
+
+
+Color lab2uint8(float L, float a, float b)
+{
+ float R1=round(((255*L)/100));
+ float G1=round(a+128);
+ float B1=round(b+128);
+ Color rgb;
+ rgb.R= R1;
+ rgb.G = G1;
+ rgb.B = B1;
+ return rgb;
+
+}
+
+ int opencv_lab2uint8(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img,dst;
+ float L,a,b;
+ int *piAddrNew = NULL;
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //checking if number of input arguments are 3
+
+ int k=0;
+ // SciErr getMatrixOfDoubleInList(void* _pvCtx, int* _piParent, int _iItemPos, int* _piRows, int* _piCols, double** _pdblReal)
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*iRows*iCols);
+ g1=(double *)malloc(sizeof(double)*iRows*iCols);
+ b1=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ // Vec3d intensity = img.at<Vec3d>(i,j);
+ L= (pstDataR[k]);
+ a= (pstDataG[k]);
+ b= (pstDataB[k++]);
+ out=lab2uint8(L,a,b);
+ r1[m]=(out.R);
+ g1[m]=(out.G);
+ b1[m++]=(out.B);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
+
+
diff --git a/sci_gateway/cpp/opencv_lab2xyz.cpp b/sci_gateway/cpp/opencv_lab2xyz.cpp
new file mode 100644
index 0000000..dc5b97a
--- /dev/null
+++ b/sci_gateway/cpp/opencv_lab2xyz.cpp
@@ -0,0 +1,393 @@
+/*--------------------------------------
+ function-lab2xyz
+ Author :Tess Zacharias
+------------------------------------- */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+ struct Color
+ {
+ float X,Y,Z,L,a,b;
+ };
+ Color lab2xyz1(float L, float a, float b)
+{
+ float y = (L + 16) / 116;
+ float x = a / 500 + y;
+ float z = y - b / 200;
+
+ if ( pow( y , 3 ) > 0.008856 ) { y = pow( y , 3 ); }
+ else { y = ( y - 16 / 116 ) / 7.787; }
+ if ( pow( x , 3 ) > 0.008856 ) { x = pow( x , 3 ); }
+ else { x = ( x - 16 / 116 ) / 7.787; }
+ if ( pow( z , 3 ) > 0.008856 ) { z = pow( z , 3 ); }
+ else { z = ( z - 16 / 116 ) / 7.787; }
+
+ Color xyz;
+ xyz.X= x * REF_X;
+ xyz.Y = y * REF_Y;
+ xyz.Z = z * REF_Z;
+ return xyz;
+
+
+}
+Color lab2xyz2(float L, float a, float b,char *s)
+{
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(!strcasecmp(s,"a"))
+ {
+ REF_X1=1.0985;
+ REF_Y1= 1.0000;
+ REF_Z1=0.3558;
+ }
+ else if(!strcasecmp(s,"c"))
+ {
+ REF_X1=0.9807;
+ REF_Y1= 1.0000;
+ REF_Z1=1.1822;
+ }
+ else if(!strcasecmp(s,"d50"))
+ {
+ REF_X1=0.9642;
+ REF_Y1= 1.0000;
+ REF_Z1=0.8251;
+ }
+ else if(!strcasecmp(s,"d65"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(!strcasecmp(s,"icc"))
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ else if(!strcasecmp(s,"d55"))
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ float y = (L + 16) / 116;
+ float x = a / 500 + y;
+ float z = y - b / 200;
+
+ if ( pow( y , 3 ) > 0.008856 ) { y = pow( y , 3 ); }
+ else { y = ( y - 16 / 116 ) / 7.787; }
+ if ( pow( x , 3 ) > 0.008856 ) { x = pow( x , 3 ); }
+ else { x = ( x - 16 / 116 ) / 7.787; }
+ if ( pow( z , 3 ) > 0.008856 ) { z = pow( z , 3 ); }
+ else { z = ( z - 16 / 116 ) / 7.787; }
+
+ Color xyz;
+ xyz.X= x * REF_X1;
+ xyz.Y = y * REF_Y1;
+ xyz.Z = z * REF_Z1;
+ return xyz;
+}
+Color lab2xyz3(float L, float a, float b,char *s)
+{
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(!strcasecmp(s,"sRGB"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(!strcasecmp(s,"adobe-rgb-1998"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ float y = (L + 16) / 116;
+ float x = a / 500 + y;
+ float z = y - b / 200;
+
+ if ( pow( y , 3 ) > 0.008856 ) { y = pow( y , 3 ); }
+ else { y = ( y - 16 / 116 ) / 7.787; }
+ if ( pow( x , 3 ) > 0.008856 ) { x = pow( x , 3 ); }
+ else { x = ( x - 16 / 116 ) / 7.787; }
+ if ( pow( z , 3 ) > 0.008856 ) { z = pow( z , 3 ); }
+ else { z = ( z - 16 / 116 ) / 7.787; }
+
+ Color xyz;
+ xyz.X= x * REF_X1;
+ xyz.Y = y * REF_Y1;
+ xyz.Z = z * REF_Z1;
+ return xyz;
+}
+int opencv_lab2xyz(char *fname, unsigned long fname_len)
+{
+ SciErr sciErr;
+ int* piAddr1=NULL;
+ int* piAddr2=NULL;
+ int* piAddr3=NULL;
+ int* piAddrNew=NULL;
+ int iRows = 0;
+ int iCols = 0;
+ char* pstData = NULL;
+ char* pstData1 = NULL;
+ CheckInputArgument(pvApiCtx,1,3);
+ CheckOutputArgument(pvApiCtx,1,1);
+ int m=0;
+ int iType = 0;
+ double *value=NULL;
+ int iPrec= 0;
+ Mat img,k;
+ int iRet = 0;
+ int iRet1 = 0;
+ Color out;
+ float L,a,b;
+ sciErr =getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ sciErr = getVarType(pvApiCtx, piAddr1, &iType);
+ if(nbInputArgument(pvApiCtx)==3)
+ {
+ /*retrieve second argument */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr2, &pstData);
+ }
+ }
+ else
+ {
+ sciprint(" The second argument should be string ");
+ return 0;
+ }
+ if((strcasecmp(pstData,"whitepoint")!=0)&&(strcasecmp(pstData,"Colorspace")!=0))
+ {
+ sciprint("\n Second argument should be any of these string :'whitepoint','Colorspace'");
+ return 0;
+ }
+ /*retrieve third argument */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3,&piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr3))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet1 = getAllocatedSingleString(pvApiCtx, piAddr3, &pstData1);
+ }
+ }
+ else
+ {
+ sciprint(" The third argument should be string ");
+ return 0;
+ }
+ if((strcasecmp(pstData,"whitepoint")==0))
+ {
+ if((strcasecmp(pstData1,"d65")!=0)&&(strcasecmp(pstData1,"d50")!=0)&&(strcasecmp(pstData1,"d55")!=0)&&(strcasecmp(pstData1,"icc")!=0)&&(strcasecmp(pstData1,"icc")!=0)&&(strcasecmp(pstData1,"a")!=0)&&(strcasecmp(pstData1,"c")!=0))
+ {
+ sciprint("\nIf Second argument is 'whitepoint' then Third argument should be any of these string :'a','d65','d55','d50','icc','c'");
+ return 0;
+ }
+ }
+ if((strcasecmp(pstData,"Colorspace")==0))
+ {
+ if((strcasecmp(pstData1,"sRGB")!=0)&&(strcasecmp(pstData1,"adobe-rgb-1998")!=0))
+ {
+ sciprint("\nIf Second argument is 'Colorspace' then Third argument should be any of these string :'sRGB','adobe-rgb-1998'");
+ return 0;
+ }
+ }
+ }
+ switch(iType)
+ {
+ case sci_matrix:
+ {
+ /* retrieve matrix values */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols,&value);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ double *output=NULL;
+ output=( double *)malloc(sizeof(double)*iRows*iCols);
+ int j=0;
+ if(nbInputArgument(pvApiCtx)==1)
+ {
+ for(int i=0;i<iRows;i++)
+ {
+ out=lab2xyz1(value[j],value[j+1],value[j+2]);
+ output[j]=out.X;
+ output[j+1]=out.Y;
+ output[j+2]=out.Z;
+ j=j+3;
+ }
+ }
+ else if(nbInputArgument(pvApiCtx)==3)
+ {
+ for(int i=0;i<iRows;i++)
+ {
+ if(!strcasecmp(pstData1,"d65")||!strcasecmp(pstData1,"d50")||!strcasecmp(pstData1,"d55")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"a")||!strcasecmp(pstData1,"c"))
+ {
+ out=lab2xyz2(value[j],value[j+1],value[j+2],pstData1);
+ }
+ else if(!strcasecmp(pstData1,"sRGB")||!strcasecmp(pstData1,"adobe-rgb-1998"))
+ {
+ out=lab2xyz3(value[j],value[j+1],value[j+2],pstData1);
+ }
+ output[j]=out.X;
+ output[j+1]=out.Y;
+ output[j+2]=out.Z;
+ j=j+3;
+ }
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,iRows,iCols,output);
+ free(output);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ break;
+ }
+ case sci_list:
+ {
+ /*retrieve image values as list */
+ int k=0;
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*iRows*iCols);
+ g1=(double *)malloc(sizeof(double)*iRows*iCols);
+ b1=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ L= (pstDataR[k]);
+ a= (pstDataG[k]);
+ b= (pstDataB[k++]);
+ if(nbInputArgument(pvApiCtx)==1)
+ {
+ out=lab2xyz1(L,a,b);
+ }
+ if(nbInputArgument(pvApiCtx)==3)
+ {
+ if(!strcasecmp(pstData1,"d65")||!strcasecmp(pstData1,"d50")||!strcasecmp(pstData1,"d55")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"a")||!strcasecmp(pstData1,"c"))
+ {
+ out=lab2xyz2(L,a,b,pstData1);
+ }
+ else if(!strcasecmp(pstData1,"sRGB")||!strcasecmp(pstData1,"adobe-rgb-1998"))
+ {
+ out=lab2xyz3(L,a,b,pstData1);
+ }
+ }
+ r1[m]=out.X;
+ g1[m]=out.Y;
+ b1[m++]=out.Z;
+ }
+ }
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ break;
+ }
+ default:
+ sciprint("input argument should be either of double matrix or image !\n"); // Should never happen
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_laplacian.cpp b/sci_gateway/cpp/opencv_laplacian.cpp
new file mode 100644
index 0000000..46ce129
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_line.cpp b/sci_gateway/cpp/opencv_line.cpp
new file mode 100644
index 0000000..c047381
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_makecform.cpp b/sci_gateway/cpp/opencv_makecform.cpp
new file mode 100644
index 0000000..c1d8481
--- /dev/null
+++ b/sci_gateway/cpp/opencv_makecform.cpp
@@ -0,0 +1,99 @@
+/********************************************************
+Function :makecform
+Syntax :B=makecform(string)
+*string : 'xyz2lab' 'lab2xyz' 'srgb2xyz'
+ 'xyz2srgb' 'srgb2lab' 'lab2srgb'
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_makecform(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int* piAddr1=NULL;
+ int error;
+ int iRet = 0;
+ char* pstData = NULL;
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ /*retrieve first argument */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr1))
+ {
+ if(isScalar(pvApiCtx, piAddr1))
+ {
+
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr1, &pstData);
+ }
+ }
+ int k=0;
+ char** output=NULL;
+ output=( char **)malloc(sizeof(char*));
+ if(strcasecmp(pstData,"xyz2lab")==0)
+ {
+ output[0]="xyz2lab";
+ sciprint(" \nc_func: @xyz2lab \nColorSpace_in: 'xyz' \nColorSpace_out: 'lab'\nencoding: 'double'\ncdata: [1x1 struct]");
+ }
+ else if(strcasecmp(pstData,"lab2xyz")==0)
+ {
+ output[0]="lab2xyz";
+ sciprint("\nc_func: @lab2xyz\nColorSpace_in: 'lab'\nColorSpace_out: 'xyz'\nencoding: 'double' \ncdata: [1x1 struct]");
+ }
+ else if(strcasecmp(pstData,"srgb2xyz")==0)
+ {
+ output[0]="srgb2xyz";
+ sciprint(" \nc_func: @applycformsequence \nColorSpace_in: 'rgb'\nColorSpace_out: 'xyz' \nencoding: 'double'\ncdata: [1x1 struct]");
+ }
+ else if(strcasecmp(pstData,"xyz2srgb")==0)
+ {
+ output[0]="xyz2srgb";
+ sciprint("\nc_func: @applycformsequence\nColorSpace_in: 'xyz'\nColorSpace_out: 'rgb'\nencoding: 'double' \ncdata: [1x1 struct]");
+ }
+ else if(strcasecmp(pstData,"srgb2lab")==0)
+ {
+ output[0]="srgb2lab";
+ sciprint("\nc_func: @applycformsequence\nColorSpace_in: 'rgb'\nColorSpace_out: 'lab'\nencoding: 'double'\ncdata: [1x1 struct]");
+ }
+ else if(strcasecmp(pstData,"lab2srgb")==0)
+ {
+ output[0]="lab2srgb";
+ sciprint("\nc_func: @applycformsequence\nColorSpace_in: 'lab'\nColorSpace_out: 'rgb' \nencoding: 'double'\ncdata: [1x1 struct]");
+ }
+ else
+ {
+ sciprint("Expected input argument 'xyz2lab' 'lab2xyz' 'srgb2xyz' 'xyz2srgb' 'srgb2lab' 'lab2srgb'");
+ return 0;
+ }
+ sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1,1,1,output);
+ free(output); // Data have been copied into Scilab memory
+ if (sciErr.iErr)
+ {
+ //Make sure everything is cleanup in case of error
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_mean1.cpp b/sci_gateway/cpp/opencv_mean1.cpp
new file mode 100644
index 0000000..4b85513
--- /dev/null
+++ b/sci_gateway/cpp/opencv_mean1.cpp
@@ -0,0 +1,64 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_mean=mean(sourceimage) */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "BOOL.h"
+#include <localization.h>
+#include<string.h>
+#include "../common.h"
+int mean1(char *fname, unsigned long fname_len)
+{
+
+ // Error management variable
+ SciErr sciErr;
+ // Variables declaration //
+ int t,i,j,k;
+ Scalar mean11;
+ //function to check number of input variable
+ CheckInputArgument(pvApiCtx, 1, 1);
+ //function to check number of output variable
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ // get Address of first input
+ Mat image;
+ retrieveImage(image,1);
+ //block of code for calculating meanimage
+ mean11=mean(image,noArray());
+ double m=0;
+ int count=0;
+ for(int i=0;i<4;i++)
+ {
+ if(mean11.val[i]!=0)
+ {
+ m=m+mean11.val[i];
+ count++;
+ }
+
+ }
+ m=m/count;
+ int error;
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,m);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ ////////// Return the output arguments to the Scilab engine //////////
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/opencv_medianblur.cpp b/sci_gateway/cpp/opencv_medianblur.cpp
new file mode 100644
index 0000000..8886af5
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_minAreaRect.cpp b/sci_gateway/cpp/opencv_minAreaRect.cpp
new file mode 100644
index 0000000..ab066b5
--- /dev/null
+++ b/sci_gateway/cpp/opencv_minAreaRect.cpp
@@ -0,0 +1,125 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_rotatedrect=minAreaRect(InputArray points);
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ int minAreaRect(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ int* pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ double sigmaSpace;
+ int error;
+ ////checking input argument
+ CheckInputArgument(pvApiCtx,1,1);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,5,5);
+ //for first argument
+ // get Address of first input
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ //check for any error
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrieve input array
+ //SciErr getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols,&pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int k=0;
+ vector<Point> contours;
+ for(int i=0;i<iCols;i++)
+ {
+
+ contours.push_back(Point2f(pstData[i],pstData[i+1])) ;
+ i++;
+ }
+ RotatedRect rect;
+ rect=minAreaRect(contours);
+ double size1,size2,center1,center2,angle;
+ //from rotated rect datatype we can fetch required size,point,angle
+ Size2f sz; //size2f function for floating point values
+ Point2f cen;
+ sz=rect.size;
+ cen=rect.center;
+ angle=rect.angle;
+ size1=sz.width;
+ size2=sz.height;
+ center1=cen.x;
+ center2=cen.y;
+
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,size1);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+2,size2);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+3,center1);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+4,center2);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+5,angle);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ 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;
+ AssignOutputVariable(pvApiCtx, 5) = nbInputArgument(pvApiCtx) + 5;
+ ReturnArguments(pvApiCtx);
+ }
+}
+
+
diff --git a/sci_gateway/cpp/opencv_minimumenclosingcirlce.cpp b/sci_gateway/cpp/opencv_minimumenclosingcirlce.cpp
new file mode 100644
index 0000000..8f76962
--- /dev/null
+++ b/sci_gateway/cpp/opencv_minimumenclosingcirlce.cpp
@@ -0,0 +1,108 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : [x.center,y.center,r.radius]=minenclosingcircle(InputArray points)
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int minimumenclosingcirlce(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double *pstData = NULL;
+ char **pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ Point2f center;
+ float radius;
+ int error;
+ //checking input argument
+ CheckInputArgument(pvApiCtx,1,1);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,3,3);
+ //for first argument
+ // get Address of first input
+ sciErr =getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ //check for any error
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrieve input array
+ //SciErr getMatrixOfDouble(void* _pvCtx, int* _piAddress, int* _piRows, int* _piCols, double** _pdblReal)
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols,&pstData);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int k=0;
+ vector<Point> contours;
+ for(int i=0;i<iCols;i++)
+ {
+
+ contours.push_back(Point2f(pstData[i],pstData[i+1])) ;
+ i++;
+ }
+
+ minEnclosingCircle(contours,center,radius);
+ ////////// Return the output arguments to the Scilab engine //////////
+ double p1,p2,c; //another way of returning pointer
+ p1=center.x;
+ p2=center.y;
+ c=radius;
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+1,p1);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+2,p2);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ return 0;
+ }
+ error=createScalarDouble(pvApiCtx,nbInputArgument(pvApiCtx)+3,c);
+ if(error!=0)
+ {
+ sciprint("error occurred");
+ 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_gateway/cpp/opencv_montage.cpp b/sci_gateway/cpp/opencv_montage.cpp
new file mode 100644
index 0000000..fcb66d7
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_morphologyEx.cpp b/sci_gateway/cpp/opencv_morphologyEx.cpp
new file mode 100644
index 0000000..cc1666a
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_ntsc2rgb.cpp b/sci_gateway/cpp/opencv_ntsc2rgb.cpp
new file mode 100644
index 0000000..9857c63
--- /dev/null
+++ b/sci_gateway/cpp/opencv_ntsc2rgb.cpp
@@ -0,0 +1,192 @@
+/* ==================================================================== */
+/* Author :Tess Zacharias */
+/* ==================================================================== */
+/* overloaded function */
+/* Syntax : return_matrix_3_xyz_values=lab2xyz(matrix_of_3_labvalues a) */
+/* Syntax : return_matrix_3_xyz_values=lab2xyz(matrix_of_3_labvalues a,String1 Name,String2 value) */
+/* ==================================================================== */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ // #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+
+struct Color
+{
+ float R,G,B,Y,I,Q;
+};
+
+
+Color ntsc2rgb1(float Y, float I, float Q)
+{
+
+ // float y=Y/255.0;
+ // float i=I/255.0;
+ // float q=Q/255.0;
+ float r= 1.000*Y+0.956*I+0.621*Q;
+ float g =1.000*Y-0.272*I-0.647*Q;
+ float b =1.000*Y-1.106*I+1.703*Q;
+
+
+ Color rgb;
+ rgb.R= r;
+ rgb.G= g;
+ rgb.B= b;
+ return rgb;
+
+}
+ int opencv_ntsc2rgb(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img,dst;
+ float Y,I,Q;
+ int *piAddrNew = NULL;
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //checking if number of input arguments are 3
+
+ int k=0;
+ // SciErr getMatrixOfDoubleInList(void* _pvCtx, int* _piParent, int _iItemPos, int* _piRows, int* _piCols, double** _pdblReal)
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ double *r,*g,*b;
+ r=(double *)malloc(sizeof(double)*iRows*iCols);
+ g=(double *)malloc(sizeof(double)*iRows*iCols);
+ b=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ // Vec3d intensity = img.at<Vec3d>(i,j);
+ Y= (pstDataR[k]);
+ I= (pstDataG[k]);
+ Q= (pstDataB[k++]);
+ out=ntsc2rgb1(Y,I,Q);
+ // cout<<R<<"\n";
+ //cout<<G<<"\n";
+ //cout<<B<<"\n";
+ r[m]=(out.R);
+ g[m]=(out.G);
+ b[m++]=(out.B);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
+
+
diff --git a/sci_gateway/cpp/opencv_puttext.cpp b/sci_gateway/cpp/opencv_puttext.cpp
new file mode 100644
index 0000000..97bf62c
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_pyrDown.cpp b/sci_gateway/cpp/opencv_pyrDown.cpp
new file mode 100644
index 0000000..7a8df72
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_pyrMeanShiftFiltering.cpp b/sci_gateway/cpp/opencv_pyrMeanShiftFiltering.cpp
new file mode 100644
index 0000000..7070083
--- /dev/null
+++ b/sci_gateway/cpp/opencv_pyrMeanShiftFiltering.cpp
@@ -0,0 +1,91 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax :return_image=pyrMeanShiftFiltering(InputArray src, double sp, double sr); */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int pyrMeanShiftFiltering(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ int* pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ double sp;
+ double sr;
+ int error;
+ TermCriteria termcrit=TermCriteria( TermCriteria::MAX_ITER+TermCriteria::EPS,5,1) ;
+
+ // checking input argument
+ CheckInputArgument(pvApiCtx,3,3);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ Mat img;
+ retrieveImage(img,1);
+ //second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ error=getScalarDouble(pvApiCtx,piAddr2,&sp);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //third argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ error=getScalarDouble(pvApiCtx,piAddr3,&sr);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //creating variable of type Mat
+ Mat dst;
+ //open cv function
+ pyrMeanShiftFiltering(img,dst, sp,sr,1,termcrit);
+ string tempstring = type2str(dst.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+ }
+}
diff --git a/sci_gateway/cpp/opencv_pyrUp.cpp b/sci_gateway/cpp/opencv_pyrUp.cpp
new file mode 100644
index 0000000..18459c3
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_rectangle.cpp b/sci_gateway/cpp/opencv_rectangle.cpp
new file mode 100644
index 0000000..36d24f0
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_regionfill.cpp b/sci_gateway/cpp/opencv_regionfill.cpp
new file mode 100644
index 0000000..85d89b3
--- /dev/null
+++ b/sci_gateway/cpp/opencv_regionfill.cpp
@@ -0,0 +1,180 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = regionfill(input_image, column_list, row_list)
+ return_image = regionfill(input_image, mask)
+Example:
+ im = regionfill(image, [0 100 100 0], [0 0 100 100])
+ im = regionfill(image, mask)
+********************************************************/
+
+#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_regionfill(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRowsR=0,iColsR=0,iColsC=0,iRowsC=0;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ double *pstDataR = NULL;
+ double *pstDataC = NULL;
+ int i, number_of_points;
+ int lineType = 8;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat image, mask, mask_orig, fin_image;
+ retrieveImage(image, 1);
+
+
+ if (nbInputArgument(pvApiCtx) == 2)
+ {
+ retrieveImage(mask_orig, 2);
+
+ for (int i = 0; i < mask_orig.cols; i++)
+ {
+ for (int j = 0; j < mask_orig.rows; j++)
+ {
+ unsigned char val = mask_orig.at<uchar>(i,j);
+ if (!(val == 0 || val == 1 || val == 255))
+ {
+ sciprint("Please enter binary mask (second argument).");
+ return 0;
+ }
+ }
+ }
+
+ if (mask_orig.type() != CV_8UC1)
+ {
+ cvtColor(mask_orig, mask, CV_BGR2GRAY);
+ }
+ else
+ {
+ mask = mask_orig.clone();
+ }
+ }
+ else
+ {
+ // Get the address of 2nd argument, the column list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the address of the 3rd agument, the row list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the column list in the form of a matrix
+ // No. of columns = No. of elements in the list
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRowsC, &iColsC, &pstDataC);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iRowsC != 1)
+ {
+ sciprint("Please enter a list of column coordinates.\n");
+ return 0;
+ }
+
+ // Get the row list in the form of a matrix
+ // No. of columns = No. of elements in the list
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRowsR, &iColsR, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iRowsR != 1)
+ {
+ sciprint("Please enter a list of row coordinates.\n");
+ return 0;
+ }
+
+ if (iColsC != iColsR)
+ {
+ sciprint("Please ensure number of elements in both row and column lists are equal.\n");
+ return 0;
+ }
+
+ // Number of points is number of columns
+ number_of_points = iColsC;
+
+ // Create the n points which define
+ // the polygon
+ Point points[1][number_of_points];
+
+ for (i = 0; i < number_of_points; i++)
+ {
+ if (pstDataR[i] < 0 || pstDataC[i] < 0)
+ {
+ sciprint("Coordinates cannot be negative.\n");
+ return 0;
+ }
+ else
+ points[0][i] = Point(pstDataR[i], pstDataC[i]);
+ }
+
+ const Point* ppt[1] = { points[0] };
+
+ int npt[] = { number_of_points };
+
+ // Create a new, black, blank image same size as of input
+ mask_orig = Mat::zeros(image.size(), image.type());
+ cvtColor(mask_orig, mask, CV_BGR2GRAY);
+
+ // Call the fillPoly OpenCV function
+ // Fill the blank image in the polygon specified
+ // by the points
+ fillPoly(mask, ppt, npt, 1, Scalar(255, 255, 255), lineType);
+ }
+
+ inpaint(image, mask, fin_image, 3, INPAINT_TELEA);
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_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_gateway/cpp/opencv_rgb2lab.cpp b/sci_gateway/cpp/opencv_rgb2lab.cpp
new file mode 100644
index 0000000..c031790
--- /dev/null
+++ b/sci_gateway/cpp/opencv_rgb2lab.cpp
@@ -0,0 +1,244 @@
+/* function-rgb2lab
+ Author :Tess Zacharias */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+
+struct Color
+{
+ float R,G,B,X,Y,Z,Ls,as,bs,r,g,b;
+};
+Color rgb2lab1(float R, float G, float B)
+{
+
+ float r = R/255.f; //R 0..1
+ float g = G/255.f; //G 0..1
+ float b = B/255.f; //B 0..1
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz;
+ if (r <= 0.04045)
+ r = r/12.92;
+ else
+ r = (float)pow((r+0.055)/1.055,2.4);
+ if (g <= 0.04045)
+ g = g/12.92;
+ else
+ g = (float)pow((g+0.055)/1.055,2.4);
+ if (b <= 0.04045)
+ b = b/12.92;
+ else
+ b = (float)pow((b+0.055)/1.055,2.4);
+ float X = 0.4124*r + 0.3576*g + 0.1805*b;
+ float Y = 0.2126*r + 0.7152 *g + 0.0722 *b;
+ float Z = 0.0193*r + 0.1192*g + 0.9505 *b;
+ float xr = X/REF_X;
+ float yr = Y/REF_Y;
+ float zr = Z/REF_Z;
+ if ( xr > eps )
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if ( yr > eps )
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if ( zr > eps )
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Color lab;
+ lab.Ls= ( 116 * fy ) - 16;
+ lab.as= 500*(fx-fy);
+ lab.bs= 200*(fy-fz);
+ return lab;
+
+}
+ Color rgb2lab2(float R, float G, float B,char *s)
+{
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(!strcmp(s,"a"))
+ {
+ REF_X1=1.0985;
+ REF_Y1= 1.0000;
+ REF_Z1=0.3558;
+ }
+ else if(!strcmp(s,"c"))
+ {
+ REF_X1=0.9807;
+ REF_Y1= 1.0000;
+ REF_Z1=1.1822;
+ }
+ else if(!strcmp(s,"d50"))
+ {
+ REF_X1=0.9642;
+ REF_Y1= 1.0000;
+ REF_Z1=0.8251;
+ }
+ else if(!strcmp(s,"d65"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(!strcmp(s,"icc"))
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ else if(!strcmp(s,"e"))
+ {
+ REF_X1=1.000;
+ REF_Y1=1.000;
+ REF_Z1=1.000;
+ }
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz,X,Y,Z,xr,yr,zr;
+ float r = R/255.f; //R 0..1
+ float g = G/255.f; //G 0..1
+ float b = B/255.f; //B 0..1
+ if (r <= 0.04045)
+ r = r/12.92;
+ else
+ r = (float)pow((r+0.055)/1.055,2.4);
+ if (g <= 0.04045)
+ g = g/12.92;
+ else
+ g = (float)pow((g+0.055)/1.055,2.4);
+ if (b <= 0.04045)
+ b = b/12.92;
+ else
+ b = (float)pow((b+0.055)/1.055,2.4);
+ X = 0.4124*r + 0.3576*g + 0.1805*b;
+ Y = 0.2126*r + 0.7152 *g + 0.0722 *b;
+ Z = 0.0193*r + 0.1192*g + 0.9505 *b;
+ xr = X/REF_X1;
+ yr = Y/REF_Y1;
+ zr = Z/REF_Z1;
+ if ( xr > eps )
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if ( yr > eps )
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if ( zr > eps )
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Color lab;
+ lab.Ls= ( 116 * fy ) - 16;
+ lab.as= 500*(fx-fy);
+ lab.bs= 200*(fy-fz);
+ return lab;
+
+}
+int opencv_rgb2lab(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr2=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ int* piaddr=NULL;
+ char *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img;
+ float R,G,B;
+ int *piAddrNew = NULL;
+ CheckOutputArgument(pvApiCtx,1,1);
+ int m=0;
+ retrieveImage(img,1);
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ g1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ b1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ for(int i=0;i<img.rows;i++)
+ {
+ for(int j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i,j);
+ R= intensity.val[2];
+ G= intensity.val[1];
+ B= intensity.val[0];
+ out=rgb2lab1(R,G,B);
+ r1[m]=out.Ls;
+ g1[m]=out.as;
+ b1[m++]=out.bs;
+ }
+ }
+ //creating the list that will be passed to the Scilab enviroment
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, img.rows,img.cols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, img.rows, img.cols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, img.rows, img.cols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_rgb2ntsc.cpp b/sci_gateway/cpp/opencv_rgb2ntsc.cpp
new file mode 100644
index 0000000..00be9cd
--- /dev/null
+++ b/sci_gateway/cpp/opencv_rgb2ntsc.cpp
@@ -0,0 +1,132 @@
+/* function-rgb2lab
+ Author :Tess Zacharias */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+struct Color
+{
+ float R,G,B,Y,I,Q;
+};
+Color rgb2ntsc(float R, float G, float B)
+{
+
+ float r=R/255.0;
+ float g=G/255.0;
+ float b=B/255.0;
+ float y = 0.299*r + 0.587*g + 0.114*b;
+ float i = 0.596*r -0.274 *g - 0.322 *b;
+ float q = 0.211*r - 0.523*g + 0.312 *b;
+
+
+ Color ntsc;
+ ntsc.Y= y;
+ ntsc.I= i;
+ ntsc.Q= q;
+ return ntsc;
+
+}
+
+int opencv_rgb2ntsc(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr2=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ int* piaddr=NULL;
+ char *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img;
+ float R,G,B;
+ int *piAddrNew = NULL;
+ CheckOutputArgument(pvApiCtx,1,1);
+ int m=0;
+ retrieveImage(img,1);
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ g1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ b1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ for(int i=0;i<img.rows;i++)
+ {
+ for(int j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i,j);
+ R= intensity.val[2];
+ G= intensity.val[1];
+ B= intensity.val[0];
+ out=rgb2ntsc(R,G,B);
+ r1[m]=out.Y;
+ g1[m]=out.I;
+ b1[m++]=out.Q;
+ }
+ }
+ //creating the list that will be passed to the Scilab enviroment
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, img.rows,img.cols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, img.rows, img.cols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, img.rows, img.cols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_rgb2xyz.cpp b/sci_gateway/cpp/opencv_rgb2xyz.cpp
new file mode 100644
index 0000000..f15f5a4
--- /dev/null
+++ b/sci_gateway/cpp/opencv_rgb2xyz.cpp
@@ -0,0 +1,220 @@
+/* function-rgb2lab
+ Author :Tess Zacharias */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+struct Color
+{
+ float R,G,B,X,Y,Z,Ls,as,bs,r,g,b;
+};
+Color rgb2xyz1(float R, float G, float B)
+{
+
+ float r = R/255.f; //R 0..1
+ float g = G/255.f; //G 0..1
+ float b = B/255.f; //B 0..1
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz;
+ if (r <= 0.04045)
+ r = r/12.92;
+ else
+ r = (float)pow((r+0.055)/1.055,2.4);
+ if (g <= 0.04045)
+ g = g/12.92;
+ else
+ g = (float)pow((g+0.055)/1.055,2.4);
+ if (b <= 0.04045)
+ b = b/12.92;
+ else
+ b = (float)pow((b+0.055)/1.055,2.4);
+ float X1 = 0.4124*r + 0.3576*g + 0.1805*b;
+ float Y1 = 0.2126*r + 0.7152 *g + 0.0722 *b;
+ float Z1 = 0.0193*r + 0.1192*g + 0.9505 *b;
+ float xr = X1;
+ float yr = Y1;
+ float zr = Z1;
+ Color xyz;
+ xyz.X= xr;
+ xyz.Y= yr;
+ xyz.Z= zr;
+ return xyz;
+
+}
+ Color rgb2xyz2(float R, float G, float B,char *s)
+{
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(!strcmp(s,"a"))
+ {
+ REF_X1=1.0985;
+ REF_Y1= 1.0000;
+ REF_Z1=0.3558;
+ }
+ else if(!strcmp(s,"c"))
+ {
+ REF_X1=0.9807;
+ REF_Y1= 1.0000;
+ REF_Z1=1.1822;
+ }
+ else if(!strcmp(s,"d50"))
+ {
+ REF_X1=0.9642;
+ REF_Y1= 1.0000;
+ REF_Z1=0.8251;
+ }
+ else if(!strcmp(s,"d65"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(!strcmp(s,"icc"))
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ else if(!strcmp(s,"e"))
+ {
+ REF_X1=1.000;
+ REF_Y1=1.000;
+ REF_Z1=1.000;
+ }
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz,X1,Y1,Z1,xr,yr,zr;
+ float r = R/255.f; //R 0..1
+ float g = G/255.f; //G 0..1
+ float b = B/255.f; //B 0..1
+ if (r <= 0.04045)
+ r = r/12.92;
+ else
+ r = (float)pow((r+0.055)/1.055,2.4);
+ if (g <= 0.04045)
+ g = g/12.92;
+ else
+ g = (float)pow((g+0.055)/1.055,2.4);
+ if (b <= 0.04045)
+ b = b/12.92;
+ else
+ b = (float)pow((b+0.055)/1.055,2.4);
+ X1 = 0.4124*r + 0.3576*g + 0.1805*b;
+ Y1 = 0.2126*r + 0.7152 *g + 0.0722 *b;
+ Z1 = 0.0193*r + 0.1192*g + 0.9505 *b;
+ xr = X1;
+ yr = Y1;
+ zr = Z1;
+ Color xyz;
+ xyz.X= xr;
+ xyz.Y= yr;
+ xyz.Z= zr;
+ return xyz;
+
+}
+
+int opencv_rgb2xyz(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr2=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ int* piaddr=NULL;
+ char *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img;
+ float R,G,B;
+ int *piAddrNew = NULL;
+ CheckOutputArgument(pvApiCtx,1,1);
+ int m=0;
+ retrieveImage(img,1);
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ g1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ b1=(double *)malloc(sizeof(double)*img.rows*img.cols);
+ for(int i=0;i<img.rows;i++)
+ {
+ for(int j=0;j<img.cols;j++)
+ {
+ Vec3b intensity = img.at<Vec3b>(i,j);
+ R= intensity.val[2];
+ G= intensity.val[1];
+ B= intensity.val[0];
+ out=rgb2xyz1(R,G,B);
+ r1[m]=out.X;
+ g1[m]=out.Y;
+ b1[m++]=out.Z;
+ }
+ }
+ //creating the list that will be passed to the Scilab enviroment
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, img.rows,img.cols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, img.rows, img.cols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, img.rows, img.cols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // free(checker);
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_roifill.cpp b/sci_gateway/cpp/opencv_roifill.cpp
new file mode 100644
index 0000000..919be08
--- /dev/null
+++ b/sci_gateway/cpp/opencv_roifill.cpp
@@ -0,0 +1,180 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = roifill(input_image, column_list, row_list)
+ return_image = roifill(input_image, mask)
+Example:
+ im = roifill(image, [0 100 100 0], [0 0 100 100])
+ im = roifill(image, mask)
+********************************************************/
+
+#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_roifill(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRowsR=0,iColsR=0,iColsC=0,iRowsC=0;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ double *pstDataR = NULL;
+ double *pstDataC = NULL;
+ int i, number_of_points;
+ int lineType = 8;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1);
+
+ // Get the input image from the Scilab environment
+ Mat image, image_orig, mask, fin_image, mask_orig;
+ retrieveImage(image_orig, 1);
+ cvtColor(image_orig, image, CV_BGR2GRAY);
+
+ if (nbInputArgument(pvApiCtx) == 2)
+ {
+ retrieveImage(mask_orig, 2);
+
+ for (int i = 0; i < mask_orig.cols; i++)
+ {
+ for (int j = 0; j < mask_orig.rows; j++)
+ {
+ unsigned char val = mask_orig.at<uchar>(i,j);
+ if (!(val == 0 || val == 1 || val == 255))
+ {
+ sciprint("Please enter binary mask (second argument).");
+ return 0;
+ }
+ }
+ }
+
+ if (mask_orig.type() != CV_8UC1)
+ {
+ cvtColor(mask_orig, mask, CV_BGR2GRAY);
+ }
+ else
+ {
+ mask = mask_orig.clone();
+ }
+
+ }
+ else
+ {
+ // Get the address of 2nd argument, the column list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the address of the 3rd agument, the row list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the column list in the form of a matrix
+ // No. of columns = No. of elements in the list
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRowsC, &iColsC, &pstDataC);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iRowsC != 1)
+ {
+ sciprint("Please enter a list of column coordinates.\n");
+ return 0;
+ }
+
+ // Get the row list in the form of a matrix
+ // No. of columns = No. of elements in the list
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRowsR, &iColsR, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iRowsR != 1)
+ {
+ sciprint("Please enter a list of row coordinates.\n");
+ return 0;
+ }
+
+ if (iColsC != iColsR)
+ {
+ sciprint("Please ensure number of elements in both row and column lists are equal.\n");
+ return 0;
+ }
+
+ // Number of points is number of columns
+ number_of_points = iColsC;
+
+ // Create the n points which define
+ // the polygon
+ Point points[1][number_of_points];
+
+ for (i = 0; i < number_of_points; i++)
+ {
+ if (pstDataR[i] < 0 || pstDataC[i] < 0)
+ {
+ sciprint("Coordinates cannot be negative.\n");
+ return 0;
+ }
+ else
+ points[0][i] = Point(pstDataR[i], pstDataC[i]);
+ }
+
+ const Point* ppt[1] = { points[0] };
+
+ int npt[] = { number_of_points };
+
+ // Create a new, black, blank image same size as of input
+ mask = Mat::zeros(image.size(), image.type());
+
+ // Call the fillPoly OpenCV function
+ // Fill the blank image in the polygon specified
+ // by the points
+ fillPoly(mask, ppt, npt, 1, Scalar(255, 255, 255), lineType);
+ }
+
+ inpaint(image, mask, fin_image, 3, INPAINT_TELEA);
+
+ string tempstring = type2str(fin_image.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker, fin_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_gateway/cpp/opencv_roipoly.cpp b/sci_gateway/cpp/opencv_roipoly.cpp
new file mode 100644
index 0000000..0b11364
--- /dev/null
+++ b/sci_gateway/cpp/opencv_roipoly.cpp
@@ -0,0 +1,145 @@
+/********************************************************
+Author: Vinay Bhat
+********************************************************
+Usage: return_image = roipoly(input_image, column_list, row_list)
+Example:
+ im = roipoly(image, [0 100 100 0], [0 0 100 100])
+********************************************************/
+
+#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_roipoly(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int iRowsR=0,iColsR=0,iColsC=0,iRowsC=0;
+ int *piAddr = NULL;
+ int *piAddr2 = NULL;
+ double *pstDataR = NULL;
+ double *pstDataC = NULL;
+ int i, number_of_points;
+ int lineType = 8;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 4);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Get the input image from the Scilab environment
+ Mat image;
+ retrieveImage(image, 1);
+
+ // Get the address of 2nd argument, the column list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the address of the 3rd agument, the row list
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ // Get the column list in the form of a matrix
+ // No. of columns = No. of elements in the list
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRowsC, &iColsC, &pstDataC);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iRowsC != 1)
+ {
+ sciprint("Please enter a list of column coordinates.\n");
+ return 0;
+ }
+
+ // Get the row list in the form of a matrix
+ // No. of columns = No. of elements in the list
+ // No. of rows = 1
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRowsR, &iColsR, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if (iRowsR != 1)
+ {
+ sciprint("Please enter a list of row coordinates.\n");
+ return 0;
+ }
+
+ if (iColsC != iColsR)
+ {
+ sciprint("Please ensure number of elements in both row and column lists are equal.\n");
+ return 0;
+ }
+
+ // Number of points is number of columns
+ number_of_points = iColsC;
+
+ // Create the n points which define
+ // the polygon
+ Point points[1][number_of_points];
+
+ for (i = 0; i < number_of_points; i++)
+ {
+ if (pstDataR[i] < 0 || pstDataC[i] < 0)
+ {
+ sciprint("Coordinates cannot be negative.\n");
+ return 0;
+ }
+ else
+ points[0][i] = Point(pstDataR[i], pstDataC[i]);
+ }
+
+ const Point* ppt[1] = { points[0] };
+
+ int npt[] = { number_of_points };
+
+ // Create a new, white, blank image same size as of input
+ Mat img = Mat::zeros(image.size(), image.type());
+
+ // Call the fillPoly OpenCV function
+ // Fill the blank image in the polygon specified
+ // by the points
+ fillPoly(img, ppt, npt, 1, Scalar(255, 255, 255), lineType);
+
+ 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_gateway/cpp/opencv_scharr.cpp b/sci_gateway/cpp/opencv_scharr.cpp
new file mode 100644
index 0000000..cb897d0
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_sepFilter2D.cpp b/sci_gateway/cpp/opencv_sepFilter2D.cpp
new file mode 100644
index 0000000..cf3db15
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_sobel.cpp b/sci_gateway/cpp/opencv_sobel.cpp
new file mode 100644
index 0000000..912be4d
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_ssim.cpp b/sci_gateway/cpp/opencv_ssim.cpp
new file mode 100644
index 0000000..b570704
--- /dev/null
+++ b/sci_gateway/cpp/opencv_ssim.cpp
@@ -0,0 +1,94 @@
+/********************************************************
+Author: Dhruti Shah
+********************************************************
+Usage: ssim_value = ssim (image, reference)
+Example:
+ val = ssim(image, ref)
+********************************************************/
+
+#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_ssim(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 2, 2);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ // Get the input image from the Scilab environment
+ Mat image;
+ retrieveImage(image, 1);
+
+ Mat ref;
+ retrieveImage(ref, 2);
+
+ double mean_img=0, mean_ref=0, std_img=0, std_ref=0, covar=0, mean_xy=0;
+
+ for (int i = 0; i < image.rows; ++i)
+ {
+ for (int j = 0; j < image.cols; ++j)
+ {
+ mean_img += image.at<uchar>(i,j);
+ mean_ref += ref.at<uchar>(i,j);
+ mean_xy += (image.at<uchar>(i,j)*ref.at<uchar>(i,j));
+ }
+ }
+
+ int no_of_pixels = image.rows * image.cols;
+ mean_img = mean_img/no_of_pixels;
+ mean_ref = mean_ref/no_of_pixels;
+ mean_xy = mean_xy/no_of_pixels;
+ covar = mean_xy - (mean_img * mean_ref);
+
+ for (int m = 0; m < image.rows; ++m)
+ {
+ for (int n = 0; n < image.cols; ++n)
+ {
+ std_img += ( (image.at<uchar>(m,n) - mean_img) * (image.at<uchar>(m,n) - mean_img) ) ;
+ std_ref += ( (ref.at<uchar>(m,n) - mean_ref) * (ref.at<uchar>(m,n) - mean_ref) ) ;
+ }
+ }
+
+ std_ref = std_ref/no_of_pixels;
+ std_ref = sqrt(std_ref);
+
+ std_img = std_img/no_of_pixels;
+ std_img = sqrt(std_img);
+
+ double value;
+ value = ( (2*mean_img*mean_ref) + 0.0001 ) * ( (2*covar) + 0.0009 );
+ value = value / ( ((mean_img*mean_img) + (mean_ref*mean_ref) + 0.0001) * ((std_img*std_img) + (std_ref*std_ref) + 0.0009) );
+
+ intErr = createScalarDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,value);
+ 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;
+
+ }
+/* ==================================================================== */
+} \ No newline at end of file
diff --git a/sci_gateway/cpp/opencv_threshold.cpp b/sci_gateway/cpp/opencv_threshold.cpp
new file mode 100644
index 0000000..1210d47
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_undistort.cpp b/sci_gateway/cpp/opencv_undistort.cpp
new file mode 100644
index 0000000..da72d8e
--- /dev/null
+++ b/sci_gateway/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_gateway/cpp/opencv_viscircles.cpp b/sci_gateway/cpp/opencv_viscircles.cpp
new file mode 100644
index 0000000..d7e82a8
--- /dev/null
+++ b/sci_gateway/cpp/opencv_viscircles.cpp
@@ -0,0 +1,209 @@
+/********************************************************
+Function :viscircles
+Syntax :B=viscircles(A,centers,radii)
+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_viscircles(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ int *piAddr1= NULL;
+ int *piAddr2= NULL;
+ int *piAddr3= NULL;
+ int *piAddr4= NULL;
+ char* pstData = NULL;
+ char* pstData1 = NULL;
+ Mat src_gray,image;
+ CheckInputArgument(pvApiCtx, 3, 5);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ double *Cx = NULL;
+ double *Cy = NULL;
+ double *radius=NULL;
+ int iRows1 = 0;
+ int iCols1 = 0;
+ int iRows2 = 0;
+ int iCols2 = 0;
+ int iRet = 0;
+ int iRet1 = 0;
+ double n;
+ retrieveImage(image, 1);
+ Mat drawing = Mat::zeros(image.size(), CV_8UC3 );
+ sciErr =getVarAddressFromPosition(pvApiCtx,2,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 1, &iRows1, &iCols1, &Cx);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 2, &iRows1, &iCols1, &Cy);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr =getVarAddressFromPosition(pvApiCtx,3,&piAddr2);
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows2, &iCols2,&radius);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ for( int i = 1; i < iCols1; i++ )
+ {
+ Point center(cvRound(Cx[i]), cvRound(Cy[i]));
+ int r = cvRound(radius[i]);
+ if(Rhs==3)
+ {
+ circle( drawing, center, r, Scalar(0,0,255), 1, 8, 0 );
+ }
+ else if(Rhs==5)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr3))
+ {
+ if(isScalar(pvApiCtx, piAddr3))
+ {
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr3, &pstData);
+ }
+ }
+ else
+ {
+ sciprint(" The Fourth argument should be string ");
+ return 0;
+ }
+ if((strcasecmp(pstData,"LineWidth")!=0)&&(strcasecmp(pstData,"EdgeColor")!=0))
+ {
+ sciprint("\nIf Fourth argument must be a string :'LineWidth' or 'EdgeColor'");
+ return 0;
+ }
+ if(strcasecmp(pstData,"EdgeColor")==0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr4);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr4))
+ {
+ if(isScalar(pvApiCtx, piAddr4))
+ {
+ iRet1 = getAllocatedSingleString(pvApiCtx, piAddr4, &pstData1);
+ }
+ }
+ else
+ {
+ sciprint(" The Fifth argument should be string ");
+ return 0;
+ }
+ if(strcasecmp(pstData1,"b")==0)
+ {
+ circle( drawing, center, r, Scalar(0,255,255), 2, 8, 0 );
+ }
+ else if(strcasecmp(pstData1,"r")==0)
+ {
+ circle( drawing, center, r, Scalar(255,255,0), 2, 8, 0 );
+ }
+ else if(strcasecmp(pstData1,"g")==0)
+ {
+ circle( drawing, center, r, Scalar(255,0,255), 2, 8, 0 );
+ }
+ else if(strcasecmp(pstData1,"y")==0)
+ {
+ circle( drawing, center, r, Scalar(255,0,0), 2, 8, 0 );
+ }
+ else if(strcasecmp(pstData1,"m")==0)
+ {
+ circle( drawing, center, r, Scalar(0,255,0), 2, 8, 0 );
+ }
+ else if(strcasecmp(pstData1,"c")==0)
+ {
+ circle( drawing, center, r, Scalar(0,0,255), 2, 8, 0 );
+ }
+ else if(strcasecmp(pstData1,"k")==0)
+ {
+ circle( drawing, center, r, Scalar(255,255,255), 2, 8, 0 );
+ }
+ else if(strcasecmp(pstData1,"w")==0)
+ {
+ circle( drawing, center, r, Scalar(0,0,0), 2, 8, 0 );
+ }
+ else
+ {
+ sciprint("\nThe Fifth argument must be a either of string value 'b','c','r','g''m','k','w','y'");
+ return 0;
+ }
+ }
+ if(strcasecmp(pstData,"LineWidth")==0)
+ {
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr4, &n);
+ if(intErr)
+ {
+ return intErr;
+ }
+ // The error checks for the function
+ if(n != round(n) || n<=0)
+ {
+ sciprint("The value of n must be an integer\n");
+ return 0;
+ }
+ circle( drawing, center, r, Scalar(255,255,0), n, 8, 0 );
+ }
+ }
+ }
+ bitwise_not(drawing,drawing);
+ string tempstring = type2str(drawing.type());
+ char *checker;
+ checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,drawing,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_gateway/cpp/opencv_watershed.cpp b/sci_gateway/cpp/opencv_watershed.cpp
new file mode 100644
index 0000000..b6379ba
--- /dev/null
+++ b/sci_gateway/cpp/opencv_watershed.cpp
@@ -0,0 +1,105 @@
+/********************************************************
+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_watershed(char *fname, unsigned long fname_len)
+ {
+
+ SciErr sciErr;
+ int intErr = 0;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ Mat src;
+ retrieveImage(src, 1);
+ // Create binary image from source image
+ Mat bw;
+ cvtColor(src, bw, CV_BGR2GRAY);
+ threshold(bw, bw, 40, 255, CV_THRESH_BINARY);
+ // Perform the distance transform algorithm
+ Mat dist;
+ distanceTransform(bw, dist, CV_DIST_L2, 3);
+ // Normalize the distance image for range = {0.0, 1.0}
+ // so we can visualize and threshold it
+ normalize(dist, dist, 0, 1., cv::NORM_MINMAX);
+ //imshow("dist", dist);
+ // Threshold to obtain the peaks
+ // This will be the markers for the foreground objects
+ threshold(dist, dist, .5, 1., CV_THRESH_BINARY);
+ //imshow("dist2", dist);
+ // Create the CV_8U version of the distance image
+ // It is needed for cv::findContours()
+ Mat dist_8u;
+ dist.convertTo(dist_8u, CV_8U);
+ // Find total markers
+ vector<vector<Point> > contours;
+ findContours(dist_8u, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
+ int ncomp = contours.size();
+ // Create the marker image for the watershed algorithm
+ Mat markers = Mat::zeros(dist.size(), CV_32SC1);
+ // Draw the foreground markers
+ for (int i = 0; i < ncomp; i++)
+ drawContours(markers, contours, i, Scalar::all(i+1), -1);
+ // Draw the background marker
+ circle(markers, cv::Point(5,5), 3, CV_RGB(255,255,255), -1);
+ //imshow("markers", markers*10000);
+ // Perform the watershed algorithm
+ watershed(src, markers);
+ // Generate random colors
+ vector<Vec3b> colors;
+ for (int i = 0; i < ncomp; i++)
+ {
+ int b = theRNG().uniform(0, 255);
+ int g = theRNG().uniform(0, 255);
+ int r = theRNG().uniform(0, 255);
+
+ colors.push_back(Vec3b((uchar)b, (uchar)g, (uchar)r));
+ }
+ // Create the result image
+ Mat dst = Mat::zeros(markers.size(), CV_8UC3);
+ // Fill labeled objects with random colors
+ for (int i = 0; i < markers.rows; i++)
+ {
+ for (int j = 0; j < markers.cols; j++)
+ {
+ int index = markers.at<int>(i,j);
+ if (index > 0 && index <= ncomp)
+ dst.at<cv::Vec3b>(i,j) = colors[index-1];
+ else
+ dst.at<cv::Vec3b>(i,j) = Vec3b(0,0,0);
+ }
+ }
+
+ //imshow("dst", dst);
+
+
+ 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_gateway/cpp/opencv_whitepoint.cpp b/sci_gateway/cpp/opencv_whitepoint.cpp
new file mode 100644
index 0000000..c4d3725
--- /dev/null
+++ b/sci_gateway/cpp/opencv_whitepoint.cpp
@@ -0,0 +1,108 @@
+/********************************************************
+Function :whitepoint
+Syntax :B=whitepoint(string)
+*string :'d65' , 'd50','a','icc','c','d55'
+Author : Tess Zacharias
+********************************************************/
+
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include "string.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_whitepoint(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+
+ int* piAddr1=NULL;
+ int error;
+ int iRet = 0;
+ char* pstData = NULL;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 1, 1);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+ sciErr = getVarAddressFromPosition(pvApiCtx, 1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ if(isStringType(pvApiCtx, piAddr1))
+ {
+ if(isScalar(pvApiCtx, piAddr1))
+ {
+
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr1, &pstData);
+ }
+ }
+ double *output=NULL;int k=0;
+ output=( double *)malloc(sizeof(double)*3);
+ if(strcmp(pstData,"d65")==0)
+ {
+ output[0]=0.9504;
+ output[1]=1.0000;
+ output[2]=1.0889;
+ }
+ else if(strcmp(pstData,"d50")==0)
+ {
+ output[0]=0.9642;
+ output[1]=1.0000;
+ output[2]=0.8251;
+ }
+ else if(strcmp(pstData,"icc")==0)
+ {
+ output[0]=0.9642;
+ output[1]=1.0000;
+ output[2]=0.8249;
+ }
+ else if(strcmp(pstData,"a")==0)
+ {
+ output[0]=1.0985;
+ output[1]=1.0000;
+ output[2]=0.3558;
+ }
+ else if(strcmp(pstData,"d55")==0)
+ {
+ output[0]=0.9568;
+ output[1]=1.0000;
+ output[2]=0.9214;
+ }
+ else if(strcmp(pstData,"c")==0)
+ {
+ output[0]=0.9807;
+ output[1]=1.0000;
+ output[2]=1.1823;
+ }
+ else
+ {
+ sciprint("Expected input number 1:to match one of these strings:'icc', 'd50', 'd55', 'd65', 'c', 'a'");
+ return 0;
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,1,3,output);
+ free(output); // Data have been copied into Scilab memory
+ if (sciErr.iErr)
+ {
+ //Make sure everything is cleanup in case of error
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_wiener2.cpp b/sci_gateway/cpp/opencv_wiener2.cpp
new file mode 100644
index 0000000..802d9ce
--- /dev/null
+++ b/sci_gateway/cpp/opencv_wiener2.cpp
@@ -0,0 +1,178 @@
+/*////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+Created By: Riddhish Bhalodia
+Date: 14th October 2015
+
+Usage:
+
+void wiener2(Mat img,int n, double sigma)
+
+1) img : Input image, grayscale only
+2) n : filt size
+3) sigma : noise var, if sigma = 0 then the variance is estimated from data
+
+*/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+#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_wiener2(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;
+ double n;
+ double sigma;
+
+
+ Mat img;
+ //checking input argument
+ CheckInputArgument(pvApiCtx, 3, 3);
+ CheckOutputArgument(pvApiCtx, 1, 1) ;
+
+ retrieveImage(img, 1);
+ //for value of the scale factor
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr2, &n);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ intErr = getScalarDouble(pvApiCtx, piAddr3, &sigma);
+ if(intErr)
+ {
+ return intErr;
+ }
+
+ // The error checks for the function
+ if(n != round(n) || n<=0 || int(n)%2==0)
+ {
+ sciprint("The value of n must be an odd integer \n");
+ return 0;
+ }
+
+ Mat out = Mat::zeros(img.size(),img.type());
+ sigma=255*255*sigma;
+ if(img.channels() !=1){
+ sciprint("Grayscale images only!");
+ return 0;
+ }
+
+ int i_min,i_max,j_min,j_max;
+ int w = (n-1)/2;
+
+ if(sigma==0){
+ double noise_est = 0;
+ for(int i=0;i<img.rows;i++){
+ for(int j=0;j<img.cols;j++){
+ i_min = max(i-w,0);
+ i_max = min(i+w,img.rows-1);
+ j_min = max(j-w,0);
+ j_max = min(j+w,img.cols-1);
+
+ // find mean of the patch
+ double mean = 0;
+ for(int ii=i_min;ii<(i_max+1);ii++){
+ for(int jj=j_min;jj<(j_max+1);jj++){
+ mean = mean + ((double)img.at<uchar>(ii,jj));
+
+ }
+ }
+ mean = mean/(n*n);
+
+ double var=0;
+ for(int ii=i_min;ii<(i_max+1);ii++){
+ for(int jj=j_min;jj<(j_max+1);jj++){
+ var = var + ((double)img.at<uchar>(ii,jj))*((double)img.at<uchar>(ii,jj));
+ }
+ }
+ var = var/(n*n);
+ var = var - mean*mean;
+ noise_est = noise_est + var;
+ }
+ }
+ noise_est = noise_est/(img.rows*img.cols);
+ sigma = noise_est;
+ }
+
+ for(int i=0;i<img.rows;i++){
+ for(int j=0;j<img.cols;j++){
+ i_min = max(i-w,0);
+ i_max = min(i+w,img.rows-1);
+ j_min = max(j-w,0);
+ j_max = min(j+w,img.cols-1);
+
+ // find mean of the patch
+ double mean = 0;
+ for(int ii=i_min;ii<(i_max+1);ii++){
+ for(int jj=j_min;jj<(j_max+1);jj++){
+ mean = mean + ((double)img.at<uchar>(ii,jj));
+
+ }
+ }
+ mean = mean/(n*n);
+
+ // find variance of the patch
+ double var=0;
+ for(int ii=i_min;ii<(i_max+1);ii++){
+ for(int jj=j_min;jj<(j_max+1);jj++){
+ var = var + ((double)img.at<uchar>(ii,jj))*((double)img.at<uchar>(ii,jj));
+ }
+ }
+ var = var/(n*n);
+ var = var - mean*mean;
+
+ double temp;
+ double sum=0;
+
+ temp = mean + (fmax(0,(var - sigma))/fmax(var,sigma))*(((double)img.at<uchar>(i,j)) - mean);
+ out.at<uchar>(i,j) = temp;
+ }
+ }
+
+
+ // out is the return image
+ 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);
+ //Assigning the list as the Output Variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+
+ ReturnArguments(pvApiCtx);
+ return 0;
+
+
+ }
+} \ No newline at end of file
diff --git a/sci_gateway/cpp/opencv_xyz2double.cpp b/sci_gateway/cpp/opencv_xyz2double.cpp
new file mode 100644
index 0000000..3d82a7d
--- /dev/null
+++ b/sci_gateway/cpp/opencv_xyz2double.cpp
@@ -0,0 +1,159 @@
+/* Function-xyz2double
+Author :Tess Zacharias */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+#include<math.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ // #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+#define REF_Y 1.00000;
+#define REF_Z 1.08883;
+
+
+int opencv_xyz2double(char *fname, unsigned long fname_len)
+{
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+
+ double check;
+ Mat img,dst;
+ float X,Y,Z;
+ int *piAddrNew = NULL;
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //checking if number of input arguments are 3
+
+ int k=0;
+ // SciErr getMatrixOfDoubleInList(void* _pvCtx, int* _piParent, int _iItemPos, int* _piRows, int* _piCols, double** _pdblReal)
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*iRows*iCols);
+ g1=(double *)malloc(sizeof(double)*iRows*iCols);
+ b1=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ // Vec3d intensity = img.at<Vec3d>(i,j);
+ X= (pstDataR[k]);
+ Y= (pstDataG[k]);
+ Z= (pstDataB[k++]);
+ r1[j*iRows+i]=X;
+ g1[j*iRows+i]=Y;
+ b1[j*iRows+i]=Z;
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
+
diff --git a/sci_gateway/cpp/opencv_xyz2lab.cpp b/sci_gateway/cpp/opencv_xyz2lab.cpp
new file mode 100644
index 0000000..2563e1c
--- /dev/null
+++ b/sci_gateway/cpp/opencv_xyz2lab.cpp
@@ -0,0 +1,423 @@
+/*--------------------------------------
+ function-xyz2lab
+ Author :Tess Zacharias
+------------------------------------- */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+ struct Color
+ {
+ float R,G,B,L,a,b;
+ };
+ Color xyz2lab1(float X, float Y, float Z)
+ {
+ /* colorspace conversion from xyz to lab */
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz,Ls,as,bs;
+ float xr=X/REF_X;
+ float yr=Y/REF_Y;
+ float zr=Z/REF_Z;
+ if ( xr > eps )
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if ( yr > eps )
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if ( zr > eps )
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Ls = ( 116 * fy ) - 16;
+ as = 500*(fx-fy);
+ bs = 200*(fy-fz);
+ Color lab;
+ lab.L =Ls;
+ lab.a =as;
+ lab.b =bs;
+ return lab;
+ }
+ Color xyz2lab2(float X, float Y, float Z,char *s)
+ {
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(strcasecmp(s,"a")==0)
+ {
+ REF_X1=1.0985;
+ REF_Y1= 1.0000;
+ REF_Z1=0.3558;
+ }
+ else if(strcasecmp(s,"c")==0)
+ {
+ REF_X1=0.9807;
+ REF_Y1= 1.0000;
+ REF_Z1=1.1822;
+ }
+ else if(strcasecmp(s,"d50")==0)
+ {
+ REF_X1=0.9642;
+ REF_Y1= 1.0000;
+ REF_Z1=0.8251;
+ }
+ else if(strcasecmp(s,"d65")==0)
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(strcasecmp(s,"icc")==0)
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ else if(strcasecmp(s,"d55")==0)
+ {
+ REF_X1=0.95682;
+ REF_Y1= 1.0000;
+ REF_Z1= 0.92149;
+ }
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz,Ls,as,bs;
+ float xr=X/REF_X1;
+ float yr=Y/REF_Y1;
+ float zr=Z/REF_Z1;
+ if ( xr > eps )
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if ( yr > eps )
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if ( zr > eps )
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Ls = ( 116 * fy ) - 16;
+ as = 500*(fx-fy);
+ bs = 200*(fy-fz);
+ Color lab;
+ lab.L =Ls;
+ lab.a =as;
+ lab.b =bs;
+ return lab;
+}
+Color xyz2lab3(float X, float Y, float Z,char *s)
+ {
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(strcasecmp(s,"sRGB")==0)
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(strcasecmp(s,"adobe-rgb-1998")==0)
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz,Ls,as,bs;
+ float xr=X/REF_X1;
+ float yr=Y/REF_Y1;
+ float zr=Z/REF_Z1;
+ if ( xr > eps )
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if ( yr > eps )
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if ( zr > eps )
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Ls = ( 116 * fy ) - 16;
+ as = 500*(fx-fy);
+ bs = 200*(fy-fz);
+ Color lab;
+ lab.L =Ls;
+ lab.a =as;
+ lab.b =bs;
+ return lab;
+}
+int opencv_xyz2lab(char *fname, unsigned long fname_len)
+{
+ SciErr sciErr;
+ int* piAddr1=NULL;
+ int* piAddr2=NULL;
+ int* piAddr3=NULL;
+ int* piAddrNew=NULL;
+ int iRows = 0;
+ int iCols = 0;
+ char* pstData = NULL;
+ char* pstData1 = NULL;
+ CheckInputArgument(pvApiCtx,1,3);
+ CheckOutputArgument(pvApiCtx,1,1);
+ int m=0;
+ int iType = 0;
+ double *value=NULL;
+ int iPrec= 0;
+ Mat img,k;
+ int iRet = 0;
+ int iRet1 = 0;
+ Color out;
+ float X,Y,Z;
+ sciErr =getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ sciErr = getVarType(pvApiCtx, piAddr1, &iType);
+ if(nbInputArgument(pvApiCtx)==3)
+ {
+ /*retrieve second argument */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 2,&piAddr2);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr2))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet = getAllocatedSingleString(pvApiCtx, piAddr2, &pstData);
+ }
+ }
+ else
+ {
+ sciprint(" The second argument should be string ");
+ return 0;
+ }
+ if((strcasecmp(pstData,"whitepoint")!=0)&&(strcasecmp(pstData,"Colorspace")!=0))
+ {
+ sciprint("\n Second argument should be any of these string :'whitepoint','Colorspace'");
+ return 0;
+ }
+ /*retrieve third argument */
+ sciErr = getVarAddressFromPosition(pvApiCtx, 3,&piAddr3);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ if(isStringType(pvApiCtx, piAddr3))
+ {
+ if(isScalar(pvApiCtx, piAddr2))
+ {
+ iRet1 = getAllocatedSingleString(pvApiCtx, piAddr3, &pstData1);
+ }
+ }
+ else
+ {
+ sciprint(" The third argument should be string ");
+ return 0;
+ }
+ if((strcasecmp(pstData,"whitepoint")==0))
+ {
+ if((strcasecmp(pstData1,"d65")!=0)&&(strcasecmp(pstData1,"d50")!=0)&&(strcasecmp(pstData1,"d55")!=0)&&(strcasecmp(pstData1,"icc")!=0)&&(strcasecmp(pstData1,"icc")!=0)&&(strcasecmp(pstData1,"a")!=0)&&(strcasecmp(pstData1,"c")!=0))
+ {
+ sciprint("\nIf Second argument is 'whitepoint' then Third argument should be any of these string :'a','d65','d55','d50','icc','c'");
+ return 0;
+ }
+ }
+ if((strcasecmp(pstData,"Colorspace")==0))
+ {
+ if((strcasecmp(pstData1,"sRGB")!=0)&&(strcasecmp(pstData1,"adobe-rgb-1998")!=0))
+ {
+ sciprint("\nIf Second argument is 'Colorspace' then Third argument should be any of these string :'sRGB','adobe-rgb-1998'");
+ return 0;
+ }
+ }
+ }
+ switch(iType)
+ {
+ case sci_matrix:
+ {
+ /*retrieve matrix values */
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols,&value);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ double *output=NULL;
+ output=( double *)malloc(sizeof(double)*iRows*iCols);
+ int j=0;
+ if(nbInputArgument(pvApiCtx)==1)
+ {
+ for(int i=0;i<iRows;i++)
+ {
+ out=xyz2lab1(value[j],value[j+1],value[j+2]);
+ output[j]=out.L;
+ output[j+1]=out.a;
+ output[j+2]=out.b;
+ j=j+3;
+ }
+ }
+ else if(nbInputArgument(pvApiCtx)==3)
+ {
+ for(int i=0;i<iRows;i++)
+ {
+ if(!strcasecmp(pstData1,"d65")||!strcasecmp(pstData1,"d50")||!strcasecmp(pstData1,"d55")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"a")||!strcasecmp(pstData1,"c"))
+ {
+ out=xyz2lab2(value[j],value[j+1],value[j+2],pstData1);
+ }
+ else if(!strcasecmp(pstData1,"sRGB")||!strcasecmp(pstData1,"adobe-rgb-1998"))
+ {
+ out=xyz2lab3(value[j],value[j+1],value[j+2],pstData1);
+ }
+ output[j]=out.L;
+ output[j+1]=out.a;
+ output[j+2]=out.b;
+ j=j+3;
+ }
+ }
+ sciErr = createMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1,iRows,iCols,output);
+ free(output);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ break;
+ }
+ case sci_list:
+ {
+ /*retrieve image value as list */
+ int k=0;
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr1, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ double *r1,*g1,*b1;
+ r1=(double *)malloc(sizeof(double)*iRows*iCols);
+ g1=(double *)malloc(sizeof(double)*iRows*iCols);
+ b1=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ X= (pstDataR[k]);
+ Y= (pstDataG[k]);
+ Z= (pstDataB[k++]);
+ if(nbInputArgument(pvApiCtx)==1)
+ {
+ out=xyz2lab1(X,Y,Z);
+ }
+ if(nbInputArgument(pvApiCtx)==3)
+ {
+ if(!strcasecmp(pstData1,"d65")||!strcasecmp(pstData1,"d50")||!strcasecmp(pstData1,"d55")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"icc")||!strcasecmp(pstData1,"a")||!strcasecmp(pstData1,"c"))
+ {
+ out=xyz2lab2(X,Y,Z,pstData1);
+ }
+ else if(!strcasecmp(pstData1,"sRGB")||!strcasecmp(pstData1,"adobe-rgb-1998"))
+ {
+ out=xyz2lab3(X,Y,Z,pstData1);
+ }
+ }
+ r1[m]=out.L;
+ g1[m]=out.a;
+ b1[m++]=out.b;
+ }
+ }
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ break;
+ }
+ default:
+ sciprint("input argument should be either of double matrix or image !\n"); // Should never happen
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}
diff --git a/sci_gateway/cpp/opencv_xyz2rgb.cpp b/sci_gateway/cpp/opencv_xyz2rgb.cpp
new file mode 100644
index 0000000..cafe54a
--- /dev/null
+++ b/sci_gateway/cpp/opencv_xyz2rgb.cpp
@@ -0,0 +1,280 @@
+/* ==================================================================== */
+/* Author :Tess Zacharias */
+/* ==================================================================== */
+/* overloaded function */
+/* Syntax : return_matrix_3_xyz_values=lab2xyz(matrix_of_3_labvalues a) */
+/* Syntax : return_matrix_3_xyz_values=lab2xyz(matrix_of_3_labvalues a,String1 Name,String2 value) */
+/* ==================================================================== */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ // #include "../common.h"
+ #define REF_X .95047; // Observer= 2°, Illuminant= D65
+#define REF_Y 1.00000;
+#define REF_Z 1.08883;
+
+struct Color
+{
+ float X,Y,Z,R,G,B;
+};
+
+Color xyz2rgb1(float X, float Y, float Z)
+{
+
+ float x = X;
+ float y = Y;
+ float z = Z;
+ float R1 = 3.2404542*x-1.5371385*y-0.4985314*z;
+ float G1 =-0.9692660*x+1.8760108*y+0.0415560 *z;
+ float B1 = 0.0556434*x-0.2040259*y+1.0572252*z;
+ if( R1 > 0.0031308 )
+ R1 = 1.055 * ( pow( R1, 1./2.4 ) ) - 0.055;
+ else
+ R1 = 12.92 * R1;
+ if( G1 > 0.0031308 )
+ G1 = 1.055 * ( pow( G1, 1./2.4 ) ) - 0.055;
+ else
+ G1 = 12.92 * G1;
+ if( B1 > 0.0031308 )
+ B1 = 1.055 * ( pow( B1, 1./2.4 ) ) - 0.055;
+ else
+ B1= 12.92 * B1;
+
+ /*R1 = R1*REF_X;
+ G1 = G1*REF_Y;
+ B1 = B1*REF_Z; */
+ /* R1 = R1 * 255;
+ G1 = G1 * 255;
+ B1 = B1 * 255;*/
+ Color rgb;
+ rgb.R= R1;
+ rgb.G= G1;
+ rgb.B= B1;
+ return rgb;
+
+}
+ Color xyz2rgb2(float X, float Y, float Z,char *s)
+{
+ double REF_X1;
+ double REF_Y1;
+ double REF_Z1;
+ if(!strcmp(s,"a"))
+ {
+ REF_X1=1.0985;
+ REF_Y1= 1.0000;
+ REF_Z1=0.3558;
+ }
+ else if(!strcmp(s,"c"))
+ {
+ REF_X1=0.9807;
+ REF_Y1= 1.0000;
+ REF_Z1=1.1822;
+ }
+ else if(!strcmp(s,"d50"))
+ {
+ REF_X1=0.9642;
+ REF_Y1= 1.0000;
+ REF_Z1=0.8251;
+ }
+ else if(!strcmp(s,"d65"))
+ {
+ REF_X1=0.9504;
+ REF_Y1= 1.0000;
+ REF_Z1= 1.0888;
+ }
+ else if(!strcmp(s,"icc"))
+ {
+ REF_X1=0.962;
+ REF_Y1=1.000;
+ REF_Z1= 0.8249;
+ }
+ else if(!strcmp(s,"e"))
+ {
+ REF_X1=1.000;
+ REF_Y1=1.000;
+ REF_Z1=1.000;
+ }
+ float x = X;
+ float y = Y;
+ float z = Z;
+ float R1 = 3.2406*x-1.5372*y-0.4986*z;
+ float G1 =-0.9689*x+1.8758*y+0.0415 *z;
+ float B1 = 0.0557*x-0.2040*y+1.0570*z;
+ if( R1 > 0.0031308 )
+ R1 = 1.055 * ( pow( R1, 1./2.4 ) ) - 0.055;
+ else
+ R1 = 12.92 * R1;
+ if( G1 > 0.0031308 )
+ G1 = 1.055 * ( pow( G1, 1./2.4 ) ) - 0.055;
+ else
+ G1 = 12.92 * G1;
+ if( B1 > 0.0031308 )
+ B1 = 1.055 * ( pow( B1, 1./2.4 ) ) - 0.055;
+ else
+ B1= 12.92 * B1;
+
+ /*R1 = R1*REF_X;
+ G1 = G1*REF_Y;
+ B1 = B1*REF_Z;*/
+ /* R1 = R1 * 255;
+ G1 = G1 * 255;
+ B1 = B1 * 255; */
+ Color rgb;
+ rgb.R= R1;
+ rgb.G= G1;
+ rgb.B= B1;
+ return rgb;
+
+
+}
+ int opencv_xyz2rgb(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ int* piLen = NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img,dst;
+ float X,Y,Z;
+ int *piAddrNew = NULL;
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //checking if number of input arguments are 3
+
+ int k=0;
+ // SciErr getMatrixOfDoubleInList(void* _pvCtx, int* _piParent, int _iItemPos, int* _piRows, int* _piCols, double** _pdblReal)
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ double *r,*g,*b;
+ r=(double *)malloc(sizeof(double)*iRows*iCols);
+ g=(double *)malloc(sizeof(double)*iRows*iCols);
+ b=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ // Vec3d intensity = img.at<Vec3d>(i,j);
+ X= (pstDataR[k]);
+ Y= (pstDataG[k]);
+ Z= (pstDataB[k++]);
+ out=xyz2rgb1(X,Y,Z);
+ //cout<<R<<"\n";
+ //cout<<G<<"\n";
+ //cout<<B<<"\n";
+ r[m]=(out.R);
+ g[m]=(out.G);
+ b[m++]=(out.B);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ //Adding the R value matrix to the list
+ //Syntax : createMatrixOfInteger32InList(void* _pvCtx, int _iVar, int* _piParent, int _iItemPos, int _iRows, int _iCols, const int* _piData)
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the G value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ //Adding the B value matrix to the list
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
diff --git a/sci_gateway/cpp/opencv_xyz2uint16.cpp b/sci_gateway/cpp/opencv_xyz2uint16.cpp
new file mode 100644
index 0000000..969cb68
--- /dev/null
+++ b/sci_gateway/cpp/opencv_xyz2uint16.cpp
@@ -0,0 +1,146 @@
+/*--------------------------------------
+ function-lab2uint16
+ Author :Tess Zacharias
+------------------------------------- */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ struct Color
+ {
+ float R,G,B,X,Y,Z;
+ };
+ Color xyz2uint16(float X, float Y, float Z)
+ {
+ /* xyz to uint16 conversion */
+ float R1=round((65535 * (X / (1 + (32767/32768))))/2);
+ float G1=round((65535 * (Y / (1 + (32767/32768))))/2);
+ float B1=round((65535 * (Z / (1 + (32767/32768))))/2);
+
+ Color rgb;
+ rgb.R = R1;
+ rgb.G = G1;
+ rgb.B = B1;
+ return rgb;
+ }
+ int opencv_xyz2uint16(char *fname, unsigned long fname_len)
+ {
+ SciErr sciErr;
+ int iRows= 0;
+ int iCols= 0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ int i,j;
+ int error;
+ Color out;
+ float X,Y,Z;
+ int *piAddrNew = NULL;
+ CheckOutputArgument(pvApiCtx,1,1);
+ int k=0;
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 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 = getMatrixOfDoubleInList(pvApiCtx, piAddr, 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 = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ int m=0;
+ unsigned short *r1,*g1,*b1;
+ r1=(unsigned short *)malloc(sizeof(unsigned short )*iRows*iCols);
+ g1=(unsigned short *)malloc(sizeof(unsigned short )*iRows*iCols);
+ b1=(unsigned short *)malloc(sizeof(unsigned short )*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ X= (pstDataR[k]);
+ Y= (pstDataG[k]);
+ Z= (pstDataB[k++]);
+ out=xyz2uint16(X,Y,Z);
+ r1[m]=(out.R);
+ g1[m]=(out.G);
+ b1[m++]=(out.B);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r1);
+ free(r1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g1);
+ free(g1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = createMatrixOfUnsignedInteger16InList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b1);
+ free(b1);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+}
+
diff --git a/sci_gateway/cpp/rgb2gray.cpp b/sci_gateway/cpp/rgb2gray.cpp
new file mode 100644
index 0000000..d696bb6
--- /dev/null
+++ b/sci_gateway/cpp/rgb2gray.cpp
@@ -0,0 +1,46 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_image=rgb2gray(sourceimage) */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp" //new header file for cvtColor function of opencv
+#include <iostream>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "BOOL.h"
+#include <localization.h>
+#include<string.h>
+#include "../common.h"
+int opencv_rgb2gray(char *fname, unsigned long fname_len)
+{
+
+ // Error management variable
+ SciErr sciErr;
+ //checking input argument
+ CheckInputArgument(pvApiCtx,1,1);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1)
+ Mat img,grayimg;
+ //calling function
+ retrieveImage(img,1);
+ cvtColor(img, grayimg, CV_BGR2GRAY );
+ string tempstring = type2str(grayimg.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,grayimg,1);
+ //returning output variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/rgb2gray.cpp~ b/sci_gateway/cpp/rgb2gray.cpp~
new file mode 100644
index 0000000..c422638
--- /dev/null
+++ b/sci_gateway/cpp/rgb2gray.cpp~
@@ -0,0 +1,46 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : return_image=rgb2gray(sourceimage) */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include "opencv2/imgproc/imgproc.hpp" //new header file for cvtColor function of opencv
+#include <iostream>
+using namespace cv;
+using namespace std;
+extern "C"
+{
+#include "api_scilab.h"
+#include "Scierror.h"
+#include "BOOL.h"
+#include <localization.h>
+#include<string.h>
+#include "../common.h"
+int rgb2gray(char *fname, unsigned long fname_len)
+{
+
+ // Error management variable
+ SciErr sciErr;
+ //checking input argument
+ CheckInputArgument(pvApiCtx,1,1);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1)
+ Mat img,grayimg;
+ //calling function
+ retrieveImage(img,1);
+ cvtColor(img, grayimg, CV_BGR2GRAY );
+ string tempstring = type2str(grayimg.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,grayimg,1);
+ //returning output variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+}
+
+/* ==================================================================== */
+}
diff --git a/sci_gateway/cpp/warpaffine.cpp b/sci_gateway/cpp/warpaffine.cpp
new file mode 100644
index 0000000..014876b
--- /dev/null
+++ b/sci_gateway/cpp/warpaffine.cpp
@@ -0,0 +1,214 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* Syntax : rotated_image=warpaffline(InputArray src, InputArray M,int size_x,int size_y ,string flag, string borderMode); */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include <sciprint.h>
+using namespace cv;
+using namespace std;
+ extern "C"
+ {
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ int warpaffine(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows = 0;
+ int iCols = 0;
+ int piRows = 0;
+ int piCols = 0;
+ int* piAddr = NULL;
+ int *piAddr7 =NULL;
+ int* piAddr2 = NULL;
+ int* piAddr3 = NULL;
+ int* piAddr4 = NULL;
+ int* piAddr5 = NULL;
+ int* piAddr6 = NULL;
+ int* piAddrNew = NULL;
+ int* piLen = NULL;
+ double* pstData = NULL;
+ int* pstData2 = NULL;
+ double *rrows;
+ double *rcols;
+ int error;
+
+ ////checking input argument
+ CheckInputArgument(pvApiCtx,6,6);
+ //checking output argument
+ CheckOutputArgument(pvApiCtx, 1, 1);
+ //for first argument
+ // get Address of first input
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ //retrieving image
+ Mat img,dst;
+ retrieveImage(img,1);
+ //second argument
+ double *m;
+ //fetching address of second argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,2,&piAddr2);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of second argument
+ sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols ,&m);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+
+ Mat m1=Mat(2,3,CV_64F);
+ int k=0;
+ for(int j=0;j<3;j++)
+ {
+ for(int i=0;i<2;i++)
+ {
+ m1.at<double>(i,j)=m[k++];
+ // cout<< m1.at<double>(i,j)<<"\n";
+ }
+ }
+
+ cout<<m1;
+ //third argument
+ double sz1,sz2;
+ //fetching address of third argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
+ //checking for error if any
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of third argument
+ error=getScalarDouble(pvApiCtx,piAddr3,&sz1);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //fourth argument
+ //fetching address of fourth argument
+ sciErr = getVarAddressFromPosition(pvApiCtx,4,&piAddr4);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of fourth argument
+ error=getScalarDouble(pvApiCtx,piAddr4,&sz2);
+ if(error!=0)
+ {
+ sciprint("error in retrieving second argument");
+ }
+ //fifth argument
+ //fetching address of fifth argument
+ char **flag;
+ sciErr = getVarAddressFromPosition(pvApiCtx,5,&piAddr5);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr5, &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, piAddr5, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ flag = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ {
+ flag[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, piAddr5, &iRows, &iCols, piLen,flag);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //this function will fetch value of fifth argument
+
+//sixth argument
+ //fetching address of sixth argument
+ char **bordermode;
+ sciErr = getVarAddressFromPosition(pvApiCtx,6,&piAddr6);
+ if (sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ sciErr = getMatrixOfString(pvApiCtx, piAddr6, &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, piAddr6, &iRows, &iCols, piLen, NULL);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ bordermode = (char**)malloc(sizeof(char*) * iRows * iCols);
+ for(int i = 0 ; i < iRows * iCols ; i++)
+ {
+ bordermode[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, piAddr6, &iRows, &iCols, piLen,bordermode);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //calling size constructor
+ Size ksize=Size(sz1,sz2);
+
+
+
+
+ //calling warpaffline function
+
+ int flag1,border;
+ if(!strcmp(flag[0],"INTER_NEAREST"))
+ flag1=INTER_LINEAR;
+ else if(!strcmp(flag[0],"INTER_LINEAR"))
+ flag1=INTER_LINEAR;
+ else if(!strcmp(flag[0],"INTER_AREA"))
+ flag1=INTER_AREA;
+ else if(!strcmp(flag[0],"INTER_CUBIC"))
+ flag1=INTER_CUBIC;
+ else if(!strcmp(flag[0],"INTER_LANCZOS4"))
+ flag1=INTER_LANCZOS4;
+ if(!strcmp(bordermode[0]," BORDER_TRANSPARENT"))
+ border=BORDER_TRANSPARENT;
+ else if(!strcmp(bordermode[0],"BORDER_CONSTANT"))
+ border=BORDER_CONSTANT;
+ else if(!strcmp(bordermode[0],"BORDER_WRAP"))
+ border=BORDER_WRAP;
+ else if(!strcmp(bordermode[0],"BORDER_REFLECT_101"))
+ border=BORDER_REFLECT_101;
+ warpAffine(img, dst,m1, ksize,flag1,border);
+ string tempstring = type2str(dst.type());
+ char* checker = (char *)malloc(tempstring.size() + 1);
+ memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
+ returnImage(checker,dst,1);
+ //returning output variable
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+
+}
+}
diff --git a/sci_gateway/cpp/xyz2lab.cpp b/sci_gateway/cpp/xyz2lab.cpp
new file mode 100644
index 0000000..fc60ea7
--- /dev/null
+++ b/sci_gateway/cpp/xyz2lab.cpp
@@ -0,0 +1,189 @@
+/* ==================================================================== */
+/* Author :Priyanka Hiranandani NIT Surat */
+/* ==================================================================== */
+/* overloaded function */
+/* Syntax : return_matrix_3_xyz_values=xyz2lab(matrix_of_3_labvalues a) */
+/* ==================================================================== */
+/* ==================================================================== */
+#include <numeric>
+#include "opencv2/core/core.hpp"
+#include "opencv2/highgui/highgui.hpp"
+#include "opencv2/opencv.hpp"
+#include <iostream>
+#include<stdio.h>
+#include <sciprint.h>
+#include<string.h>
+using namespace cv;
+using namespace std;
+
+extern "C"
+{
+ #include "api_scilab.h"
+ #include "Scierror.h"
+ #include "BOOL.h"
+ #include <localization.h>
+ #include "../common.h"
+ #define REF_X .9504; // Observer= 2°, Illuminant= D65
+ #define REF_Y 1.00000;
+ #define REF_Z 1.08883;
+
+ struct Color
+ {
+ float R,G,B,X,Y,Z,L,a,b;
+ };
+
+ Color xyz2lab3(float X,float Y, float Z)
+ {
+ float eps = 216.f/24389.f;
+ float k = 24389.f/27.f;
+ float fx,fy,fz,Ls,as,bs;
+ float xr=X/REF_X;
+ float yr=Y/REF_Y;
+ float zr=Z/REF_Z;
+ if (xr > eps)
+ fx = (float)pow(xr, 1/3.);
+ else
+ fx = (float) ((k * xr + 16.) / 116.);
+ if (yr > eps)
+ fy = (float)pow(yr, 1/3.);
+ else
+ fy = (float) ((k * yr + 16.) / 116.);
+ if (zr > eps)
+ fz = (float)pow(zr, 1/3.);
+ else
+ fz = (float) ((k * zr + 16.) / 116);
+ Ls = ( 116 * fy ) - 16;
+ as = 500*(fx-fy);
+ bs = 200*(fy-fz);
+ Color lab;
+ lab.L =Ls;
+ lab.a =as;
+ lab.b =bs;
+ return lab;
+ }
+
+
+ int xyz2lab(char *fname, unsigned long fname_len)
+ {
+ // Error management variable
+ SciErr sciErr;
+ //variable info
+ int iRows=0;
+ int iCols=0;
+ int piRows=0;
+ int piCols=0;
+ int* piAddr=NULL;
+ int* piAddr1=NULL;
+ int* piAddr3=NULL;
+ double *value=NULL;
+ double *pstDataR = NULL;
+ double *pstDataG = NULL;
+ double *pstDataB = NULL;
+ int* piLen= NULL;
+ char **val;
+ int i,j;
+ int error;
+ Color out;
+ double check;
+ Mat img,dst;
+ float R,G,B;
+ int *piAddrNew = NULL;
+ double *r,*g,*b;
+ int k=0;
+ //checking output argument
+ CheckOutputArgument(pvApiCtx,1,1);
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the R values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 1, &iRows, &iCols, &pstDataR);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the G values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 2, &iRows, &iCols, &pstDataG);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive address of the list
+ sciErr = getVarAddressFromPosition(pvApiCtx,1,&piAddr);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //retrive the matrix of the B values
+ sciErr = getMatrixOfDoubleInList(pvApiCtx, piAddr, 3, &iRows, &iCols, &pstDataB);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //dynamically allocating memory to varibles
+ r=(double *)malloc(sizeof(double)*iRows*iCols);
+ g=(double *)malloc(sizeof(double)*iRows*iCols);
+ b=(double *)malloc(sizeof(double)*iRows*iCols);
+ for(int i=0;i<iRows;i++)
+ {
+ for(int j=0;j<iCols;j++)
+ {
+ R=(pstDataR[k]);
+ G=(pstDataG[k]);
+ B= (pstDataB[k++]);
+ out=xyz2lab3(R,G,B);
+ r[j*iRows+i]=(out.L);
+ g[j*iRows+i]=(out.a);
+ b[j*iRows+i]=(out.b);
+ }
+ }
+
+ sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, 3, &piAddrNew);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the R value matrix to the list to be returned
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 1, iRows,iCols, r);
+ free(r);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the G value matrix to the list to be returned
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 2, iRows, iCols, g);
+ free(g);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ //Adding the B value matrix to the list to be returned
+ sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx)+1 , piAddrNew, 3, iRows, iCols, b);
+ free(b);
+ if(sciErr.iErr)
+ {
+ printError(&sciErr, 0);
+ return 0;
+ }
+ AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
+ ReturnArguments(pvApiCtx);
+ return 0;
+ }
+}