mexopencv  3.4.1
MEX interface for OpenCV library
ExposureCompensator_.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
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 == "feed") {
65  nargchk(nrhs==5 && nlhs==0);
66  vector<Point> corners(rhs[2].toVector<Point>());
67  vector<UMat> images, masks;
68  {
69  vector<MxArray> arr(rhs[3].toVector<MxArray>());
70  images.reserve(arr.size());
71  for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
72  images.push_back(it->toMat(CV_8U).getUMat(ACCESS_READ).clone());
73  }
74  {
75  vector<MxArray> arr(rhs[4].toVector<MxArray>());
76  masks.reserve(arr.size());
77  for (vector<MxArray>::const_iterator it = arr.begin(); it != arr.end(); ++it)
78  masks.push_back(it->toMat(CV_8U).getUMat(ACCESS_READ).clone());
79  }
80  obj->feed(corners, images, masks);
81  }
82  else if (method == "apply") {
83  nargchk(nrhs==6 && nlhs<=1);
84  int index = rhs[2].toInt();
85  Point corner(rhs[3].toPoint());
86  Mat image(rhs[4].toMat()); // CV_8U
87  Mat mask(rhs[5].toMat(CV_8U));
88  obj->apply(index, corner, image, mask);
89  plhs[0] = MxArray(image);
90  }
91  else if (method == "gains") {
92  nargchk(nrhs==2 && nlhs<=1);
94  if (p.empty())
95  mexErrMsgIdAndTxt("mexopencv:error",
96  "Method only supported for GainCompensator");
97  vector<double> g(p->gains());
98  plhs[0] = MxArray(g);
99  }
100  else
101  mexErrMsgIdAndTxt("mexopencv:error",
102  "Unrecognized operation %s", method.c_str());
103 }
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.
std::vector< double > gains() const
cv::Ptr< cv::detail::ExposureCompensator > createExposureCompensator(const std::string &type, std::vector< MxArray >::const_iterator first, std::vector< MxArray >::const_iterator last)
Create an instance of ExposureCompensator using options in arguments.
#define CV_8U
STL namespace.
T end(T... args)
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
STL class.
index
T push_back(T... args)
virtual void apply(int index, Point corner, InputOutputArray image, InputArray mask)=0
map< int, Ptr< ExposureCompensator > > obj_
Object container.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Ptr< Y > dynamicCast() 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.
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
void feed(const std::vector< Point > &corners, const std::vector< UMat > &images, const std::vector< UMat > &masks)
T size(T... args)
STL class.
bool empty() const
Global constant definitions.
T begin(T... args)
ACCESS_READ
T c_str(T... args)
cv::Mat toMat() const
T reserve(T... args)