mexopencv  3.4.1
MEX interface for OpenCV library
copyMakeBorder.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 using namespace std;
10 using namespace cv;
11 
19 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
20 {
21  // Check the number of arguments
22  nargchk(nrhs>=2 && nlhs<=1);
23 
24  // Argument vector: (src, t, b, l, r) or (src, [t b l r])
25  vector<MxArray> rhs(prhs, prhs+nrhs);
26  bool vect_variant = (rhs[1].numel() == 4);
27  nargchk(vect_variant ? ((nrhs%2)==0) : (nrhs>=5 && (nrhs%2)!=0));
28 
29  // Option processing
30  int borderType = cv::BORDER_DEFAULT;
31  bool isolated = false; // TODO: only makes sense for ROI submatrices
32  Scalar value;
33  for (int i=(vect_variant ? 2 : 5); i<nrhs; i+=2) {
34  string key(rhs[i].toString());
35  if (key == "BorderType")
36  borderType = BorderType[rhs[i+1].toString()];
37  else if (key == "Isolated")
38  isolated = rhs[i+1].toBool();
39  else if (key == "Value")
40  value = rhs[i+1].toScalar();
41  else
42  mexErrMsgIdAndTxt("mexopencv:error",
43  "Unrecognized option %s", key.c_str());
44  }
45  borderType |= (isolated ? cv::BORDER_ISOLATED : 0);
46 
47  // Process
48  Mat src(rhs[0].toMat()), dst;
49  int top, bottom, left, right;
50  if (vect_variant) {
51  vector<int> v(rhs[1].toVector<int>());
52  nargchk(v.size() == 4);
53  top = v[0];
54  bottom = v[1];
55  left = v[2];
56  right = v[3];
57  }
58  else {
59  top = rhs[1].toInt();
60  bottom = rhs[2].toInt();
61  left = rhs[3].toInt();
62  right = rhs[4].toInt();
63  }
64  copyMakeBorder(src, dst, top, bottom, left, right, borderType, value);
65  plhs[0] = MxArray(dst);
66 }
T left(T... args)
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void copyMakeBorder(InputArray src, OutputArray dst, int top, int bottom, int left, int right, int borderType, const Scalar &value=Scalar())
uint32_t v
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...
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:66
BORDER_ISOLATED
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.
Global constant definitions.
T c_str(T... args)
BORDER_DEFAULT
cv::Mat toMat() const