我一直在试图修复代码cs0103中的错误,其中'faceRect'不存在于当前上下文中,但是当判断我的代码时,我不知道我错在哪里,我是新的dlibdotnet和www.example.com

以下是三个功能协同工作:

FrameGrabber:

void FrameGrabber(object sender, EventArgs e)
{
    try
    {
        face_detected_lbl.Text = "0";
        NamePersons.Add("");

        // Get the current frame from the capture device
        Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);

        // Convert it to Grayscale
        Emgu.CV.Image<Emgu.CV.Structure.Gray, byte> gray = currentFrame.Convert<Emgu.CV.Structure.Gray, byte>();

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

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

            // Check if the face is live
            DlibDotNet.Rectangle dlibRect = new DlibDotNet.Rectangle(f.rect.Left, f.rect.Top, f.rect.Right, f.rect.Bottom);
            bool isLive = IsLiveFunction(currentFrame, dlibRect);

            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);

                string name = recognizer.Recognize(result);

                finalname = name;
                // Draw the label for each face detected and recognized
                if (string.IsNullOrEmpty(name))
                {
                    currentFrame.Draw(string.IsNullOrEmpty(name) ? "Unknown" : name, ref font, new System.Drawing.Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.Red));
                }
                else
                {
                    currentFrame.Draw(name, ref font, new System.Drawing.Point(f.rect.X - 2, f.rect.Y - 2), new Bgr(Color.Lime));
                }
            }

IsLiveFunction:

private bool IsLiveFunction(Emgu.CV.Image<Emgu.CV.Structure.Bgr, byte> currentFrame, DlibDotNet.Rectangle faceRect)
{
     bool isLive = false;

     try
     {
         System.Drawing.Rectangle emguRect = new System.Drawing.Rectangle((int)faceRect.Left, (int)faceRect.Top, (int)faceRect.Width, (int)faceRect.Height);

         // Convert the current frame to grayscale
         Emgu.CV.Image<Emgu.CV.Structure.Gray, byte> grayFrame = currentFrame.Convert<Emgu.CV.Structure.Gray, byte>();

         // Extract region of interest (ROI) from the current frame using the face rectangle
         Emgu.CV.Image<Emgu.CV.Structure.Gray, byte> faceImage = grayFrame.Copy(emguRect);

         double ear = CalculateEyeAspectRatio(faceImage);
         double blinkThreshold = 0.2;
         bool blinkingDetected = ear < blinkThreshold;
         DlibDotNet.Rectangle dlibRect = new DlibDotNet.Rectangle(emguRect.Left, emguRect.Top, emguRect.Right, emguRect.Bottom);
         bool headMovementDetected = DetectHeadMovement(grayFrame, dlibRect);
    }
    catch()
    { }
}

LogInLogOut:

private void login_timer_Tick(object sender, EventArgs e)
{
    try
    {
        pwede_na_magout = false;

        if (!string.IsNullOrEmpty(identified_name_lbl.Text) )
        {
            //--- TIMEIN 1
            bool checkuser = false;
            int face_detected = Convert.ToInt32(face_detected_lbl.Text);
            currentFrame = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
            bool isLive = IsLiveFunction(currentFrame, faceRect);
            string query = "SELECT Username, Date, Time_In FROM logbook_tb";

            MySqlCommand cmd = new MySqlCommand(query, connection);

            if (connection.State != ConnectionState.Open)
            {
                // blah blah
            }

            if (checkuser == false && !string.IsNullOrEmpty(lname.Text) && (face_detected == 1 && isLive) && (DateTime.Parse(time_login.Text, CultureInfo.InvariantCulture) < DateTime.Parse("11:59 AM", CultureInfo.InvariantCulture)))
            {
                MessageBox.Show("Blink once and move your head to log in.", "Instructions", MessageBoxButtons.OK, MessageBoxIcon.Information);

                LOGIN();
                READ_RECORD();
            }
            else
            {
                // If blinking or head movement is not detected
                DialogResult result = MessageBox.Show("Failed to detect real face. Would you like to try again?", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); ;

                if (result == DialogResult.Retry)
                {
                    // Retry
                    login_timer_Tick(sender, e);
                }
                else
                {
                    // Exit
                    Application.Exit();
                }
            }
        }
    }
}

我试

DlibDotNet.Rectangle faceRect = GetFaceRectangleFromCurrentFrame();

然而,这将导致我创建一个新的函数,甚至不能保证它会解决问题.

以下是它应该如何在我的脑海中工作:

Facedect > Blinkheadmovement >如果都为真,则登录,否则显示提示信息.

我还不知道是否会有更多的功能问题,如果你能认出一些并告诉我,那将是一个很大的帮助.

谢谢!

推荐答案

我把我所有的代码从www.example.com 2.0翻译成最新的4.8,现在一切都正常工作.

Csharp相关问答推荐

ASP.NET MVC购物车数量更新并从购物车中删除项目

有没有一种方法可以在包含混合文本的标签中嵌入超链接?

如何使用CsvReader获取给定列索引的列标题?

为什么C#Bigbit不总是相同的比特长度?

如何使用ConcurentDictionary属性上的属性将自定义System.Text.Json JsonConverter应用于该属性的值?

System.Text.Json数据化的C#类映射

Unity中的刚体2D运动

MongoDB.NET-将数据绑定到模型类,但无法读取整数值

获取具有AutoFaces的所有IOptions对象的集合

在此系统上已禁用获取正在运行的脚本.&在ASP.NET Core Web API中

如何将MongoDB序列化程序设置为内部对象属性

如何通过属性初始化器强制初始化继承记录内的属性?

DateTime ToString()未以指定格式打印

在字符串C#之前获取数字

MSTest--将消息直接写入StdOut和使用TestContext有什么不同?

我可以查看我们向应用程序洞察发送了多少数据吗?

源代码生成器项目使用`dotnet build`编译,而不是在Visual Studio中编译?

如何在C#中正确类型化带有泛型的嵌套类

如何在C#.NET桌面应用程序中动态更改焦点工具上的后退 colored颜色

Xamarin Forms应用程序中登录页面的用户名和密码编辑文本之间不需要的空格