static async Task Main(string[] args) { Console.WriteLine("Hello World!"); CancellationTokenSource cts = new CancellationTokenSource(); Console.CancelKeyPress += (sender, a) => { a.Cancel = true; cts.Cancel(); }; string configurationFilePath; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { configurationFilePath = @"/share/JAVS.Hypnos.Pi.HDMIController/PiSettings.json"; } else { configurationFilePath = @"./PiSettings.json"; } _piSettings = await JSONFile.LoadAsync <PiSettings>(configurationFilePath); FaceDetectionService faceDetectionService = new FaceDetectionService(_piSettings); await faceDetectionService.Init(); faceDetectionService.ListenFor <FaceDetectionStats>((stats) => { Console.WriteLine("Face Change."); string output = ""; if (stats.IsZeroFaceAlert) { output = @"vcgencmd display_power 0".Bash(); } else if (stats.FaceRectangles?.Count > 0) { output = @"xset s reset"; output += @"vcgencmd display_power 1".Bash(); } Console.WriteLine(output); //if (stats.IsZeroFaceAlert) // output = @"echo 'standby 0' | cec-client -s -d 1".Bash(); //else if(stats.FaceRectangles?.Count > 0) // output = @"echo 'standby 1' | cec-client -s -d 1".Bash(); }); await faceDetectionService.Join(new JoinGroupRequest() { IsHDMIController = true, Password = "******" }); while (!cts.IsCancellationRequested) { } }
static async Task Main(string[] args) { _faceDetectionConfiguration = new FaceDetectionConfiguration() { ScaleFactor = 1.2, MinimumNeighbors = 5, MinimumFaceWidth = 20, MinimumFaceHeight = 20, FaceTimeoutInSeconds = 5 }; Console.WriteLine("Hello World!"); CancellationTokenSource cts = new CancellationTokenSource(); Console.CancelKeyPress += (sender, a) => { a.Cancel = true; cts.Cancel(); }; string configurationFilePath; if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { configurationFilePath = @"/share/JAVS.Hypnos.Pi.Detector/PiSettings.json"; } else { configurationFilePath = @"./PiSettings.json"; } _piSettings = await JSONFile.LoadAsync <PiSettings>(configurationFilePath); FaceDetectionService faceDetectionService = new FaceDetectionService(_piSettings); await faceDetectionService.Init(); faceDetectionService.ListenFor <ClientGroupStats>((stats) => { foreach (var group in stats.ConnectedClientGroupCounts) { Console.WriteLine($"{group.Key}: {group.Value} Clients Connected."); _clientGroupStats = stats; } }); faceDetectionService.ListenFor <FaceDetectionConfiguration>((config) => { _faceDetectionConfiguration = config; }); await faceDetectionService.Join(new JoinGroupRequest() { IsDetector = true, Password = "******" }); RunFacialDetection(cts, faceDetectionService); }
public IHttpActionResult Detect([FromBody] byte[] photo) { if (photo == null) { return(BadRequest("No picture")); } try { IFaceDetectionService faceDetectionService = new FaceDetectionService(); Image <Gray, byte> facePhoto = faceDetectionService.DetectFaceAsGrayImage(photo.ByteArrayToImage()); return(Ok(facePhoto.ToBitmap().ImageToByteArray())); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private async Task ProcessImage() { if (_photo == null) { return; } IsBusy = true; var stream = await _photo.OpenAsync(FileAccessMode.Read); var res = await FaceDetectionService.ProcessImageAsync(stream.AsStream(), FaceApiKey); Faces = res.ToList(); OnPropertyChanged(() => Faces); FaceDetectionService.CalculateIPDAsync(Faces, _controlIPD); IsBusy = false; _annotationCanvasUpdateEvent.Publish(true); }
public static void ClassInitialize(TestContext context) => faceDetectionService = new FaceDetectionService();
public static void RunFacialDetection(CancellationTokenSource cts, FaceDetectionService service) { string haarCascadeFile = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? _piSettings.LinuxPathToFaceHaarCascade : _piSettings.DevPathToFaceHaarCascade; Console.WriteLine("Path to cascade classifier: " + haarCascadeFile); if (!File.Exists(haarCascadeFile)) { Console.WriteLine("NO HAAR FILE FOUND"); return; } Mat sourceImg = new Mat(); DateTime lastFaceTime = DateTime.Now; bool wasSearchingForFace = true; VideoCapture captureInstance = new VideoCapture(0); while (!captureInstance.IsOpened()) { Console.WriteLine("Video Capture being reopened."); captureInstance.Open(0); Thread.Sleep(500); } using (CascadeClassifier cascade = new CascadeClassifier(haarCascadeFile)) //using (Window webCamWindow = new Window("webCamWindow")) { while (!cts.IsCancellationRequested) { captureInstance.Read(sourceImg); if (sourceImg.Empty()) { break; } var grayImage = new Mat(); Cv2.CvtColor(sourceImg, grayImage, ColorConversionCodes.BGRA2GRAY); Cv2.EqualizeHist(grayImage, grayImage); var faces = cascade.DetectMultiScale( image: grayImage, scaleFactor: _faceDetectionConfiguration.ScaleFactor, minNeighbors: _faceDetectionConfiguration.MinimumNeighbors, flags: HaarDetectionType.DoRoughSearch | HaarDetectionType.ScaleImage, minSize: new Size(_faceDetectionConfiguration.MinimumFaceWidth, _faceDetectionConfiguration.MinimumFaceHeight) ); if (faces.Length > 0) { lastFaceTime = DateTime.Now; if (wasSearchingForFace) { service.PublishFaceDetectionStats(new FaceDetectionStats { FaceRectangles = faces.Select(face => new Shared.FaceRect { X = face.X, Y = face.Y, Width = face.Width, Height = face.Height }).ToList() }); wasSearchingForFace = false; } } else if (DateTime.Now - lastFaceTime >= TimeSpan.FromSeconds(_faceDetectionConfiguration.FaceTimeoutInSeconds)) { if (!wasSearchingForFace) { service.PublishFaceDetectionStats(new FaceDetectionStats { IsZeroFaceAlert = true }); } wasSearchingForFace = true; } } } }
int i = 0; // 图片处理计数器 public FrmFacePhoto() { InitializeComponent(); _personFaceRepository = new PersonFaceRepository(); _faceDetectionService = new FaceDetectionService(); }
private void Init() { _faceDetectionService = new FaceDetectionService(); _personFaceRepository = new PersonFaceRepository(); _cache = _personFaceRepository.GetAllPersonFaces(); }
public FaceDetectionController(FaceDetectionService faceDetectionService) { _faceDetectionService = faceDetectionService; }
private void InitializeServices() { _faceDetectionService = new FaceDetectionService(); _faceDetectionService.ImageWithDetectionChanged += _faceDetectionService_ImageChanged; }