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,
35 bool override =
false;
37 for (
int i=1; i<nrhs; i+=2) {
38 string key(rhs[i].toString());
40 flags = rhs[i+1].toInt();
43 else if (key ==
"Unchanged")
44 unchanged = rhs[i+1].toBool();
45 else if (key ==
"AnyDepth")
46 anydepth = rhs[i+1].toBool();
47 else if (key ==
"AnyColor")
48 anycolor = rhs[i+1].toBool();
49 else if (key ==
"Grayscale") {
50 color = !rhs[i+1].toBool();
53 else if (key ==
"Color") {
54 color = rhs[i+1].toBool();
57 else if (key ==
"GDAL")
58 gdal = rhs[i+1].toBool();
59 else if (key ==
"ReduceScale") {
60 scale_denom = rhs[i+1].toInt();
61 CV_Assert(scale_denom==1 || scale_denom==2 ||
62 scale_denom==4 || scale_denom==8);
64 else if (key ==
"FlipChannels")
65 flip = rhs[i+1].toBool();
67 mexErrMsgIdAndTxt(
"mexopencv:error",
68 "Unrecognized option %s", key.c_str());
76 flags = cv::IMREAD_UNCHANGED;
80 flags = cv::IMREAD_LOAD_GDAL;
84 flags |= (anydepth ? cv::IMREAD_ANYDEPTH : 0);
86 flags |= (anycolor ? cv::IMREAD_ANYCOLOR :
88 (color ? cv::IMREAD_COLOR : cv::IMREAD_GRAYSCALE));
91 if (scale_denom > 1) {
93 flags |= cv::IMREAD_REDUCED_GRAYSCALE_2;
94 else if (scale_denom == 4)
95 flags |= cv::IMREAD_REDUCED_GRAYSCALE_4;
96 else if (scale_denom == 8)
97 flags |= cv::IMREAD_REDUCED_GRAYSCALE_8;
103 string filename(rhs[0].toString());
104 Mat img = imread(filename, flags);
105 if (img.data == NULL)
106 mexErrMsgIdAndTxt(
"mexopencv:error",
"imread failed");
107 if (flip && (img.channels() == 3 || img.channels() == 4)) {
109 cvtColor(img, img, (img.channels()==3 ?
110 cv::COLOR_BGR2RGB : cv::COLOR_BGRA2RGBA));
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.