2017-08-08 104 views
0

我想问你,如果我可以使用散列技术与SURF算法,我做了一个程序,通过匹配测试图像与保存的图像数据集进行人脸识别。SURF与哈希

我使用了Accord.net,并且通过这个库的BOW制作了一些功能,然后我做了ID3决策树和KNN,但是两种方式的结果都不是很好,我问我是否可以使用哈希技术来快速创建和更好的结果,否则这将不可行? 这是BOW

    private void button2_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      var watchFEC = System.Diagnostics.Stopwatch.StartNew(); 
      Accord.Math.Random.Generator.Seed = 0; 
      bow.ParallelOptions.MaxDegreeOfParallelism = 1; 
      bow.Learn(DatasetImages); 
      // After this point, we will be able to translate 
      // images into double[] feature vectors using 
      features = bow.Transform(DatasetImages); 
      watchFEC.Stop(); 
      var elapsedMs = watchFEC.ElapsedMilliseconds; 
      MessageBox.Show("Feature Extraction and Clastering is done" + '\n' + "Time for Feature Extraction and Clastering for Dataset is: " + elapsedMs.ToString() + " ms"); 
     } catch { MessageBox.Show("Error"); }  } 

的代码,这是代码为学习

private void button3_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      var watchLearn = System.Diagnostics.Stopwatch.StartNew(); 
      inputs = features.ToInt32(); 
      tree = teacher.Learn(inputs, outputs); 
      error = new ZeroOneLoss(outputs).Loss(tree.Decide(inputs)); 
      MessageBox.Show("Error rate of learning is : "+error.ToString()); 
      watchLearn.Stop(); 
      var elapsedMs = watchLearn.ElapsedMilliseconds; 
      MessageBox.Show("Learning is done" + '\n' + "Time for Learning is: " + elapsedMs.ToString() + " ms"); 
     } 
     catch(Exception ex) { MessageBox.Show("Error"+ex); } 

    } 

这个代码测试

 private void button4_Click_1(object sender, EventArgs e) 
    { 
     try 
     { 
      var watchTest = System.Diagnostics.Stopwatch.StartNew(); 
      Bitmap[] testimage = new Bitmap[1]; 
      testimage[0] = (Bitmap)pictureBox1.Image; 
      var ff = bow.Transform(testimage); 
      ff.ToInt32(); 
      var predicted = tree.Decide(ff); 
      int i = 1; 
      for (i = 1; i < sizeofdataset; i++) 
      { 
       if (predicted[0] == Convert.ToInt16(workSheet.Cells[i, 3].Value.ToString())) 
       { 

        listBox1.SelectedItem = i; 
        MessageBox.Show("Test" + i); 
        break; 
       } 
      } 
      MessageBox.Show("Test" + predicted[0]); 
      pictureBox2.Image = new Bitmap(workSheet.Cells[i, 1].Value.ToString()); 
      watchTest.Stop(); 
      var elapsedMs = watchTest.ElapsedMilliseconds; 
      MessageBox.Show("Time for Testing is: " + elapsedMs.ToString() + " ms"); 
     } 

     catch (Exception ex) { MessageBox.Show("Error" + ex); } 

    } 
+0

Hiraqui嗨,如果可以的话,请把你的项目的完整.ZIP到Accord.NET的问题跟踪器,它可能更容易检测到这里可能存在的问题。但是 - 你是否也尝试过使用SVM而不是决策树?它们通常比ID3决策树更快/更可靠(至少在Accord.NET框架内)。 – Cesar

+0

@Cesar,感谢您的回复,我将您的完整程序发送给您的电子邮件,我没有尝试SVM –

回答

0

相反的ID3或k-NN,请尝试使用具有卡方内核的SVM。

如果您想试用SVM,那么有一个example on how to create multi-class kernel SVMs at the bottom of this page (see second example)。你可以用“ChiSquare”替换它写成“Gaussian”的所有地方,以创建一个卡方SVM。

如果您碰巧在{“索引超出数组范围”的范围内运行),如您在项目的问题跟踪器中指出的那样,我认为您可能没有培训或测试样本的课程。请确保您有足够的所有课程的训练样本,您的课程编号从0开始,输出向量中的最高级别标签对应number_of_classes - 1,并且在没有任何关联的训练样本的情况下没有整数。

我张贴下面就如何培养使用在Accord.NET框架卡方支持向量机内核的例子:

// Let's say we have the following data to be classified 
// into three possible classes. Those are the samples: 
// 
double[][] inputs = 
{ 
    //    input   output 
    new double[] { 0, 1, 1, 0 }, // 0 
    new double[] { 0, 1, 0, 0 }, // 0 
    new double[] { 0, 0, 1, 0 }, // 0 
    new double[] { 0, 1, 1, 0 }, // 0 
    new double[] { 0, 1, 0, 0 }, // 0 
    new double[] { 1, 0, 0, 0 }, // 1 
    new double[] { 1, 0, 0, 0 }, // 1 
    new double[] { 1, 0, 0, 1 }, // 1 
    new double[] { 0, 0, 0, 1 }, // 1 
    new double[] { 0, 0, 0, 1 }, // 1 
    new double[] { 1, 1, 1, 1 }, // 2 
    new double[] { 1, 0, 1, 1 }, // 2 
    new double[] { 1, 1, 0, 1 }, // 2 
    new double[] { 0, 1, 1, 1 }, // 2 
    new double[] { 1, 1, 1, 1 }, // 2 
}; 

int[] outputs = // those are the class labels 
{ 
    0, 0, 0, 0, 0, 
    1, 1, 1, 1, 1, 
    2, 2, 2, 2, 2, 
}; 

// Create the multi-class learning algorithm for the machine 
var teacher = new MulticlassSupportVectorLearning<ChiSquare>() 
{ 
    // Configure the learning algorithm to use SMO to train the 
    // underlying SVMs in each of the binary class subproblems. 
    Learner = (param) => new SequentialMinimalOptimization<ChiSquare>() 
    { 
     // Estimate a suitable guess for the Gaussian kernel's parameters. 
     // This estimate can serve as a starting point for a grid search. 
     UseKernelEstimation = true 
    } 
}; 

// Configure parallel execution options (or leave it at the default value for maximum speed) 
teacher.ParallelOptions.MaxDegreeOfParallelism = 1; 

// Learn a machine 
var machine = teacher.Learn(inputs, outputs); 

// Obtain class predictions for each sample 
int[] predicted = machine.Decide(inputs); 

// Get class scores for each sample 
double[] scores = machine.Score(inputs); 

// Compute classification error 
double error = new ZeroOneLoss(outputs).Loss(predicted);