summaryrefslogtreecommitdiff
path: root/sci_gateway1/cpp/opencv_bbox2points.cpp
diff options
context:
space:
mode:
authorshamikam2017-01-16 02:56:17 +0530
committershamikam2017-01-16 02:56:17 +0530
commita6df67e8bcd5159cde27556f4f6a315f8dc2215f (patch)
treee806e966b06a53388fb300d89534354b222c2cad /sci_gateway1/cpp/opencv_bbox2points.cpp
downloadFOSSEE_Image_Processing_Toolbox-master.tar.gz
FOSSEE_Image_Processing_Toolbox-master.tar.bz2
FOSSEE_Image_Processing_Toolbox-master.zip
First CommitHEADmaster
Diffstat (limited to 'sci_gateway1/cpp/opencv_bbox2points.cpp')
-rw-r--r--sci_gateway1/cpp/opencv_bbox2points.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/sci_gateway1/cpp/opencv_bbox2points.cpp b/sci_gateway1/cpp/opencv_bbox2points.cpp
new file mode 100644
index 0000000..975fc00
--- /dev/null
+++ b/sci_gateway1/cpp/opencv_bbox2points.cpp
@@ -0,0 +1,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;
+}
+/* ==================================================================== */
+}