Exemplo n.º 1
0
 /// <summary>
 /// The method trains the SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree from CvSVMParams. By the optimality one mean that the cross-validation estimate of the test set error is minimal. 
 /// </summary>
 /// <param name="trainData">The training data.</param>
 /// <param name="responses">The response for the training data.</param>
 /// <param name="varIdx">Can be null if not needed. When specified, identifies variables (features) of interest. It is a Matrix&lt;int&gt; of nx1</param>
 /// <param name="sampleIdx">Can be null if not needed. When specified, identifies samples of interest. It is a Matrix&lt;int&gt; of nx1</param>
 /// <param name="parameters">The parameters for SVM</param>
 /// <param name="kFold">Cross-validation parameter. The training set is divided into k_fold subsets, one subset being used to train the model, the others forming the test set. So, the SVM algorithm is executed k_fold times</param>
 /// <returns></returns>
 public bool TrainAuto(
    Matrix<float> trainData,
    Matrix<float> responses,
    Matrix<int> varIdx,
    Matrix<int> sampleIdx,
    MCvSVMParams parameters,
    int kFold)
 {
    return TrainAuto(
       trainData,
       responses,
       varIdx,
       sampleIdx,
       parameters,
       kFold,
       GetDefaultGrid(Emgu.CV.ML.MlEnum.SVM_PARAM_TYPE.C),
       GetDefaultGrid(Emgu.CV.ML.MlEnum.SVM_PARAM_TYPE.GAMMA),
       GetDefaultGrid(Emgu.CV.ML.MlEnum.SVM_PARAM_TYPE.P),
       GetDefaultGrid(Emgu.CV.ML.MlEnum.SVM_PARAM_TYPE.NU),
       GetDefaultGrid(Emgu.CV.ML.MlEnum.SVM_PARAM_TYPE.COEF),
       GetDefaultGrid(Emgu.CV.ML.MlEnum.SVM_PARAM_TYPE.DEGREE));
 }
Exemplo n.º 2
0
 public static extern bool CvSVMTrainAuto(
     IntPtr model,
     IntPtr trainData,
     IntPtr responses,
     IntPtr varIdx,
     IntPtr sampleIdx,
     MCvSVMParams parameters,
     int kFold,
     MCvParamGrid cGrid,
     MCvParamGrid gammaGrid,
     MCvParamGrid pGrid,
     MCvParamGrid nuGrid,
     MCvParamGrid coefGrid,
     MCvParamGrid degreeGrid);
Exemplo n.º 3
0
 public static extern bool CvSVMTrain(
     IntPtr model,
     IntPtr trainData,
     IntPtr responses,
     IntPtr varIdx,
     IntPtr sampleIdx,
     MCvSVMParams parameters);
Exemplo n.º 4
0
 public static extern void CvSVMGetParameters(IntPtr model, ref MCvSVMParams param);
Exemplo n.º 5
0
Arquivo: SVM.cs Projeto: TaNeRs/SSSS
 /// <summary>
 /// The method trains the SVM model automatically by choosing the optimal parameters C, gamma, p, nu, coef0, degree from CvSVMParams. By the optimality one mean that the cross-validation estimate of the test set error is minimal. 
 /// </summary>
 /// <param name="trainData">The training data.</param>
 /// <param name="responses">The response for the training data.</param>
 /// <param name="varIdx">Can be null if not needed. When specified, identifies variables (features) of interest. It is a Matrix&lt;int&gt; of nx1</param>
 /// <param name="sampleIdx">Can be null if not needed. When specified, identifies samples of interest. It is a Matrix&lt;int&gt; of nx1</param>
 /// <param name="parameters">The parameters for SVM</param>
 /// <param name="kFold">Cross-validation parameter. The training set is divided into k_fold subsets, one subset being used to train the model, the others forming the test set. So, the SVM algorithm is executed k_fold times</param>
 /// <param name="cGrid">cGrid</param>
 /// <param name="gammaGrid">gammaGrid</param>
 /// <param name="pGrid">pGrid</param>
 /// <param name="nuGrid">nuGrid</param>
 /// <param name="coefGrid">coedGrid</param>
 /// <param name="degreeGrid">degreeGrid</param>
 /// <returns></returns>
 public bool TrainAuto(
  Matrix<float> trainData,
  Matrix<float> responses,
  Matrix<Byte> varIdx,
  Matrix<Byte> sampleIdx,
  MCvSVMParams parameters,
  int kFold,
  MCvParamGrid cGrid,
  MCvParamGrid gammaGrid,
  MCvParamGrid pGrid,
  MCvParamGrid nuGrid,
  MCvParamGrid coefGrid,
  MCvParamGrid degreeGrid)
 {
     return MlInvoke.CvSVMTrainAuto(
     Ptr,
     trainData.Ptr,
     responses.Ptr,
     varIdx == null ? IntPtr.Zero : varIdx.Ptr,
     sampleIdx == null ? IntPtr.Zero : sampleIdx.Ptr,
     parameters,
     kFold,
     cGrid,
     gammaGrid,
     pGrid,
     nuGrid,
     coefGrid,
     degreeGrid);
 }
Exemplo n.º 6
0
        public FeatureRecognizer()
        {
            isTrained = false;

            SVMParameters = new SVMParams();
            SVMParameters.SVMType = Emgu.CV.ML.MlEnum.SVM_TYPE.C_SVC;
            //SVMParameters.SVMType = Emgu.CV.ML.MlEnum.SVM_TYPE.NU_SVC;
            //p.KernelType = Emgu.CV.ML.MlEnum.SVM_KERNEL_TYPE.POLY;
            //SVMParameters.KernelType = Emgu.CV.ML.MlEnum.SVM_KERNEL_TYPE.LINEAR;
            SVMParameters.KernelType = Emgu.CV.ML.MlEnum.SVM_KERNEL_TYPE.POLY;
            //SVMParameters.KernelType = Emgu.CV.ML.MlEnum.SVM_KERNEL_TYPE.RBF;
            SVMParameters.Gamma = 3;
            SVMParameters.Degree = 3;
            SVMParameters.C = 1;
            SVMParameters.TermCrit = new MCvTermCriteria(100, 0.00001);
            //SVMParameters.Nu
            //SVMParameters.P
            //SVMParameters.Coef0 =
            paramsm = new MCvSVMParams();
            paramsm.svm_type = Emgu.CV.ML.MlEnum.SVM_TYPE.C_SVC;
            paramsm.kernel_type = Emgu.CV.ML.MlEnum.SVM_KERNEL_TYPE.LINEAR;
            paramsm.gamma = 2;
            paramsm.degree = 3;
            paramsm.C = 3;
            paramsm.term_crit = new MCvTermCriteria(100, 0.00001);
            //debugImages = new List<DebugImage>();
            debugImages = null;

            //SVMModel = new SVM();
               // foreach(SignShape shape in Enum.GetValues(typeof(SignShape)))
            for (int i = 0;i < signShapeCount;i++)
            {
                SVM model = new SVM();
                SVMModels.Add(model);
            }

            int R = 10;
            int C = 10;
            double v = 2;
            for (int i = 0; i < 8; i++)
            {
                GWOutputImage = GWOutputImage.ConcateHorizontal(GaborWavelet(R, C, i, v));
                Image<Gray, double> GW = GaborWavelet(R, C, i, v);
                ConvolutionKernelF ckernel = new ConvolutionKernelF(10, 10);
                for (int l = 0; l < 10; l++)
                    for (int k = 0; k < 10; k++)
                        ckernel[l, k] = (float)GW[l, k].Intensity / 10000;
                ckernel.Center = new Point(5, 5);
                cKernelList.Add(ckernel);
            }
        }