summaryrefslogtreecommitdiff
path: root/sci_gateway1/cpp/opencv_bbox2points.cpp
blob: 975fc00deda317e769ca85c6eae4d454c42386ff (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
/***************************************************
Author : Tanmay Chaudhari
***************************************************/

#include <numeric>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include <bits/stdc++.h>
using namespace cv;
using namespace std;
extern "C"
{
    #include "api_scilab.h"
    #include "Scierror.h"
    #include "BOOL.h"
    #include <localization.h>
    #include "sciprint.h"
 //   #include "../common.h"
 //   #include "../common.cpp"

int opencv_bbox2points()
{
	//Error management variable
	SciErr sciErr;
	
	//Variable declaration
	int i;
	int iComplex = 0;
	int iType = 0;
	int iRows = 0;
	int iCols = 0;
	int *piAddr = NULL;
	double *pdblReal = NULL;
	double *points;

	//Check input output arguments
	checkInputArgument(pvApiCtx, 1, 1);
	checkOutputArgument(pvApiCtx, 1, 1);

	//Get variable address of the first input arguent
	sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
	if(sciErr.iErr)
	{		
		printError(&sciErr, 0);
		return 0;
	}

	//Check type
	sciErr = getVarType(pvApiCtx, piAddr, &iType);
	if(sciErr.iErr || iType != sci_matrix)
	{
		printError(&sciErr, 0);
		return 0;
	}

	//Get complexity
	iComplex = isVarComplex(pvApiCtx, piAddr);
	
	//Check complexity
	if(iComplex)
	{
		Scierror(999, "%s: Wrong type for input argument: A complex number is not expected.\n");
		return 0;
	}
	
	sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &iRows, &iCols, &pdblReal);
	if(sciErr.iErr || iCols != 4 || iRows == 0)
	{
		printError(&sciErr, 0);
		return 0;
	}
	
	sciErr = createList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, &piAddr);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}

	for( i = 0; i < iRows; i++)					//Rows in box
	{
		points = (double*)malloc(sizeof(double) * 8);
		memset(points, 0, sizeof(points));

		//Upper-left
		points[0] = pdblReal[i];
		points[4] = pdblReal[i + iRows];	

		//Upper-right
		points[1] = pdblReal[i] + pdblReal[i + 2 * iRows];
		points[5] = pdblReal[i + iRows];

		//Lower-right
		points[2] = pdblReal[i] + pdblReal[i + 2 * iRows];
		points[6] = pdblReal[i + iRows] + pdblReal[i+ 3 * iRows];

		//Lower-left
		points[3] = pdblReal[i];
		points[7] = pdblReal[i + iRows] + pdblReal[i + 3 * iRows];

		sciErr = createMatrixOfDoubleInList(pvApiCtx, nbInputArgument(pvApiCtx) + 1, piAddr, i + 1, 4, 2, points);
		if(sciErr.iErr)
		{
			printError(&sciErr, 0);
			return 0;
		}
	}

	//Return output arguments
	AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
	ReturnArguments(pvApiCtx);
	
	return 0;
}
/* ==================================================================== */
}