public static void GenerateThumbnail(MediaViewModel mediaViewModel) { switch (mediaViewModel.MediaType) { case MediaType.Photo: ThreadPool.QueueUserWorkItem(delegate { PictureTools.GenerateThumbnailOfPicture(mediaViewModel.AbsoluteURL, mediaViewModel.ID_Media, setImage); }); break; case MediaType.Video: ThreadPool.QueueUserWorkItem(delegate { VideoTools.CaptureScreen(mediaViewModel.AbsoluteURL, mediaViewModel.ID_Media, new TimeSpan(0, 0, 30, 0), "Thumbnail", 0.5, null, setImage); }); break; case MediaType.Musique: ThreadPool.QueueUserWorkItem(delegate { AudioTools.ReadMP3CoverArt(mediaViewModel.AbsoluteURL, mediaViewModel.ID_Media, setImage); }); break; case MediaType.Autre: break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Performs processing of the most recent frame from the video feed. /// This is an Ansyncronous method. /// </summary> /// <returns>An Asyncronous <c>Task</c></returns> private async Task ProcessFrames() { if (this.Camera == null) { Globals.Log.Error("Camera device not set. Shutting down."); return; } string detectorPath = ConfigurationManager.AppSettings["DetectorPath"]; string basePath = System.IO.Path.GetDirectoryName(ConfigurationManager.AppSettings["CameraSettingsPath"]); string detectorPathFull = System.IO.Path.Join(basePath, detectorPath); string protoFile = ConfigurationManager.AppSettings["ProtoFile"]; string detectorModelFile = ConfigurationManager.AppSettings["DetectorModelFile"]; string embeddingModelFile = ConfigurationManager.AppSettings["EmbeddingModelFile"]; string recogniserModelFile = ConfigurationManager.AppSettings["RecogniserModelFile"]; string labelEncoderFile = ConfigurationManager.AppSettings["LabelEncoderFile"]; // build the detector. DnnCaffeFaceDetector detector = new DnnCaffeFaceDetector(CameraConfig.MinConfidence, detectorPathFull, protoFile, detectorModelFile, embeddingModelFile, recogniserModelFile, labelEncoderFile); // show window. Cv2.NamedWindow(this.Camera.CameraName, WindowMode.AutoSize); bool resizeWindow = true; int frameCenterX = 0; int frameCenterY = 0; FacesList facesList; // loop indefinitely. while (!this.IsStopping) { try { int fps = Convert.ToInt32(this.Camera.Fps()); Mat frame = this.Camera.GetCurrentFrame(); if (frame != null) { if (this.IsAutoTracking) { // Todo: Implement Auto Tracking. if (frameCenterX == 0) { // calculate center of frame. frameCenterX = frame.Width / 2; frameCenterY = frame.Height / 2; } // process faces in the frame. frame = detector.Detect(frame, out facesList); // todo: track highest confidence face } // On Screen Display (OSD) variables. string autoTrackText = ""; string recordingText = ""; string watermarkText = ""; Scalar rgbColor; // set up text for OSD. if (this.IsAutoTracking) { autoTrackText = "ON"; } else { autoTrackText = "OFF"; } if (this.Camera.IsContinuousRecording) { recordingText = "ON"; } else { recordingText = "OFF"; } // set up colours for OSD. if (this.Camera.IsContinuousRecording) { rgbColor = new Scalar(0, 0, 255); } else if (this.IsAutoTracking) { rgbColor = new Scalar(0, 255, 0); } else { rgbColor = new Scalar(0, 255, 255); } watermarkText = string.Format("Auto Tracking: {0} Continuous Recording: {1} FPS: {2}", autoTrackText, recordingText, fps); Point watermarkLocation = new Point(10, 22); Cv2.PutText(frame, watermarkText, watermarkLocation, HersheyFonts.HersheyComplex, 0.9, rgbColor); if (resizeWindow) { Cv2.ResizeWindow(this.Camera.CameraName, frame.Width, frame.Height); resizeWindow = false; } Cv2.ImShow(this.Camera.CameraName, frame); } int key = Cv2.WaitKeyEx((int)(1000 / fps)); if (key == 'q') { break; } switch (key) { case 2490368: // Up Arrow Key Camera.MoveUp(this.ptzLock); break; case 2621440: // Down Arrow Key Camera.MoveDown(this.ptzLock); break; case 2424832: // Left Arrow Key Camera.MoveLeft(this.ptzLock); break; case 2555904: // Right Arrow Key Camera.MoveRight(this.ptzLock); break; case 'z': Camera.ZoomIn(this.ptzLock); break; case 'x': Camera.ZoomOut(this.ptzLock); break; case 'a': this.IsAutoTracking = VideoTools.FlipBool(this.IsAutoTracking); if (!this.IsAutoTracking) { Camera.StopPtz(); } break; case 'c': Camera.IsContinuousRecording = VideoTools.FlipBool(Camera.IsContinuousRecording); break; } } catch (Exception detail) { Globals.Log.Error(detail); } } }