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
|
/***************************************************
Author : Deepshikha
***************************************************/
#include <numeric>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <iostream>
using namespace cv;
using namespace std;
extern "C"
{
#include "api_scilab.h"
#include "Scierror.h"
#include "BOOL.h"
#include <localization.h>
#include <sciprint.h>
#include "../common.h"
int opencv_triangulatePoints(char *fname, unsigned long fname_len)
{
//variables
int i,j,n,m;
int iRows=0,iCols=0;
int *piAddr1 = NULL;
int *piAddr2 = NULL;
int *piAddr3 = NULL;
int *piAddr4 = NULL;
double *pdblReal = NULL;
SciErr sciErr;
/*------------------------------------------- Checking Input Argument ----------------------------------------------------*/
CheckInputArgument(pvApiCtx, 4, 4);
CheckOutputArgument(pvApiCtx, 1, 1) ;
/*------------------------------------- Projection matrix 1 :- First argument of the input -------------------------------------*/
sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr1, &iRows, &iCols, &pdblReal);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
if(iRows!=3 or iCols!=4){
Scierror(iRows,"Projection matrix (arg 1) must be a 3 X 4 matrix");
return 0;
}
Mat projMat1(iRows, iCols, CV_64F);
for(i = 0; i < iRows; i++)
for(j = 0; j < iCols; j++){
projMat1.at<double>(i,j) = pdblReal[i + (j * iRows)];
}
/* ------------------------------------ Projection matrix 2 :- Second argument of the input -------------------------------------*/
sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr2);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr2, &iRows, &iCols, &pdblReal);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
if(iRows!=3 or iCols!=4){
Scierror(iRows,"Projection matrix (arg 2) must be a 3 X 4 matrix");
return 0;
}
Mat projMat2(iRows, iCols, CV_64F);
for(i=0;i<iRows;i++)
for(j=0;j<iCols;j++)
projMat2.at<double>(i,j) = pdblReal[i + (j * iRows)];
/* ------------------------------------ Points matrix 1 :- Third argument of the input -------------------------------------*/
sciErr = getVarAddressFromPosition(pvApiCtx,3,&piAddr3);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr3, &iRows, &iCols, &pdblReal);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
n = iCols;
if(iRows!=2){
Scierror(iRows,"Points matrix (arg 3) must be a 2 X N matrix");
return 0;
}
Mat newPoint1(2, iCols, CV_64F);
for(i = 0; i < 2; i++)
for(j = 0; j < iCols; j++)
newPoint1.at<double>(i,j) = pdblReal[ i + ( j * iRows )];
/* ------------------------------------ Points matrix 2 :- Fourth argument of the input -------------------------------------*/
sciErr = getVarAddressFromPosition(pvApiCtx, 4, &piAddr4);
if (sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
sciErr = getMatrixOfDouble(pvApiCtx, piAddr4, &iRows, &iCols, &pdblReal);
if(sciErr.iErr)
{
printError(&sciErr, 0);
return 0;
}
m = iCols;
if(iRows!=2){
Scierror(iRows,"Points matrix (arg 4) must be a 2 X N matrix");
return 0;
}
Mat newPoint2(iRows, iCols, CV_64F);
for(i = 0; i < iRows; i++)
for(j = 0; j < iCols; j++)
newPoint2.at<double>(i,j) = pdblReal[ i + ( j * iRows )];
if(n!=m){
Scierror(n,"No of columns of arg 3 and arg 4 must be same");
return 0;
}
Mat new_image(4, n, CV_64F);
triangulatePoints(projMat1, projMat2, newPoint1, newPoint2, new_image);
string tempstring = type2str(new_image.type());
char *checker;
checker = (char *)malloc(tempstring.size() + 1);
memcpy(checker, tempstring.c_str(), tempstring.size() + 1);
returnImage(checker,new_image,1);
free(checker);
//Assigning the list as the Output Variable
AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
//Returning the Output Variables as arguments to the Scilab environment
ReturnArguments(pvApiCtx);
return 0;
}
/* ==================================================================== */
}
|