forked from xidianzhanglei/Single-perspective-warps-multiple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetLocation.cpp
63 lines (51 loc) · 1.44 KB
/
getLocation.cpp
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
#include "mex.h"
#include <time.h>
#include <math.h>
#include <string.h>
/*Round function.*/
double round(double x) { return (x-floor(x))>0.5 ? ceil(x) : floor(x); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
/* Input/output variables. */
double *data;
double *xk;
double *idx;
/* Intermediate variables.*/
int datam,datan;
int i, j;
/* Check for proper number of arguments. */
if (nrhs != 2)
{
mexErrMsgTxt("Two inputs required.");
}
else if (nlhs > 1)
{
mexErrMsgTxt("Wrong number of output arguments.");
}
/* Assign pointers to inputs. */
data = mxGetPr(prhs[0]);
xk = mxGetPr(prhs[1]);
/* Get sizes of input matrices (images, transformations, etc.).*/
datam = mxGetM(prhs[0]);
datan = mxGetN(prhs[0]);
/* Create matrix for the return arguments. */
plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
/* Assign pointers to output canvas (warped image2). */
idx = mxGetPr(plhs[0]);
/* Start computations. */
/* For each pixel in the target image... */
idx[0] = 0;
for(i=0;i<datam;i++)
{
if(data[i] == xk[0]){
for(j=1;j<datan && data[(datam*j)+i] == xk[j];j++);
if(j==datan)
{
idx[0] = i+1;
return;
}
}
}
/* Bye bye.*/
return;
}