mexopencv  0.1
mex interface for opencv library
illuminationChange.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>=2 && (nrhs%2)==0 && nlhs<=1);
24 
25  // Argument vector
26  vector<MxArray> rhs(prhs, prhs+nrhs);
27 
28  // Option processing
29  float alpha = 0.2f;
30  float beta = 0.4f;
31  bool flip = true;
32  for (int i=2; i<nrhs; i+=2) {
33  string key(rhs[i].toString());
34  if (key == "Alpha")
35  alpha = rhs[i+1].toFloat();
36  else if (key == "Beta")
37  beta = 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)),
47  mask(rhs[1].toMat(CV_8U)),
48  dst;
49  // MATLAB's default is RGB while OpenCV's is BGR
50  if (flip && src.channels() == 3)
51  cvtColor(src, src, cv::COLOR_RGB2BGR);
52  if (flip && mask.channels() == 3)
53  cvtColor(mask, mask, cv::COLOR_RGB2BGR);
54  illuminationChange(src, mask, dst, alpha, beta);
55  // OpenCV's default is BGR while MATLAB's is RGB
56  if (flip && dst.channels() == 3)
57  cvtColor(dst, dst, cv::COLOR_BGR2RGB);
58  plhs[0] = MxArray(dst);
59 }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
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.