mexopencv  3.4.1
MEX interface for OpenCV library
boundingRect.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/imgproc.hpp"
10 using namespace std;
11 using namespace cv;
12 
20 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
21 {
22  // Check the number of arguments
23  nargchk(nrhs==1 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Process
29  Rect r;
30  if (rhs[0].isNumeric() || rhs[0].isLogical()) {
31  // points or mask
32  Mat curve(rhs[0].toMat(
33  rhs[0].isUint8() || rhs[0].isLogical() ? CV_8U :
34  (rhs[0].isFloat() ? CV_32F : CV_32S)));
35  r = boundingRect(curve);
36  }
37  else if (rhs[0].isCell()) {
38  // points
39  if (!rhs[0].isEmpty() && rhs[0].at<MxArray>(0).isFloat()) {
40  vector<Point2f> curve(rhs[0].toVector<Point2f>());
41  r = boundingRect(curve);
42  }
43  else {
44  vector<Point> curve(rhs[0].toVector<Point>());
45  r = boundingRect(curve);
46  }
47  }
48  else
49  mexErrMsgIdAndTxt("mexopencv:error", "Invalid points argument");
50  plhs[0] = MxArray(r);
51 }
#define CV_8U
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
#define CV_32F
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...
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.
#define CV_32S
Global constant definitions.
Rect boundingRect(InputArray points)
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
cv::Mat toMat() const