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,
34 bool override =
false;
36 for (
int i=1; i<nrhs; i+=2) {
37 string key(rhs[i].toString());
39 flags = rhs[i+1].toInt();
42 else if (key ==
"Unchanged")
43 unchanged = rhs[i+1].toBool();
44 else if (key ==
"AnyDepth")
45 anydepth = rhs[i+1].toBool();
46 else if (key ==
"AnyColor")
47 anycolor = rhs[i+1].toBool();
48 else if (key ==
"Grayscale") {
49 color = !rhs[i+1].toBool();
52 else if (key ==
"Color") {
53 color = rhs[i+1].toBool();
56 else if (key ==
"GDAL")
57 gdal = rhs[i+1].toBool();
58 else if (key ==
"FlipChannels")
59 flip = rhs[i+1].toBool();
61 mexErrMsgIdAndTxt(
"mexopencv:error",
62 "Unrecognized option %s", key.c_str());
70 flags = cv::IMREAD_UNCHANGED;
74 flags = cv::IMREAD_LOAD_GDAL;
78 flags |= (anydepth ? cv::IMREAD_ANYDEPTH : 0);
80 flags |= (anycolor ? cv::IMREAD_ANYCOLOR :
82 (color ? cv::IMREAD_COLOR : cv::IMREAD_GRAYSCALE));
87 string filename(rhs[0].toString());
89 bool status = imreadmulti(filename, imgs, flags);
91 mexErrMsgIdAndTxt(
"mexopencv:error",
"imreadmulti failed");
92 for (vector<Mat>::iterator it = imgs.begin(); it != imgs.end(); ++it) {
94 mexErrMsgIdAndTxt(
"mexopencv:error",
"imreadmulti failed");
95 if (flip && (it->channels() == 3 || it->channels() == 4)) {
97 cvtColor(*it, *it, (it->channels()==3 ?
98 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.