mexopencv  3.4.1
MEX interface for OpenCV library
Timelapser_.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
10 #include "opencv2/stitching.hpp"
11 #include <typeinfo>
12 using namespace std;
13 using namespace cv;
14 using namespace cv::detail;
15 
16 // Persistent objects
17 namespace {
19 int last_id = 0;
22 
27 }
28 
36 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
37 {
38  // Check the number of arguments
39  nargchk(nrhs>=2 && nlhs<=1);
40 
41  // Argument vector
42  vector<MxArray> rhs(prhs, prhs+nrhs);
43  int id = rhs[0].toInt();
44  string method(rhs[1].toString());
45 
46  // Constructor is called. Create a new object from argument
47  if (method == "new") {
48  nargchk(nrhs==3 && nlhs<=1);
49  string type(rhs[2].toString());
50  obj_[++last_id] = Timelapser::createDefault(TimelapserTypesMap[type]);
51  plhs[0] = MxArray(last_id);
52  mexLock();
53  return;
54  }
55 
56  // Big operation switch
57  Ptr<Timelapser> obj = obj_[id];
58  if (obj.empty())
59  mexErrMsgIdAndTxt("mexopencv:error", "Object not found id=%d", id);
60  if (method == "delete") {
61  nargchk(nrhs==2 && nlhs==0);
62  obj_.erase(id);
63  mexUnlock();
64  }
65  else if (method == "typeid") {
66  nargchk(nrhs==2 && nlhs<=1);
67  plhs[0] = MxArray(string(typeid(*obj).name()));
68  }
69  else if (method == "initialize") {
70  nargchk(nrhs==4 && nlhs==0);
71  vector<Point> corners(rhs[2].toVector<Point>());
72  vector<Size> sizes(rhs[3].toVector<Size>());
73  obj->initialize(corners, sizes);
74  }
75  else if (method == "process") {
76  nargchk(nrhs==5 && nlhs==0);
77  Mat img(rhs[2].toMat(CV_16S));
78  Mat mask(rhs[3].toMat(CV_8U));
79  Point tl(rhs[4].toPoint());
80  obj->process(img, mask, tl);
81  }
82  else if (method == "getDst") {
83  nargchk(nrhs==2 && nlhs<=1);
84  Mat dst(obj->getDst().getMat(ACCESS_READ));
85  plhs[0] = MxArray(dst);
86  }
87  else
88  mexErrMsgIdAndTxt("mexopencv:error",
89  "Unrecognized operation %s", method.c_str());
90 }
virtual void initialize(const std::vector< Point > &corners, const std::vector< Size > &sizes)
Common definitions for the stitching module.
map< int, Ptr< Timelapser > > obj_
Object container.
Definition: Timelapser_.cpp:21
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
STL class.
virtual const UMat & getDst()
const ConstMap< std::string, int > TimelapserTypesMap
time lapser types
Definition: Timelapser_.cpp:24
Mat getMat(int flags) const
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: Timelapser_.cpp:36
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/output arguments number check.
Definition: mexopencv.hpp:181
STL class.
bool empty() const
Global constant definitions.
#define CV_16S
ACCESS_READ
T c_str(T... args)
int type() const
std::map wrapper with one-line initialization and lookup method.
Definition: MxArray.hpp:927
int last_id
Last object id to allocate.
Definition: Timelapser_.cpp:19
cv::Mat toMat() const
virtual void process(InputArray img, InputArray mask, Point tl)