C# emgu会自动将无法识别的人脸添加到数据库中

C# emgu会自动将无法识别的人脸添加到数据库中,c#,emgucv,face-recognition,C#,Emgucv,Face Recognition,我想从下面的代码中做的是更改button2 click事件,以自动向数据库中添加无法识别的面,因此无需按下按钮。我尝试过各种想法,但大多数都会出现错误。是否可以使用否定识别结果来运行button2 Click事件 private void button2_Click(object sender, System.EventArgs e) { try { //Trained face counter ContTrain = ContTrain + 1

我想从下面的代码中做的是更改button2 click事件,以自动向数据库中添加无法识别的面,因此无需按下按钮。我尝试过各种想法,但大多数都会出现错误。是否可以使用否定识别结果来运行button2 Click事件

private void button2_Click(object sender, System.EventArgs e)
{
    try
    {

        //Trained face counter
        ContTrain = ContTrain + 1;

        //Get a gray frame from capture device
        gray = grabber.QueryGrayFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

        //Face Detector
        MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
        face,
        1.2,
        10,
        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
        new Size(20, 20));

        //Action for each element detected
        foreach (MCvAvgComp f in facesDetected[0])
        {

            TrainedFace = currentFrame.Copy(f.rect).Convert<Gray, byte>();



            break;
        }

        //resize face detected image for force to compare the same size with the 
        //test image with cubic interpolation type method
        TrainedFace = result.Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
        named = DateTime.Now.ToString("dd-MM-yy HH:mm:ss:ms");
        TrainedFace.Save(Application.StartupPath + "/Temp/face1.bmp");

        string dated = DateTime.Now.ToString("HH:mm:ss:ff dd-MM-yy");
        label4.Text = dated;

        //Show face added in gray scale
        imageBox1.Image = TrainedFace;
        trainingImages.Add(TrainedFace);
        labels.Add(label4.Text);

        byte[] imagepic = null;
        FileStream fsstream = new FileStream(Application.StartupPath + "/Temp/face1.bmp", FileMode.Open, FileAccess.Read);
        BinaryReader br = new BinaryReader(fsstream);
        imagepic = br.ReadBytes((int)fsstream.Length);



        string myConnection = "datasource=sql4.freemysqlhosting.net;port=3306;user=sql434250;password=lE3!lQ5*";
        MySqlConnection myConn = new MySqlConnection(myConnection);
        MySqlCommand SelectCommand = new MySqlCommand("INSERT INTO `sql434250`.`facialid` (`id`, `timeanddate`, `photo1`) VALUES (NULL, @dated, @IMG);", myConn);
        MySqlDataReader myReader;


        myConn.Open();
        SelectCommand.Parameters.Add(new MySqlParameter("@IMG", imagepic));
        SelectCommand.Parameters.Add(new MySqlParameter("@dated", dated));
        myReader = SelectCommand.ExecuteReader();


        while (myReader.Read())
        {
        }
        Refresh();

    }
    catch (MySqlException ee)
    {

        MessageBox.Show(e.ToString());
        int errorcode = ee.Number;
    }

}




void FrameGrabber(object sender, EventArgs e)
{
    label3.Text = "0";
    //label4.Text = "";
    NamePersons.Add("");


    //Get the current frame form capture device
    currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

    //Convert it to Grayscale
    gray = currentFrame.Convert<Gray, Byte>();

    //Face Detector
    MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
        face,
        1.2,
        10,
        Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
        new Size(20, 20));

    //Action for each element detected
    foreach (MCvAvgComp f in facesDetected[0])
    {
        t = t + 1;
        result = currentFrame.Copy(f.rect).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
        //draw the face detected in the 0th (gray) channel with blue color
        currentFrame.Draw(f.rect, new Bgr(Color.Red), 2);


        if (trainingImages.ToArray().Length != 0)
        {
            //TermCriteria for face recognition with numbers of trained images like maxIteration
            MCvTermCriteria termCrit = new MCvTermCriteria(ContTrain, 0.001);

            //Eigen face recognizer
            EigenObjectRecognizer recognizer = new EigenObjectRecognizer(
                trainingImages.ToArray(),
                labels.ToArray(),
                3000,
                ref termCrit);

            name = recognizer.Recognize(result);

            //Draw the label for each face detected and recognized
            currentFrame.Draw(name, ref font, new Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.LightGreen));

        }

        NamePersons[t - 1] = name;
        NamePersons.Add("");


        //Set the number of faces detected on the scene
        label3.Text = facesDetected[0].Length.ToString();

    }
    t = 0;

    //Names concatenation of persons recognized
    for (int nnn = 0; nnn < facesDetected[0].Length; nnn++)
    {
        names = names + NamePersons[nnn] + ", ";
    }
    //Show the faces procesed and recognized
    imageBoxFrameGrabber.Image = currentFrame;


    //Clear the list(vector) of names
    NamePersons.Clear();

}

你忘了问问题了。当前的代码有什么问题?代码工作正常,我只是希望删除点击事件,这样代码会在MySQL数据库中添加一张无法识别的脸。我希望它可能来自帧捕获器代码。发布的所有内容都是程序说明和一些代码。然而,我们需要你去。我们不能确定你想从我们这里得到什么。请编辑您的帖子,以包含我们可以回答的有效问题。提醒:请确保您知道,要求我们为您编写程序或建议是离题的。@tnw要详细说明负面识别结果是否可用于运行按钮2单击事件,这是怎么回事