19 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
22 nargchk(nrhs>=1 && (nrhs%2)==1 && nlhs<=2);
25 vector<MxArray> rhs(prhs, prhs+nrhs);
29 int flags = cv::COVAR_NORMAL | cv::COVAR_ROWS;
31 for (
int i=1; i<nrhs; i+=2) {
32 string key(rhs[i].toString());
34 mean = rhs[i+1].toMat();
35 flags |= cv::COVAR_USE_AVG;
37 else if (key==
"Flags")
38 flags = rhs[i+1].toInt();
39 else if (key==
"Scrambled") {
41 UPDATE_FLAG(flags, !rhs[i+1].toBool(), cv::COVAR_NORMAL);
43 else if (key==
"Normal")
44 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::COVAR_NORMAL);
45 else if (key==
"UseAvg")
46 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::COVAR_USE_AVG);
47 else if (key==
"Scale")
48 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::COVAR_SCALE);
49 else if (key==
"Rows") {
50 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::COVAR_ROWS);
51 UPDATE_FLAG(flags, !rhs[i+1].toBool(), cv::COVAR_COLS);
53 else if (key==
"Cols") {
54 UPDATE_FLAG(flags, rhs[i+1].toBool(), cv::COVAR_COLS);
55 UPDATE_FLAG(flags, !rhs[i+1].toBool(), cv::COVAR_ROWS);
57 else if (key==
"CType")
58 ctype = (rhs[i+1].isChar()) ?
61 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
65 Mat samples(rhs[0].toMat()), covar;
66 calcCovarMatrix(samples, covar, mean, flags, ctype);
const ConstMap< std::string, int > ClassNameMap
Translates class name used in MATLAB to equivalent OpenCV depth.
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
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.