mexopencv  3.4.1
MEX interface for OpenCV library
stylization.cpp
Go to the documentation of this file.
1 
8 #include "mexopencv.hpp"
9 #include "opencv2/photo.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 && (nrhs%2)==1 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  float sigma_s = 60;
30  float sigma_r = 0.45f;
31  bool flip = false;
32  for (int i=1; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "SigmaS")
35  sigma_s = rhs[i+1].toFloat();
36  else if (key == "SigmaR")
37  sigma_r = rhs[i+1].toFloat();
38  else if (key == "FlipChannels")
39  flip = rhs[i+1].toBool();
40  else
41  mexErrMsgIdAndTxt("mexopencv:error",
42  "Unrecognized option %s", key.c_str());
43  }
44 
45  // Process
46  Mat src(rhs[0].toMat(CV_8U)), dst;
47  if (flip && src.channels() == 3) {
48  // MATLAB's default is RGB while OpenCV's is BGR
49  cvtColor(src, src, cv::COLOR_RGB2BGR);
50  }
51  stylization(src, dst, sigma_s, sigma_r);
52  if (flip && dst.channels() == 3) {
53  // OpenCV's default is BGR while MATLAB's is RGB
54  cvtColor(dst, dst, cv::COLOR_BGR2RGB);
55  }
56  plhs[0] = MxArray(dst);
57 }
COLOR_RGB2BGR
void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0)
COLOR_BGR2RGB
#define CV_8U
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
Definition: stylization.cpp:20
STL namespace.
struct mxArray_tag mxArray
Forward declaration for mxArray.
Definition: matrix.h:259
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.
void stylization(InputArray src, OutputArray dst, float sigma_s=60, float sigma_r=0.45f)
Global constant definitions.
T c_str(T... args)
void flip(InputArray src, OutputArray dst, int flipCode)
cv::Mat toMat() const
int channels() const