我想要用于眨眼检测的代码

编程入门 行业动态 更新时间:2024-10-12 12:34:02
本文介绍了我想要用于眨眼检测的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用c#.i中的opencv进行眨眼检测项目。检测眼睛和脸部但不会眨眼。所以任何人都可以帮我检测眨眼.. 这里是代码

Im doing the project for eye blink detection using opencv in c#.i detect eye and face but not eye blink.so any one help me to detect eye blink.. here is the code

using Emgu.CV; using Emgu.CV.Structure; using Emgu.Util; using Emgu.CV.CvEnum; namespace EyeDetection { public partial class Form1 : Form { private Capture _capture; private HaarCascade _faces; private HaarCascade _eyes; int xMax; int yMax; public Form1() { InitializeComponent(); _capture = new Capture(); _faces=new HaarCascade("C:\\Users\\subha\\Documents\\Visual Studio 2010\\Projects\\EyeDetection\\EyeDetection\\haarcascade_frontalface_default.xml"); _eyes = new HaarCascade("C:\\Users\\subha\\Documents\\Visual Studio 2010\\Projects\\EyeDetection\\EyeDetection\\haarcascade_eye.xml"); Application.Idle += ProcessFrame; _capture.Start(); } private void ProcessFrame(object sender, EventArgs arg) { try { Image<bgr,> frame = _capture.QueryFrame(); Image<gray,> grayFrame = frame.Convert<gray,>(); grayFrame._EqualizeHist(); MCvAvgComp[][] facesDetected = grayFrame.DetectHaarCascade(_faces, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, new Size(20, 20)); if (facesDetected[0].Length == 1) { MCvAvgComp face = facesDetected[0][0]; Int32 yCoordStartSearchEyes = face.rect.Top + (face.rect.Height * 3 / 11); Point startingPointSearchEyes = new Point(face.rect.X, yCoordStartSearchEyes); Point endingPointSearchEyes = new Point((face.rect.X + face.rect.Width), yCoordStartSearchEyes); Size searchEyesAreaSize = new Size(face.rect.Width, (face.rect.Height * 2 / 9)); Point lowerEyesPointOptimized = new Point(face.rect.X, yCoordStartSearchEyes + searchEyesAreaSize.Height); Size eyeAreaSize = new Size(face.rect.Width / 2, (face.rect.Height * 2 / 9)); Point startingLeftEyePointOptimized = new Point(face.rect.X + face.rect.Width / 2, yCoordStartSearchEyes); Rectangle possibleROI_eyes = new Rectangle(startingPointSearchEyes, searchEyesAreaSize); Rectangle possibleROI_rightEye = new Rectangle(startingPointSearchEyes, eyeAreaSize); Rectangle possibleROI_leftEye = new Rectangle(startingLeftEyePointOptimized, eyeAreaSize); grayFrame.ROI = possibleROI_leftEye; MCvAvgComp[][] leftEyesDetected = grayFrame.DetectHaarCascade(_eyes, 1.15, 0, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20)); grayFrame.ROI = Rectangle.Empty; grayFrame.ROI = possibleROI_rightEye; MCvAvgComp[][] rightEyesDetected = grayFrame.DetectHaarCascade(_eyes, 1.15, 0, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(20, 20)); grayFrame.ROI = Rectangle.Empty; if (leftEyesDetected[0].Length != 0 && rightEyesDetected[0].Length != 0) { frame.Draw(face.rect, new Bgr(Color.Violet), 2); grayFrame.ROI = possibleROI_leftEye; CircleF[] leftEyecircles = grayFrame.HoughCircles(new Gray(180), new Gray(70), 5.0, 10.0, 1, 200)[0]; grayFrame.ROI = Rectangle.Empty; grayFrame.ROI = possibleROI_rightEye; CircleF[] rightEyecircles = grayFrame.HoughCircles(new Gray(180), new Gray(70), 5.0, 10.0, 1, 200)[0]; grayFrame.ROI = Rectangle.Empty; foreach (MCvAvgComp eyeLeft in leftEyesDetected[0]) { Rectangle eyeRect = eyeLeft.rect; eyeRect.Offset(startingLeftEyePointOptimized.X, startingLeftEyePointOptimized.Y); frame.Draw(eyeRect, new Bgr(Color.Red), 2); } foreach (MCvAvgComp eyeRight in rightEyesDetected[0]) { Rectangle eyeRect = eyeRight.rect; eyeRect.Offset(startingPointSearchEyes.X, startingPointSearchEyes.Y); frame.Draw(eyeRect, new Bgr(Color.Red), 2); } } DisplayBox.Image = frame.Bitmap; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }

推荐答案

为什么不呢从这里开始 EmguCV:代码库 [ ^ ] 或此处支持和服务 [ ^ ] 并且要切合实际。你认为这里有多少用户在他们的计算机上安装了EmguCV并且愿意调试你的代码? 如果你想要代码这非常糟糕,你要么自己写,要么付某人为你做。 Why not start here EmguCV: Code Gallery[^] or here Support and Services[^] And to be realistic. How many users here do you think have EmguCV installed on their computers and are willing to debug your code? And if you want the code this badly you either have to write it yourself or pay someone to do it for you.

更多推荐

我想要用于眨眼检测的代码

本文发布于:2023-11-07 19:29:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1567219.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   我想要

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!