Search code examples
javac++opencvjavacv

what is component mask in train CvNormalBayesClassifier opencv?


I am training the SIFT BOW descriptors using normal Bayes classifier. my training data has 79 rows representing each row a sample and 500 columns. response data has 79 rows and 1 column. varIdx and sampleIdx are 0 and update=true.

    CvNormalBayesClassifier classifier=new CvNormalBayesClassifier();

         CvMat val1 =cvCreateMat(1,1,CV_8U);
         double[] myarr1=new double[1];
         myarr1[0]=0.0;
         val1.put(myarr1);
         CvMat val2 =cvCreateMat(1,1,CV_8U);
         double[] myarr2=new double[1];
         myarr2[0]=0.0;
         val2.put(myarr2);

         classifier.train(trainingdata, label,val1,val2 ,true);

error:

OpenCV Error: Sizes of input arguments do not match (Component mask should contain as many elements as the total number of input variables) in cvPreprocessIndexArray, file ..\..\..\..\opencv\modules\ml\src\inner_functions.cpp, line 426
Exception in thread "main" java.lang.RuntimeException: ..\..\..\..\opencv\modules\ml\src\inner_functions.cpp:426: error: (-209) Component mask should contain as many elements as the total number of input variables in function cvPreprocessIndexArray

    at com.googlecode.javacv.cpp.opencv_ml$CvNormalBayesClassifier.train(Native Method)
    at com.cis.project.Recognition.main(Recognition.java:74)

what is the component mask?


Solution

  • from the docs :

    Many ML models may be trained on a selected feature subset, and/or on a selected sample subset of the training set. To make it easier for you, the method train usually includes the var_idx and sample_idx parameters. The former parameter identifies variables (features) of interest, and the latter one identifies samples of interest. Both vectors are either integer (CV_32SC1) vectors (lists of 0-based indices) or 8-bit (CV_8UC1) masks of active variables/samples. You may pass NULL pointers instead of either of the arguments, meaning that all of the variables/samples are used for training.

    so, either pass it a 1d integer or uchar Mat the same length as the labels/samples, filled with 0 and 1 to be used as a mask, or pass an empty object (or a null pointer, depending on your api).