mexopencv  3.4.1
MEX interface for OpenCV library
SeamFinder_.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 }
23 
31 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
32 {
33  // Check the number of arguments
34  nargchk(nrhs>=2 && nlhs<=1);
35 
36  // Argument vector
37  vector<MxArray> rhs(prhs, prhs+nrhs);
38  int id = rhs[0].toInt();
39  string method(rhs[1].toString());
40 
41  // Constructor is called. Create a new object from argument
42  if (method == "new") {
43  nargchk(nrhs>=3 && nlhs<=1);
45  rhs[2].toString(), rhs.begin() + 3, rhs.end());
46  plhs[0] = MxArray(last_id);
47  mexLock();
48  return;
49  }
50 
51  // Big operation switch
52  Ptr<SeamFinder> obj = obj_[id];
53  if (obj.empty())
54  mexErrMsgIdAndTxt("mexopencv:error", "Object not found id=%d", id);
55  if (method == "delete") {
56  nargchk(nrhs==2 && nlhs==0);
57  obj_.erase(id);
58  mexUnlock();
59  }
60  else if (method == "typeid") {
61  nargchk(nrhs==2 && nlhs<=1);
62  plhs[0] = MxArray(string(typeid(*obj).name()));
63  }
64  else if (method == "find") {
65  nargchk(nrhs==5 && nlhs<=1);
66 
67  vector<Point> corners(rhs[3].toVector<Point>());
68  vector<UMat> src, masks;
69  {
70  vector<MxArray> arr(rhs[2].toVector<MxArray>());
71  src.reserve(arr.size());
72  for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
73  src.push_back(it->toMat().getUMat(ACCESS_READ));
74  }
75  {
76  vector<MxArray> arr(rhs[4].toVector<MxArray>());
77  masks.reserve(arr.size());
78  for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
79  masks.push_back(it->toMat(CV_8U).getUMat(ACCESS_RW));
80  }
81  obj->find(src, corners, masks);
82  vector<Mat> masks_;
83  masks_.reserve(masks.size());
84  for (vector<UMat>::const_iterator it = masks.begin(); it != masks.end(); ++it)
85  masks_.push_back(it->getMat(ACCESS_READ));
86  plhs[0] = MxArray(masks_);
87  }
88  else
89  mexErrMsgIdAndTxt("mexopencv:error",
90  "Unrecognized operation %s", method.c_str());
91 }
Common definitions for the stitching module.
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: SeamFinder_.cpp:31
#define CV_8U
STL namespace.
map< int, Ptr< SeamFinder > > obj_
Object container.
Definition: SeamFinder_.cpp:21
T end(T... args)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
STL class.
int last_id
Last object id to allocate.
Definition: SeamFinder_.cpp:19
ACCESS_RW
T push_back(T... args)
cv::Ptr< cv::detail::SeamFinder > createSeamFinder(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of SeamFinder using options in arguments.
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.
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
virtual void find(const std::vector< UMat > &src, const std::vector< Point > &corners, std::vector< UMat > &masks)=0
T size(T... args)
STL class.
bool empty() const
Global constant definitions.
T begin(T... args)
ACCESS_READ
T c_str(T... args)
T reserve(T... args)