mexopencv  0.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","Unrecognized option");
43  }
44  borderType |= (isolated ? cv::BORDER_ISOLATED : 0);
45 
46  // Process
47  Mat src(rhs[0].toMat()), dst;
48  int top, bottom, left, right;
49  if (vect_variant) {
50  vector<int> v(rhs[1].toVector<int>());
51  nargchk(v.size() == 4);
52  top = v[0];
53  bottom = v[1];
54  left = v[2];
55  right = v[3];
56  }
57  else {
58  top = rhs[1].toInt();
59  bottom = rhs[2].toInt();
60  left = rhs[3].toInt();
61  right = rhs[4].toInt();
62  }
63  copyMakeBorder(src, dst, top, bottom, left, right, borderType, value);
64  plhs[0] = MxArray(dst);
65 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
const ConstMap< std::string, int > BorderType
Border type map for option processing.
Definition: mexopencv.hpp:52
mxArray object wrapper for data conversion and manipulation.
Definition: MxArray.hpp:123
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Definition: mexopencv.hpp:166
Global constant definitions.