summaryrefslogtreecommitdiff
path: root/sci_gateway/cpp/warpaffine.cpp
blob: 014876bed615f278eaf0ed28c3de9c5f84bdd5b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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);   
                  
}
}