private void detectFace(out System.Drawing.Bitmap face, out Bitmap bigImage) { face = null; double scale = 0.5; Bitmap bitmap = EmguCVHelper.GetScaledCaptureImage(scale).ToBitmap(); var faces = FaceRecognitionService.DetectFace(bitmap); if (faces.Count > 0) { IsFaceDetected = true; face = bitmap; m_detectedFace = faces[0].Bitmap; EmguCVHelper.DrawObjectsBoundaries(EmguCVHelper.CaptureImage, faces, scale); } else { IsFaceDetected = false; } RaisePropertyChanged(() => IsFaceDetected); bigImage = EmguCVHelper.CaptureImage.ToBitmap(); }
private void Sensor_ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame != null) { colorFrame.CopyPixelDataTo(this.colorPixels); System.Drawing.Bitmap bmp = EmguCVHelper.ImageToBitmap(colorFrame); if (_grabando) { videoController.InicioGrabacion = DateTime.Now.Ticks; videoController.framesBmp.Add(bmp); } // Write the pixel data into our bitmap this.colorBitmap.WritePixels( new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight), this.colorPixels, this.colorBitmap.PixelWidth * sizeof(int), 0); } using (DrawingContext dc = this.drawingGroup.Open()) { dc.DrawImage(this.colorBitmap, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } } }
/// <summary> /// برسی وجود صورت در تصویر /// </summary> /// <returns>نتیجه برسی</returns> public bool Check() { Bitmap l_bitmap = EmguCVHelper.ScaleImage((Image <Bgr, byte>)Input, m_scale).ToBitmap(); m_faces = this.FaceRecognition.DetectFace(l_bitmap); return(m_faces.Count > 0); }
/// <summary> /// رمزگشایی کد QR موجود /// </summary> /// <returns>مقدار رمزگشایی شده</returns> public object Run() { string l_IDString = (string)QrService.Read(EmguCVHelper.ScaleImage((Image <Bgr, byte>)Input, 0.25).ToBitmap()); Guid l_Id = Guid.Empty; Guid.TryParse(l_IDString, out l_Id); return(l_Id); }
/// <summary> /// متد سازنده /// </summary> public MainViewModel() { if (!IsInDesignMode) { try { //Proxies are created QrService = new QRServiceProxy(); AutomatedAttendanceSystem = new AAS.Proxy.AutomatedAttendanceSystemProxy(); FaceRecognition = new FaceRecognitionServiceProxy(); intitalizeAttendanceMethods(); EmguCVHelper.StartCapture(); EmguCVHelper.CaptureImageIsRefreshed += RefreshImage; m_restTimer = new Timer(3000); m_restTimer.Elapsed += restTimer_Elapsed; } catch (Exception ex) { Exception exep = ex; { MessageBox.Show(exep.Message); } while ((exep = exep.InnerException) != null) { ; } } m_logs = new List <Log>(); } else { Employee employee = new Employee() { FirstName = "احمد", LastName = "رحیمی", Gender = Gender.Male, DateOfBirth = new DateTime(1980, 01, 01), DateOfEmployement = new DateTime(2000, 04, 12), IdentityNumber = "13654", NationalID = new IRNationalID("000-000004-3"), EmployeeID = new EmployeeID(0, 4, 1), ProfilePicture = new Bitmap(@"G:\_DATA\dummy.png"), }; DetectedEmployee = employee; //DetectedEmployee = null; ErrorMessage = (string)Application.Current.FindResource("FRSCouldNotDetect"); AlternativeMethodMessage = (string)Application.Current.FindResource("FRSCouldNotDetectAlternativeMethod"); EntryOrExit = string.Format((string)Application.Current.FindResource("Entry")); EntryOrExitHour = DateTime.Now; } }
private void detectAndRecognizeFace() { //needs preproessing if (SelectedLogFilter != null) { if (SelectedLogFilter.Picture != null) { Image <Bgr, byte> image = new Image <Bgr, byte>(SelectedLogFilter.Picture); DetectedFaces = FaceRecognitionService.DetectFace(EmguCVHelper.ScaleImage(image, 0.25).ToBitmap()); QRCodeContent = (string)QRService.Read(SelectedLogFilter.Picture); Guid id = Guid.Empty; int i = 0; if (DetectedFaces.Count > 0) { do { string str = FaceRecognitionService.RecognizeFace(DetectedFaces[i].Bitmap); Guid.TryParse(str, out id); i++; } while (id != Guid.Empty && i < DetectedFaces.Count); } if (id != Guid.Empty) { DetectedEmployee = AutomatedAttendanceSystem.RetrieveEmployee(id); } else { DetectedEmployee = null; } //if (DetectedFaces.Count > 0) //{ // EmguCVHelper.DrawObjectsBoundaries(image, DetectedFaces, 0.25); // SelectedLogFilter.Picture = image.ToBitmap(); //} } } }
/// <summary> /// متد سازنده /// </summary> public MainViewModel() { if (!IsInDesignMode) { try { FaceRecognitionService = new FaceRecognitionServiceProxy(); if (FaceRecognitionService != null) { EmguCVHelper.StartCapture(); EmguCVHelper.CaptureImageIsRefreshed += RefreshImage; } } catch (Exception ex) { MessageBox.Show(ex.Message); } } m_savedFrames = new List <Bitmap>(); processCommandLineArgs(); }
private void SensorAllFramesReady(object sender, AllFramesReadyEventArgs e) { Skeleton[] skeletons = new Skeleton[0]; bool depthReceived = false; _ultimoFrameTomado = DateTime.Now.Ticks; using (DepthImageFrame framesDistancia = e.OpenDepthImageFrame()) { if (framesDistancia == null) { return; } framesDistancia.CopyDepthImagePixelDataTo(this.depthPixels); depthReceived = true; if (datosDistancia == null) { datosDistancia = new short[framesDistancia.PixelDataLength]; } if (colorImagenDistancia == null) { colorImagenDistancia = new byte[framesDistancia.PixelDataLength * 4]; } framesDistancia.CopyPixelDataTo(datosDistancia); } using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame != null) { colorFrame.CopyPixelDataTo(this.colorPixels); System.Drawing.Bitmap bmp = EmguCVHelper.ImageToBitmap(colorFrame); videoController.InicioGrabacion = DateTime.Now.Ticks; if (videoController.framesBmp.Count < 2000) { videoController.framesBmp.Add(bmp); } else { videoController.ForzarReinicioDeVideo(); } Image <Hsv, Byte> currentFrameHSV = new Image <Hsv, byte>(bmp); Image <Gray, Byte> grayFrame = currentFrameHSV.Convert <Gray, Byte>(); Image <Gray, Byte> imageHSVDest = currentFrameHSV.InRange(lowerLimit, upperLimit); imageHSVDest.Erode(100); VectorOfVectorOfPoint vectorOfPoint = EmguCVHelper.FindContours(imageHSVDest); for (int i = 0; i < vectorOfPoint.Size; i++) { var contour = vectorOfPoint[i]; var area = CvInvoke.ContourArea(contour); if (area > 100) { System.Drawing.Rectangle rec = CvInvoke.BoundingRectangle(contour); Point p1 = new Point(rec.X, rec.Y); Point p2 = new Point(rec.X + rec.Width, rec.Y + rec.Height); ObjetoX = (p1.X + p2.X) / 2; ObjetoY = (p1.Y + p2.Y) / 2; if (true == depthReceived) { this.sensor.CoordinateMapper.MapDepthFrameToColorFrame( DepthFormat, this.depthPixels, ColorFormat, this.colorCoordinates); int depthIndex = (int)ObjetoX + ((int)ObjetoY * this.depthWidth); DepthImagePixel depthPixel = this.depthPixels[depthIndex]; ObjetoZ = datosDistancia[depthIndex] >> 3; int X = (int)ObjetoX / this.colorToDepthDivisor; int Y = (int)ObjetoY / this.colorToDepthDivisor; } if (ObjetoZ > 0) { skelObjeto = DistanceHelper.ObtenerSkelPoint((int)ObjetoX, (int)ObjetoY, ObjetoZ, this.sensor); flagObjeto = true; } } } colorFrame.CopyPixelDataTo(this.colorPixels); // Write the pixel data into our bitmap this.colorBitmap.WritePixels( new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight), this.colorPixels, this.colorBitmap.PixelWidth * sizeof(int), 0); } } using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size //dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); dc.DrawImage(this.colorBitmap, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); if (skeletons.Length != 0) { foreach (Skeleton skel in skeletons) { //Skeleton skel = skeletons[0]; if (skel.TrackingState == SkeletonTrackingState.Tracked) { this.DrawBonesAndJoints(skel, dc); } //Toma de mediciones de mano, hombro y codo derecho: ManoDerecha = skel.Joints[JointType.HandRight]; //Joint munecaDer = skel.Joints[JointType.WristRight]; CodoDerecho = skel.Joints[JointType.ElbowRight]; HombroDerecho = skel.Joints[JointType.ShoulderRight]; //Dibujo un punto negro sobre el objeto detectado Point objeto = new Point(this.ObjetoX, this.ObjetoY); dc.DrawEllipse(Brushes.Black, new Pen(Brushes.Black, 5), objeto, 5, 5); if ((HombroDerecho.TrackingState == JointTrackingState.Tracked) && (ManoDerecha.TrackingState == JointTrackingState.Tracked) && (CodoDerecho.TrackingState == JointTrackingState.Tracked)) { if (flagObjeto && !flagSkeleton) { puntos = new Puntos(HombroDerecho, CodoDerecho, ManoDerecha, skelObjeto); CalcularAngulosFinales(puntos); } //Console.WriteLine($"Mano X Y Z {handRight.Position.X} {handRight.Position.Y} {handRight.Position.Z}"); //Console.WriteLine($"Objeto X Y Z {skelObjeto.X} {skelObjeto.Y} {skelObjeto.Z}"); #region FinalizacionDelEjercicio if (!_objetoTomado && DistanceHelper.ObtenerDistancia(ManoDerecha, skelObjeto) < 0.2) { _objetoTomadoTiempo = DateTime.Now.AddSeconds(1).Ticks; _objetoTomado = true; } if (!_brazoMovido && _objetoTomadoTiempo < DateTime.Now.Ticks) { _vueltaPosicionInicialTiempo = DateTime.Now.AddSeconds(1).Ticks; arduinoController.EnviarAngulosFromAngulosServos(new AngulosServos(ArduinoController.BRAZO_GB)); _brazoMovido = true; } if (_vueltaPosicionInicialTiempo < DateTime.Now.Ticks) { Ejercicio.FinalizoConExito = true; Cerrar(); } #endregion FinalizacionDelEjercicio } } } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } }