19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=1);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
28 bool unchanged =
false,
33 bool override =
false;
35 for (
int i=1; i<nrhs; i+=2) {
36 string key(rhs[i].toString());
38 flags = rhs[i+1].toInt();
41 else if (key ==
"Unchanged")
42 unchanged = rhs[i+1].toBool();
43 else if (key ==
"AnyDepth")
44 anydepth = rhs[i+1].toBool();
45 else if (key ==
"AnyColor")
46 anycolor = rhs[i+1].toBool();
47 else if (key ==
"Grayscale") {
48 color = !rhs[i+1].toBool();
51 else if (key ==
"Color") {
52 color = rhs[i+1].toBool();
55 else if (key ==
"FlipChannels")
56 flip = rhs[i+1].toBool();
58 mexErrMsgIdAndTxt(
"mexopencv:error",
59 "Unrecognized option %s", key.c_str());
67 flags = cv::IMREAD_UNCHANGED;
71 flags |= (anydepth ? cv::IMREAD_ANYDEPTH : 0);
73 flags |= (anycolor ? cv::IMREAD_ANYCOLOR :
75 (color ? cv::IMREAD_COLOR : cv::IMREAD_GRAYSCALE));
80 Mat buf(rhs[0].toMat(CV_8U));
81 Mat img = imdecode(buf, flags);
83 mexErrMsgIdAndTxt(
"mexopencv:error",
"imdecode failed");
84 if (flip && (img.channels() == 3 || img.channels() == 4)) {
86 cvtColor(img, img, (img.channels()==3 ?
87 cv::COLOR_BGR2RGB : cv::COLOR_BGRA2RGBA));
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.