public MediaPlaybackViewModel() { _mouseService = App.Container.Resolve <MouseService>(); PlaybackService.Playback_MediaPlaying += OnPlaying; PlaybackService.Playback_MediaPaused += OnPaused; PlaybackService.Playback_MediaTimeChanged += Playback_MediaTimeChanged; PlaybackService.Playback_MediaLengthChanged += Playback_MediaLengthChanged; PlaybackService.Playback_MediaBuffering += Playback_MediaBuffering; PlaybackService.Playback_MediaEndReached += Playback_MediaEndReach; PlaybackService.Playback_MediaFailed += Playback_MediaFailed; PlaybackService.Playback_MediaStopped += Playback_MediaStopped; PlaybackService.Playback_MediaTracksAdded += OnMediaTrackAdded; PlaybackService.Playback_MediaTracksDeleted += OnMediaTrackDeleted; PlaybackService.Playback_MediaParsed += Playback_MediaParsed; App.Container.Resolve <NetworkListenerService>().InternetConnectionChanged += MediaPlaybackViewModel_InternetConnectionChanged; Locator.PlaybackService.Playback_MediaSet += OnCurrentMediaChanged; Locator.PlaybackService.OnPlaylistChanged += PlaylistService_OnPlaylistChanged; Locator.PlaybackService.OnPlaylistEndReached += OnPlaylistEndReached; Locator.PlaybackService.OnRepeatChanged += OnRepeatChanged; Locator.PlaybackService.PlayingTypeChanged += OnPlayingTypeChanged; Window.Current.SizeChanged += OnSizeChanged; }
public override void Update(GameTime gt) { base.Update(gt); //If the cursor is over the object, and the button is down if (Body.BoundingRect.Contains((int)MouseService.Cursor.Position.X, (int)MouseService.Cursor.Position.Y)) { ImageRender.Color = HoverColor; if (MouseService.IsMouseButtonPressed(MouseButton.LeftButton)) { _hasFocus = true; } } else { ImageRender.Color = Color; } if (_hasFocus && MouseService.IsMouseButtonDown(MouseButton.LeftButton)) { Body.Position -= new Vector2(MouseService.Delta.X, MouseService.Delta.Y); } else if (_hasFocus && MouseService.IsMouseButtonUp(MouseButton.LeftButton)) { _hasFocus = false; } TextBody.Position = Body.Position + Vector2.One * 10f; }
private void UpdateDisplayImage() { RBSK rbsk = MouseService.GetStandardMouseRules(); rbsk.Settings.GapDistance = GapDistance; rbsk.Settings.BinaryThreshold = BinaryThreshold; PointF[] result = RBSKService.RBSK(CurrentImage, rbsk); using (Image <Bgr, Byte> img = CurrentImage.Clone()) { //if (!ROI.IsEmpty) //{ // img.ROI = ROI; //} if (result != null) { foreach (PointF point in result) { img.Draw(new CircleF(point, 2), new Bgr(Color.Yellow), 2); } } DisplayImage = ImageService.ToBitmapSource(img); } }
private void UpdateGapDistance() { if (CurrentResult != null) { CurrentResult.GapDistance = GapDistance; } RBSK rbsk = MouseService.GetStandardMouseRules(); rbsk.Settings.GapDistance = GapDistance; rbsk.Settings.BinaryThreshold = BinaryThreshold; PointF[] result = RBSKService.RBSK(CurrentImage, rbsk); using (Image <Bgr, Byte> img = CurrentImage.Clone()) { img.DrawPolyline(MotionTrack.Select(x => x.ToPoint()).ToArray(), false, new Bgr(Color.Blue), 2); if (result != null) { foreach (PointF point in result) { img.Draw(new CircleF(point, 2), new Bgr(Color.Yellow), 2); } } DisplayImage = ImageService.ToBitmapSource(img); } }
private void UpdateGapDistance() { RBSK rbsk = MouseService.GetStandardMouseRules(); rbsk.Settings.GapDistance = GapDistance; rbsk.Settings.BinaryThreshold = ThresholdValue; PointF[] result = RBSKService.RBSK(OriginalImage, rbsk); if (result == null || !result.Any()) { DisplayImage = ImageService.ToBitmapSource(OriginalImage); return; } using (Image <Gray, Byte> displayImage = OriginalImage.Convert <Gray, Byte>()) using (Image <Gray, Byte> binaryimage = displayImage.ThresholdBinary(new Gray(ThresholdValue), new Gray(255))) using (Image <Bgr, byte> drawImage = binaryimage.Convert <Bgr, byte>()) { foreach (PointF point in result) { drawImage.Draw(new CircleF(point, 2), new Bgr(Color.Yellow), 2); } DisplayImage = ImageService.ToBitmapSource(drawImage); } PreviewGenerated = false; Boundries = new ObservableCollection <BoundaryBaseViewModel>(); //Console.WriteLine(GapDistance); }
public override void Update(GameTime gameTime, Rectangle clientBound) { MouseService mouseService = ServicesHelper.GetService <MouseService>(); _position = mouseService.CurrentPosition; base.Update(gameTime, clientBound); }
public static void LClick(this KPoint point, int times) { for (int i = 0; i < times; i++) { MouseService.LeftClick(WindowsHandle, point.X, point.Y); Thread.Sleep(100); } }
private void ExecuteStopCommand() { MouseService.SetBusyState(); _cts?.Cancel(); _myStopwatch.Reset(); _currentStatusbarState = EStatusbarState.Default; SetCurrentBusinessData(); EnvironmentContainer.CreatePopUpWindow(EnvironmentContainer.ApplicationTitle, Application.Current.TryFindResource("CalculationStopped").ToString()); }
public BodyDetectionViewModel(ITrackedVideo headPoints = null, Dictionary <int, ISingleFrameResult> results = null, string file = "") { ThresholdValue = headPoints.ThresholdValue; Video = ModelResolver.Resolve <IVideo>(); VideoSettings = ModelResolver.Resolve <IVideoSettings>(); BlobDetector = new CvBlobDetector(); RBSK = MouseService.GetStandardMouseRules(); HeadPoints = results; FileLocation = file; OpenVideo(); }
private void ExecuteClearAllCommand() { MouseService.SetBusyState(); HierarchialData.RowData.Clear(); HierarchialData.Clear(); _myStopwatch.Reset(); SetCurrentBusinessData(); OnPropertyChanged(nameof(HierarchialData)); OnPropertyChanged(nameof(CollectionView)); }
public MainVM(MouseService mouseService) { MS = mouseService; foreach (var screen in Screen.AllScreens) { // For each screen, add the screen properties to a list box. Specs += "Device Name: " + screen.DeviceName + "\n"; Specs += "Bounds: " + screen.Bounds.ToString() + "\n"; Specs += "Type: " + screen.GetType().ToString() + "\n"; Specs += "Working Area: " + screen.WorkingArea.ToString() + "\n"; Specs += "Primary Screen: " + screen.Primary.ToString() + "\n\n"; } }
public PlayVideoViewModel(HistoryService historyService, IMediaService mediaService, VlcService mediaPlayerService) : base(historyService, mediaService, mediaPlayerService) { _subtitles = new ObservableCollection <Subtitle>(); _subtitlesTracks = new Dictionary <int, string>(); _audioTracks = new Dictionary <int, string>(); #if NETFX_CORE _mouseService = App.Container.Resolve <MouseService>(); #endif _setSubTitlesCommand = new SetSubtitleTrackCommand(); _setAudioTrackCommand = new SetAudioTrackCommand(); _openSubtitleCommand = new OpenSubtitleCommand(); }
private void UpdateBinaryImage() { RBSK rbsk = MouseService.GetStandardMouseRules(); rbsk.Settings.BinaryThreshold = SliderValue; using (Image <Bgr, Byte> image = new Image <Bgr, byte>(ImageLocation)) using (Image <Gray, Byte> grayImage = image.Convert <Gray, Byte>()) using (Image <Gray, Byte> filteredImage = grayImage.SmoothMedian(rbsk.Settings.FilterLevel)) using (Image <Gray, Byte> binaryImage = filteredImage.ThresholdBinary(new Gray(rbsk.Settings.BinaryThreshold), new Gray(255))) { Image2 = ImageService.ToBitmapSource(binaryImage); } }
private async Task ExecuteStartCalculationCommandAsync() { MouseService.SetBusyState(); EnvironmentContainer.CreatePopUpWindow(EnvironmentContainer.ApplicationTitle, Application.Current.TryFindResource("CalculationStart").ToString()); _myStopwatch.Reset(); _myStopwatch.Start(); _currentStatusbarState = EStatusbarState.Busy; SetCurrentBusinessData(); _cts?.Dispose(); _cts = new CancellationTokenSource(); await EnvironmentContainer.Instance.StartCalculationAsync(HierarchialData.Where(p => p.HasChildren).ToList(), _cts.Token).ConfigureAwait(false); }
public MediaPlaybackViewModel() { _mouseService = App.Container.Resolve <MouseService>(); PlaybackService.Playback_StatusChanged += Playback_StatusChanged; PlaybackService.Playback_MediaTimeChanged += Playback_MediaTimeChanged; PlaybackService.Playback_MediaLengthChanged += Playback_MediaLengthChanged; PlaybackService.Playback_MediaBuffering += Playback_MediaBuffering; PlaybackService.Playback_MediaEndReached += Playback_MediaEndReach; PlaybackService.Playback_MediaFailed += Playback_MediaFailed; PlaybackService.Playback_MediaStopped += Playback_MediaStopped; PlaybackService.Playback_MediaTracksUpdated += Playback_MediaTracksUpdated; PlaybackService.Playback_MediaParsed += Playback_MediaParsed; PlaybackService.Playback_MediaSet += PlaybackService_MediaSet; App.Container.Resolve <NetworkListenerService>().InternetConnectionChanged += MediaPlaybackViewModel_InternetConnectionChanged; }
internal void Initialize(D3D11Host host) { Services = new GameServiceContainer(); ServiceLocator.Initialize(Services); Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", host.GraphicsDevice); Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services); Services.AddService<IGraphicsDeviceService>(host); Services.AddService(host.GraphicsDevice); _mouse = new MouseService(host); Services.AddService<IMouseService>(_mouse); _mouse.ButtonDown += OnMouseButtonDown; _keyboard = new KeyboardService(host); Services.AddService<IKeyboardService>(_keyboard); _timer = new TimerService(); Services.AddService<ITimerService>(_timer); Services.AddService(new FastSpriteBatch(host.GraphicsDevice)); _timer.LastFrameUpdateTime = _gameTime; _timer.LastFrameRenderTime = _gameTime; SpriteBatch = new SpriteBatch(host.GraphicsDevice); Services.AddService(SpriteBatch); Content = new ContentManager(Services); Content.RootDirectory = Environment.CurrentDirectory; SpriteManager = new SpriteManagerService(Content); Services.AddService<ISpriteManagerService>(SpriteManager); SpriteManager.LoadSpriteSheet("Textures/Hulls.json"); Host = host; World = new EntityWorld(false, false, false); int drawDepth = 0; World.CreateComponentPool<Transform>(200, 200); World.SystemManager.SetSystem(new GridRendererSystem(), Artemis.Manager.GameLoopType.Draw, drawDepth++); World.InitializeAll(); World.CreateCamera(Constants.ActiveCameraTag, Host.GraphicsDevice); Emitter = new ParticleEmitterComponent(); }
private void ProcessFrame() { if (string.IsNullOrWhiteSpace(ImageLocation)) { return; } if (string.IsNullOrWhiteSpace(BackgroundLocation)) { return; } RBSK rbsk = MouseService.GetStandardMouseRules(); rbsk.Settings.BinaryThreshold = SliderValue; using (Image <Bgr, Byte> image = new Image <Bgr, byte>(ImageLocation)) using (Image <Gray, Byte> backgroundImage = new Image <Gray, byte>(BackgroundLocation)) using (Image <Gray, Byte> grayImage = image.Convert <Gray, Byte>()) using (Image <Gray, Byte> filteredImage = grayImage.SmoothMedian(rbsk.Settings.FilterLevel)) using (Image <Gray, Byte> binaryImage = filteredImage.ThresholdBinary(new Gray(rbsk.Settings.BinaryThreshold), new Gray(255))) using (Image <Gray, Byte> backgroundNot = backgroundImage.Not()) using (Image <Gray, Byte> finalImage = binaryImage.Add(backgroundNot)) //using (Image<Gray, Byte> finalImageNot = finalImage.Not()) { double gapDistance = GetBestGapDistance(grayImage, rbsk); rbsk.Settings.GapDistance = gapDistance; PointF[] result = RBSKService.RBSK(finalImage, rbsk); Image1 = ImageService.ToBitmapSource(image); using (Image <Bgr, Byte> dImage = image.Clone()) { foreach (PointF point in result) { dImage.Draw(new CircleF(point, 3), new Bgr(Color.Yellow), 3); } Image3 = ImageService.ToBitmapSource(dImage); } } }
public override void Update(GameTime gt) { base.Update(gt); MouseService.Cursor.Position = new Vector2(MouseService.Cursor.Position.X + (_moveCursor.Position.X * 5), MouseService.Cursor.Position.Y - (_moveCursor.Position.Y * 5)); if (MouseService.IsMouseButtonPressed(MouseButton.RightButton) || _emitButton.Pressed()) { EntityGame.Log.Write("Mouse button pressed, dispensing particles", this, Alert.Info); } if (MouseService.IsMouseButtonDown(MouseButton.RightButton) || _emitButton.Down()) { Spawner.Emit(30); } if (MouseService.IsMouseButtonReleased(MouseButton.RightButton) || _emitButton.Pressed()) { EntityGame.Log.Write("Mouse button released, stopping particles", this, Alert.Info); } }
public RenderingEngine() { LoadSettings(); MouseService = new MouseService(this); KeyboardService = new KeyboardService(this); SelectionService = new SelectionService(this); SelectionService.Completed += SelectionServiceOnCompleted; SelectionService.InComplete += SelectionServiceOnInComplete; MouseService.MouseMove += MouseServiceOnMouseMove; MouseService.MouseDown += MouseServiceOnMouseDown; MouseService.MouseUp += MouseServiceOnMouseUp; _tickerProvider.Tick += TickerProviderOnTick; ProcessorCompiler.CompileStart += ProcessorCompilerOnCompileStart; ProcessorCompiler.Finished += ProcessorCompilerOnFinished; }
private async Task ExecuteSaveCommandAsync() { if (InteractionService.ShowQuestionMessageBox(Application.Current.TryFindResource("QWantToSave").ToString()) == MessageBoxResult.No) { return; } MouseService.SetBusyState(); _cts?.Dispose(); _cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); bool result = await EnvironmentContainer.Instance.SaveHashAsync(HierarchialData.Where(p => p.HasChildren).ToList(), _cts.Token).ConfigureAwait(false); if (result) { InteractionService.ShowInformationMessageBox(Application.Current.TryFindResource("SuccessfullySaved").ToString()); } else { InteractionService.ShowErrorMessageBox(Application.Current.TryFindResource("SaveFailed").ToString()); } }
internal void Initialize(D3D11Host host) { if (IsInitialized) return; IsInitialized = true; Services = new GameServiceContainer(); ServiceLocator.Initialize(Services); _host = host; Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", _host.GraphicsDevice); Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services); Services.AddService<IGraphicsDeviceService>(host); Services.AddService(host.GraphicsDevice); _mouse = new MouseService(host); Services.AddService<IMouseService>(_mouse); _mouse.ButtonDown += OnMouseButtonDown; _keyboard = new KeyboardService(host); Services.AddService<IKeyboardService>(_keyboard); _timer = new TimerService(); Services.AddService<ITimerService>(_timer); Services.AddService(new FastSpriteBatch(host.GraphicsDevice)); _timer.LastFrameUpdateTime = _gameTime; _timer.LastFrameRenderTime = _gameTime; SpriteBatch = new SpriteBatch(host.GraphicsDevice); Services.AddService(SpriteBatch); Content = new ContentManager(Services); Content.RootDirectory = Environment.CurrentDirectory; SpriteManager = new SpriteManagerService(Content); Services.AddService<ISpriteManagerService>(SpriteManager); //LoadHullSprites("textures/hulls.json"); Artemis.System.EntitySystem.BlackBoard.SetEntry("ContentManager", Content); World = new EntityWorld(false, false, false); World.CreateComponentPool<Transform>(200, 200); _gridSystem = new GridRendererSystem(); _gridSystem.IsEnabled = false; World.SystemManager.SetSystem(_gridSystem, Artemis.Manager.GameLoopType.Draw, 1); //World.SystemManager.SetSystem(new ShipRendererSystem(), Artemis.Manager.GameLoopType.Draw, 2); World.SystemManager.SetSystem(new SceneGraphRendererSystem<StandardShipModelRenderer>(new StandardShipModelRenderer()), Artemis.Manager.GameLoopType.Draw, 3); World.SystemManager.SetSystem(new BoundingBoxRendererSystem(), Artemis.Manager.GameLoopType.Draw, 4); World.SystemManager.SetSystem(new GenericDrawableRendererSystem(), Artemis.Manager.GameLoopType.Draw, 5); _hardpointRendererSystem = new HardpointRendererSystem(); _hardpointRendererSystem.IsEnabled = false; World.SystemManager.SetSystem(_hardpointRendererSystem, Artemis.Manager.GameLoopType.Draw, 6); World.SystemManager.SetSystem(new CameraControlSystem(), Artemis.Manager.GameLoopType.Update, 1); _transformSystem = new MouseControlledTransformSystem(); World.SystemManager.SetSystem(_transformSystem, Artemis.Manager.GameLoopType.Update, 2); World.SystemManager.SetSystem(new ShipUpdateSystem(), Artemis.Manager.GameLoopType.Update, 3); World.SystemManager.SetSystem(new BoundingBoxSelectionSystem(), Artemis.Manager.GameLoopType.Update, 4); World.SystemManager.SetSystem(new ShowThrusterTrailsOverrideSystem(), Artemis.Manager.GameLoopType.Update, 5); World.InitializeAll(); CameraEntity = World.CreateCamera(Constants.ActiveCameraTag, _host.GraphicsDevice); CameraEntity.Tag = Constants.ActiveCameraTag; Camera = CameraEntity.GetComponent<Camera>(); GridEntity = World.CreateGrid(new Vector2(50, 50), GridColor); World.CreateCircle(Vector2.Zero, 10, 8, XnaColor.Red * 0.4f); host.PreviewKeyDown += HandleKeyboardInput; EditorService = new ShipEditorService(_mouse, World); CreateNewShipModelCommand.Execute(null); EditorService.SelectedPartEntities.CollectionChanged += (o, e) => { if (e.NewItems != null && e.NewItems.Count > 0) { var color = e.NewItems.Cast<Entity>().First().GetComponent<IShipPartComponent>().Part.Color; _selectedColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedColor))); } }; _mouse.WheelChanged += OnWheelChanged; IsHardpointsVisible = false; LoadHullSprites("textures/hulls.json"); IsGridVisible = true; }
public static void LClick(this KPoint point) { MouseService.LeftClick(WindowsHandle, point.X, point.Y); }
// move the mouse private void MoveMouse_Tick(object sender, EventArgs e) { Random gen = new Random(); MouseService.MoveMouse(gen.Next(-25, 25), gen.Next(-25, 25)); }
public MediaPlaybackViewModel() { _mouseService = App.Container.Resolve <MouseService>(); }
private void UpdateFrameNumber() { Video.SetFrame(SliderValue); using (Image <Bgr, Byte> orig = Video.GetFrameImage()) using (Image <Gray, Byte> origGray = orig.Convert <Gray, Byte>()) using (Image <Gray, Byte> binary = origGray.ThresholdBinary(new Gray(ThresholdValue), new Gray(255))) using (Image <Gray, Byte> subbed = BinaryBackground.AbsDiff(binary)) { CvBlobs blobs = new CvBlobs(); BlobDetector.Detect(subbed, blobs); CvBlob mouseBlob = null; double maxArea = -1; foreach (var blob in blobs.Values) { if (blob.Area > maxArea) { mouseBlob = blob; maxArea = blob.Area; } } //double gapDistance = GetBestGapDistance(rbsk); double gapDistance = 50; RBSK.Settings.GapDistance = gapDistance; //PointF[] headPoints = ProcessFrame(orig, RBSK); PointF center = mouseBlob.Centroid; //LineSegment2DF[] targetPoints = null; Point[] mouseContour = mouseBlob.GetContour(); orig.DrawPolyline(mouseContour, true, new Bgr(Color.Cyan)); Image1 = ImageService.ToBitmapSource(orig); PointF[] result; if (HeadPoints != null) { result = HeadPoints[SliderValue].HeadPoints; } else { double prob = 0; RBSK headRbsk = MouseService.GetStandardMouseRules(); headRbsk.Settings.GapDistance = 65; headRbsk.Settings.BinaryThreshold = 20; List <List <PointF> > allKeyPoints = headRbsk.FindKeyPoints(mouseContour, headRbsk.Settings.NumberOfSlides, false); result = headRbsk.FindPointsFromRules(allKeyPoints[0], binary, ref prob); } if (result != null) { using (Image <Bgr, Byte> test = orig.Clone()) { foreach (var point in result) { test.Draw(new CircleF(point, 3), new Bgr(Color.Red), 3); } Image1 = ImageService.ToBitmapSource(test); } } else { return; } RotatedRect rotatedRect = CvInvoke.MinAreaRect(mouseContour.Select(x => new PointF(x.X, x.Y)).ToArray()); //Console.WriteLine("Size: " + rotatedRect.Size); ISkeleton skel = ModelResolver.Resolve <ISkeleton>(); Image <Gray, Byte> tempBinary = binary.Clone(); System.Drawing.Rectangle rect = mouseBlob.BoundingBox; Image <Gray, Byte> binaryRoi = tempBinary.GetSubRect(rect); using (Image <Bgr, Byte> displayImage = subbed.Convert <Bgr, Byte>()) using (Image <Gray, Byte> skelImage = skel.GetSkeleton(binaryRoi)) using (Image <Bgr, Byte> drawImage = orig.Clone()) using (Image <Bgr, Byte> tempImage2 = new Image <Bgr, byte>(drawImage.Size)) { //----------------------------------------- if (SkelImage != null) { SkelImage.Dispose(); } SkelImage = skelImage.Clone(); //-------------------------------------------- tempImage2.SetValue(new Bgr(Color.Black)); ISpineFinding spineFinder = ModelResolver.Resolve <ISpineFinding>(); spineFinder.NumberOfCycles = 3; spineFinder.NumberOfIterations = 1; spineFinder.SkeletonImage = skelImage; //spineFinder.RotatedRectangle = rotatedRect; Image5 = ImageService.ToBitmapSource(skelImage); const int delta = 20; double smallestAngle = double.MaxValue; Point tailPoint = Point.Empty; for (int i = 0; i < mouseContour.Length; i++) { int leftDelta = i - delta; int rightDelta = i + delta; if (leftDelta < 0) { leftDelta += mouseContour.Length; } if (rightDelta >= mouseContour.Length) { rightDelta -= mouseContour.Length; } Point testPoint = mouseContour[i]; Point leftPoint = mouseContour[leftDelta]; Point rightPoint = mouseContour[rightDelta]; Vector v1 = new Vector(leftPoint.X - testPoint.X, leftPoint.Y - testPoint.Y); Vector v2 = new Vector(rightPoint.X - testPoint.X, rightPoint.Y - testPoint.Y); double angle = Math.Abs(Vector.AngleBetween(v1, v2)); if (angle < 30 && angle > 9) { if (angle < smallestAngle) { smallestAngle = angle; tailPoint = testPoint; } } } PointF headCornerCorrect = new PointF(result[2].X - rect.X, result[2].Y - rect.Y); PointF tailCornerCorrect = new PointF(tailPoint.X - rect.X, tailPoint.Y - rect.Y); PointF[] spine = spineFinder.GenerateSpine(headCornerCorrect, tailCornerCorrect); Point topCorner = mouseBlob.BoundingBox.Location; PointF[] spineCornerCorrected = new PointF[spine.Length]; for (int i = 0; i < spine.Length; i++) { spineCornerCorrected[i] = new PointF(spine[i].X + topCorner.X, spine[i].Y + topCorner.Y); } ITailFinding tailFinding = ModelResolver.Resolve <ITailFinding>(); double rotatedWidth = rotatedRect.Size.Width < rotatedRect.Size.Height ? rotatedRect.Size.Width : rotatedRect.Size.Height; List <Point> bodyPoints; if (result != null) { double firstDist = result[2].DistanceSquared(spineCornerCorrected.First()); double lastDist = result[2].DistanceSquared(spineCornerCorrected.Last()); if (firstDist < lastDist) { spineCornerCorrected = spineCornerCorrected.Reverse().ToArray(); } } double waistLength; double pelvicArea1, pelvicArea2; tailFinding.FindTail(mouseContour, spineCornerCorrected, displayImage, rotatedWidth, mouseBlob.Centroid, out bodyPoints, out waistLength, out pelvicArea1, out pelvicArea2); Console.WriteLine(smallestAngle); if (!tailPoint.IsEmpty) { drawImage.Draw(new CircleF(tailPoint, 4), new Bgr(Color.Red), 3); } if (bodyPoints != null && bodyPoints.Count > 0) { Point[] bPoints = bodyPoints.ToArray(); double volume = MathExtension.PolygonArea(bPoints); Emgu.CV.Structure.Ellipse fittedEllipse = PointCollection.EllipseLeastSquareFitting(bPoints.Select(x => x.ToPointF()).ToArray()); //CvInvoke.Ellipse(drawImage, fittedEllipse.RotatedRect, new MCvScalar(0, 0, 255), 2); Console.WriteLine("Volume: " + volume + " - " + (fittedEllipse.RotatedRect.Size.Width * fittedEllipse.RotatedRect.Size.Height) + ", Waist Length: " + waistLength); //Alter this to something better if (MathExtension.PolygonArea(bPoints) > (rotatedRect.Size.Height * rotatedRect.Size.Width) / 6 || true) { //tempImage2.FillConvexPoly(bPoints, new Bgr(Color.White)); tempImage2.DrawPolyline(bPoints, true, new Bgr(Color.White)); PointF centroid = MathExtension.FindCentroid(bPoints); System.Drawing.Rectangle minRect; Image <Gray, Byte> temp2 = new Image <Gray, byte>(tempImage2.Width + 2, tempImage2.Height + 2); CvInvoke.FloodFill(tempImage2, temp2, centroid.ToPoint(), new MCvScalar(255, 255, 255), out minRect, new MCvScalar(5, 5, 5), new MCvScalar(5, 5, 5)); using (Image <Gray, Byte> nonZeroImage = tempImage2.Convert <Gray, Byte>()) { int[] volume2 = nonZeroImage.CountNonzero(); Console.WriteLine("Volume2: " + volume2[0]); //int tester = 9; //using (Image<Gray, Byte> t1 = nonZeroImage.Erode(tester)) //using (Image<Gray, Byte> t2 = t1.Dilate(tester)) //using (Image<Gray, Byte> t3 = t2.Erode(tester)) //using (Image<Gray, Byte> t4 = t3.Dilate(tester)) //using (Image<Gray, Byte> t5 = t4.Erode(tester)) //using (Image<Gray, Byte> t6 = t5.Dilate(tester)) //using (Image<Gray, Byte> t7 = t6.Erode(tester)) //{ // Image6 = ImageService.ToBitmapSource(t7); //} } tempImage2.Draw(new CircleF(centroid, 2), new Bgr(Color.Blue), 2); double distanceToSpine = double.MaxValue; PointF p11 = PointF.Empty, p22 = PointF.Empty; for (int i = 1; i < spineCornerCorrected.Length; i++) { PointF point1 = spineCornerCorrected[i - 1]; PointF point2 = spineCornerCorrected[i]; double cDist = MathExtension.MinDistanceFromLineToPoint(point1, point2, centroid); if (cDist < distanceToSpine) { p11 = point1; p22 = point2; distanceToSpine = cDist; } } PointSideVector psv = MathExtension.FindSide(p11, p22, centroid); if (psv == PointSideVector.Below) { distanceToSpine *= -1; } Console.WriteLine(distanceToSpine + ","); } } for (int i = 1; i < spine.Length; i++) { PointF point1 = spine[i - 1]; PointF point2 = spine[i]; point1.X += topCorner.X; point1.Y += topCorner.Y; point2.X += topCorner.X; point2.Y += topCorner.Y; LineSegment2D line = new LineSegment2D(new Point((int)point1.X, (int)point1.Y), new Point((int)point2.X, (int)point2.Y)); drawImage.Draw(line, new Bgr(Color.Aqua), 2); tempImage2.Draw(line, new Bgr(Color.Cyan), 2); } drawImage.Draw(new CircleF(mouseBlob.Centroid, 2), new Bgr(Color.Blue), 2); Image3 = ImageService.ToBitmapSource(drawImage); Image6 = ImageService.ToBitmapSource(tempImage2); double rotatedRectArea = rotatedRect.Size.Width * rotatedRect.Size.Height; if (rotatedRectArea < 75000) { //Console.WriteLine(rotatedRectArea); //return; } else { //Console.WriteLine(rotatedRectArea); } double height = rotatedRect.Size.Height; double width = rotatedRect.Size.Width; //double angle = rotatedRect.Angle; bool heightLong = height > width; double halfLength; PointF[] vertices = rotatedRect.GetVertices(); if (heightLong) { halfLength = height; } else { halfLength = width; } halfLength /= 2; PointF[] sidePoints1 = new PointF[4], midPoints = new PointF[2]; PointF p1 = vertices[0], p2 = vertices[1], p3 = vertices[2], p4 = vertices[3]; double d1 = p1.DistanceSquared(p2); double d2 = p2.DistanceSquared(p3); if (d1 < d2) { //p1 and p2, p3 and p4 are side points sidePoints1[0] = p1; sidePoints1[1] = p2; sidePoints1[2] = p4; sidePoints1[3] = p3; midPoints[0] = p1.MidPoint(p4); midPoints[1] = p2.MidPoint(p3); } else { //p2 and p3, p1 and p4 are side points sidePoints1[0] = p1; sidePoints1[1] = p4; sidePoints1[2] = p2; sidePoints1[3] = p3; midPoints[0] = p1.MidPoint(p2); midPoints[1] = p3.MidPoint(p4); } PointF intersection1 = PointF.Empty; PointF intersection2 = PointF.Empty; using (Image <Gray, Byte> halfTest1 = origGray.CopyBlank()) using (Image <Gray, Byte> halfTest2 = origGray.CopyBlank()) { Point[] rect1 = new Point[] { new Point((int)sidePoints1[0].X, (int)sidePoints1[0].Y), new Point((int)midPoints[0].X, (int)midPoints[0].Y), new Point((int)midPoints[1].X, (int)midPoints[1].Y), new Point((int)sidePoints1[1].X, (int)sidePoints1[1].Y) }; Point[] rect2 = new Point[] { new Point((int)sidePoints1[2].X, (int)sidePoints1[2].Y), new Point((int)midPoints[0].X, (int)midPoints[0].Y), new Point((int)midPoints[1].X, (int)midPoints[1].Y), new Point((int)sidePoints1[3].X, (int)sidePoints1[3].Y) }; if (MathExtension.PolygonContainsPoint(rect1, center)) { //Rect 1 is head, look for line in r2 } else if (MathExtension.PolygonContainsPoint(rect2, center)) { //Rect 2 is head, look for line in r1 } else { //Something has gone wrong } halfTest1.FillConvexPoly(rect1, new Gray(255)); halfTest2.FillConvexPoly(rect2, new Gray(255)); //Image5 = ImageService.ToBitmapSource(halfTest1); //Image6 = ImageService.ToBitmapSource(halfTest2); //binary.Copy(holder1, halfTest1); //binary.Copy(holder2, halfTest2); int count1, count2; //using (Image<Gray, Byte> binaryInverse = subbed.Not()) using (Image <Gray, Byte> holder1 = subbed.Copy(halfTest1)) using (Image <Gray, Byte> holder2 = subbed.Copy(halfTest2)) { //Image4 = ImageService.ToBitmapSource(subbed); //Image5 = ImageService.ToBitmapSource(holder1); //Image6 = ImageService.ToBitmapSource(holder2); count1 = holder1.CountNonzero()[0]; count2 = holder2.CountNonzero()[0]; } PointF qr1 = PointF.Empty, qr2 = PointF.Empty, qr3 = PointF.Empty, qr4 = PointF.Empty; if (count1 > count2) { //holder 1 is head, holder 2 is rear qr1 = sidePoints1[2]; qr2 = sidePoints1[2].MidPoint(midPoints[0]); qr3 = sidePoints1[3].MidPoint(midPoints[1]); qr4 = sidePoints1[3]; } else if (count1 < count2) { //holder 2 is head, holder 1 is year qr1 = sidePoints1[0]; qr2 = sidePoints1[0].MidPoint(midPoints[0]); qr3 = sidePoints1[1].MidPoint(midPoints[1]); qr4 = sidePoints1[1]; } //fat line is qr2, qr3 PointF centerPoint = qr2.MidPoint(qr3); PointF i1 = qr2; PointF i2 = qr3; intersection1 = MathExtension.PolygonLineIntersectionPoint(centerPoint, i1, mouseContour); intersection2 = MathExtension.PolygonLineIntersectionPoint(centerPoint, i2, mouseContour); } double deltaX = halfLength * Math.Cos(rotatedRect.Angle * MathExtension.Deg2Rad); double deltaY = halfLength * Math.Sin(rotatedRect.Angle * MathExtension.Deg2Rad); const double scaleFactor = 0.25; PointF newPoint = new PointF((float)(center.X - (deltaX * scaleFactor)), (float)(center.Y - (deltaY * scaleFactor))); PointF intersectionPoint1 = PointF.Empty; PointF intersectionPoint2 = PointF.Empty; Point[] temp = null; PointF[] headPoints = RBSKService.RBSKParallel(binary, MouseService.GetStandardMouseRules(), ref temp); if (headPoints != null) { PointF tip = headPoints[2]; //targetPoints = new LineSegment2DF[3]; Point centerInt = new Point((int)newPoint.X, (int)newPoint.Y); //targetPoints[0] = new LineSegment2DF(centerInt, new PointF(tip.X, tip.Y)); Vector forwardVec = new Vector(tip.X - newPoint.X, tip.Y - newPoint.Y); Vector rotatedVec = new Vector(-forwardVec.Y, forwardVec.X); PointF i1 = new PointF((float)(newPoint.X + (rotatedVec.X * 1)), (float)(newPoint.Y + (rotatedVec.Y * 1))); PointF i2 = new PointF((float)(newPoint.X - (rotatedVec.X * 1)), (float)(newPoint.Y - (rotatedVec.Y * 1))); //targetPoints[1] = new LineSegment2DF(centerInt, i1); //targetPoints[2] = new LineSegment2DF(centerInt, i2); intersectionPoint1 = MathExtension.PolygonLineIntersectionPoint(newPoint, i1, mouseContour); intersectionPoint2 = MathExtension.PolygonLineIntersectionPoint(newPoint, i2, mouseContour); } //displayImage.Draw(mouseBlob.BoundingBox, new Bgr(Color.Red), 2); displayImage.Draw(new CircleF(mouseBlob.Centroid, 3), new Bgr(Color.Blue), 2); displayImage.Draw(rotatedRect, new Bgr(Color.Yellow), 3); //displayImage.Draw(mouseContour, new Bgr(Color.Aqua), 2); //displayImage.FillConvexPoly(new Point[] { new Point((int)sidePoints1[0].X, (int)sidePoints1[0].Y), new Point((int)midPoints[0].X, (int)midPoints[0].Y), new Point((int)midPoints[1].X, (int)midPoints[1].Y), new Point((int)sidePoints1[1].X, (int)sidePoints1[1].Y) }, new Bgr(Color.Blue)); //if (targetPoints != null) //{ // displayImage.Draw(targetPoints[0], new Bgr(Color.Green), 2); // displayImage.Draw(targetPoints[1], new Bgr(Color.Green), 2); // displayImage.Draw(targetPoints[2], new Bgr(Color.Green), 2); //} //if (!intersection1.IsEmpty && !intersection2.IsEmpty) //{ // LineSegment2DF lineSegment = new LineSegment2DF(intersection1, intersection2); // displayImage.Draw(lineSegment, new Bgr(Color.MediumPurple), 4); // //Console.WriteLine(lineSegment.Length); //} //displayImage.Draw(new CircleF(newPoint, 4), new Bgr(Color.MediumPurple), 3); //Console.WriteLine(rotatedRect.Angle); Image4 = ImageService.ToBitmapSource(displayImage); } } }
public BodyDetection() { ThresholdValue = 20; BlobDetector = new CvBlobDetector(); RBSK = MouseService.GetStandardMouseRules(); }
public override void Update(GameTime gt) { base.Update(gt); if (!HasFocus && Body.BoundingRect.Contains((int)MouseService.Cursor.Position.X, (int)MouseService.Cursor.Position.Y)) { _imageRender.Color = HoverColor; if (MouseService.IsMouseButtonPressed(MouseButton.LeftButton)) { _clickposition = MouseService.Cursor.Position; HasFocus = true; } if (MouseService.IsMouseButtonPressed(MouseButton.RightButton)) { HasFocus = true; _lastImmovable = Collision.Immovable; } } else if (!HasFocus) { //_clickposition = Vector2.Zero; //_releaseposition = Vector2.Zero; _imageRender.Color = Color; } if (HasFocus && MouseService.IsMouseButtonReleased(MouseButton.LeftButton)) { HasFocus = false; _releaseposition = MouseService.Cursor.Position; //Add delta to force. _physics.AddForce((_clickposition - _releaseposition) / 2f); } else if (HasFocus && MouseService.IsMouseButtonDown(MouseButton.RightButton)) { Body.Position -= new Vector2(MouseService.Delta.X, MouseService.Delta.Y); Collision.Immovable = true; } else if (HasFocus && MouseService.IsMouseButtonUp(MouseButton.LeftButton) && MouseService.IsMouseButtonUp(MouseButton.RightButton)) { HasFocus = false; Collision.Immovable = _lastImmovable; } //ResetTimer our position if it goes off screen. if (Body.Right < 0) { Body.X = EntityGame.Viewport.Width; } else if (Body.Left > EntityGame.Viewport.Width) { Body.X = 0 - Body.Width; } if (Body.Bottom < 0) { Body.Y = EntityGame.Viewport.Height; } else if (Body.Top > EntityGame.Viewport.Height) { Body.Y = 0 - Body.Bounds.Y; } _textRender.Text = Name + Environment.NewLine + "X:" + Math.Round(Body.X, 2) + Environment.NewLine + "Y" + Math.Round(Body.Y, 2); _textBody.Position = Body.Position + Vector2.One * 3; }
private Dictionary <int, ISingleFrameResult> GenerateDictionary() { //const int SecondBinaryThresold = 10; const double movementDelta = 15; Services.RBSK.RBSK rbsk = MouseService.GetStandardMouseRules(); if (GapDistance <= 0) { GapDistance = GetBestGapDistance(rbsk); } rbsk.Settings.GapDistance = GapDistance; rbsk.Settings.BinaryThreshold = ThresholdValue; Dictionary <int, ISingleFrameResult> results = new Dictionary <int, ISingleFrameResult>(); Video.Reset(); int counter = 0; int frameCount = Video.FrameCount; while (true) { if (Paused) { continue; } if (Cancelled) { break; } using (Image <Bgr, byte> frame = Video.GetFrameImage()) { if (frame == null) { break; } if (Roi != Rectangle.Empty) { frame.ROI = Roi; } double waist, waistArea, waistArea2, waistArea3, waistArea4; PointF centroid; //if (counter == 500) //{ // frame.ROI = new Rectangle(0,0,1,1); //} PointF[] headPoints = ProcessFrame(frame, rbsk, out waist, out waistArea, out waistArea2, out waistArea3, out waistArea4, out centroid, true); if (Roi != Rectangle.Empty) { centroid.X += Roi.X; centroid.Y += Roi.Y; if (headPoints != null) { headPoints[0].X += Roi.X; headPoints[0].Y += Roi.Y; headPoints[1].X += Roi.X; headPoints[1].Y += Roi.Y; headPoints[2].X += Roi.X; headPoints[2].Y += Roi.Y; headPoints[3].X += Roi.X; headPoints[3].Y += Roi.Y; headPoints[4].X += Roi.X; headPoints[4].Y += Roi.Y; } } //Console.WriteLine(waist + " " + waistArea); //if (headPoints != null) //{ // foreach (var point in headPoints) // { // frame.Draw(new CircleF(point, 2), new Bgr(Color.Yellow), 2); // } //} //ImageViewer.Show(frame); ISingleFrameResult frameResult = ModelResolver.Resolve <ISingleFrameResult>(); frameResult.HeadPoints = headPoints; frameResult.CentroidSize = waist; frameResult.PelvicArea = waistArea; frameResult.PelvicArea2 = waistArea2; frameResult.PelvicArea3 = waistArea3; frameResult.PelvicArea4 = waistArea4; frameResult.Centroid = centroid; results.Add(counter, frameResult); counter++; if (ProgressUpdates != null) { ProgressUpdates(this, new RBSKVideoUpdateEvent((double)counter / frameCount)); } } } if (Cancelled) { return(results); } //Find the most confident run of head detections List <List <HeadPointHolder> > confidentPoints = new List <List <HeadPointHolder> >(); PointF lastPoint = PointF.Empty; List <HeadPointHolder> currentList = new List <HeadPointHolder>(); double currentTotalMovement = 0; for (int i = 0; i < results.Count; i++) { PointF[] headPoints = results[i].HeadPoints; if (headPoints == null) { //No head found, use alternative methods if (currentList.Count > 0) { confidentPoints.Add(currentList); } currentList = new List <HeadPointHolder>(); lastPoint = PointF.Empty; currentTotalMovement = 0; //Console.WriteLine("Head points are null " + i); continue; } //Check against expected position PointF currentPoint = headPoints[2]; if (lastPoint.IsEmpty) { lastPoint = currentPoint; currentList.Add(new HeadPointHolder(i, currentPoint, currentTotalMovement)); continue; } double distance = lastPoint.Distance(currentPoint); if (distance < movementDelta) { //Acceptable currentTotalMovement += distance; currentList.Add(new HeadPointHolder(i, currentPoint, currentTotalMovement)); lastPoint = currentPoint; } else { if (currentList.Count > 0) { confidentPoints.Add(currentList); } currentList = new List <HeadPointHolder>(); lastPoint = PointF.Empty; currentTotalMovement = 0; //Console.WriteLine("Outside of range " + i); } } if (currentList.Count > 0) { confidentPoints.Add(currentList); } if (confidentPoints.Count == 0) { return(results); } //Find longest list with highest total movement List <HeadPointHolder> bestList = confidentPoints[0]; //double currentMaxTraverse = bestList.Last().TotalDelta; foreach (List <HeadPointHolder> list in confidentPoints) { //double currentTotalDelta = list.Last().TotalDelta; if (list.Count > bestList.Count) { //currentMaxTraverse = currentTotalDelta; bestList = list; } } //We now have a confident set of headpoints int minIndex = bestList.Select(x => x.FrameNumber).Min(); int maxIndex = bestList.Select(x => x.FrameNumber).Max(); minIndex--; while (minIndex >= 0) { //Traverse backwards PointF[] lastPoints = results[minIndex + 1].HeadPoints; if (lastPoints != null) { lastPoint = lastPoints[2]; } else { lastPoint = new PointF(-100, -100); } PointF[] headPoints = results[minIndex].HeadPoints; if (headPoints == null) { //No head found, use alternative methods int previousThreshold = rbsk.Settings.BinaryThreshold; rbsk.Settings.BinaryThreshold = ThresholdValue2; Video.SetFrame(minIndex); PointF[] headPoints2 = null; using (Image <Bgr, byte> frame = Video.GetFrameImage()) { if (frame == null) { break; } if (Roi != Rectangle.Empty) { frame.ROI = Roi; } headPoints2 = ProcessFrame(frame, rbsk, lastPoint, movementDelta); } rbsk.Settings.BinaryThreshold = previousThreshold; if (headPoints2 != null) { //We've got a good location //double temp = results[minIndex].CentroidSize; results[minIndex].HeadPoints = headPoints2; //results[minIndex].CentroidSize = temp; //results[minIndex] = new Tuple<PointF[], double>(headPoints2, temp); } else { for (int i = 0; i <= minIndex; i++) { if (results.ContainsKey(i)) { //double temp = results[i].Item2; //results[i] = new Tuple<PointF[], double>(null, temp); results[i].HeadPoints = null; } } break; } minIndex--; continue; } //Check against expected position PointF currentPoint = headPoints[2]; if (lastPoint.Distance(currentPoint) < movementDelta) { //Good point } else { //Wrong point, search for another rbsk that falls within range //if (minIndex == 17 || minIndex == 16) //{ // Console.WriteLine(""); //} Video.SetFrame(minIndex); PointF[] headPoints2 = null; using (Image <Bgr, byte> frame = Video.GetFrameImage()) { if (frame == null) { break; } if (Roi != Rectangle.Empty) { frame.ROI = Roi; } headPoints2 = ProcessFrame(frame, rbsk, lastPoint, movementDelta); } if (headPoints2 != null) { //We've got a good location //double temp = results[maxIndex].Item2; //results[minIndex] = new Tuple<PointF[], double>(headPoints2, temp); results[minIndex].HeadPoints = headPoints2; } else { //No other rbsk falls within range, use alternative methods //Console.WriteLine("Need to use alternative methods"); for (int i = 0; i <= minIndex; i++) { if (results.ContainsKey(i)) { //double temp = results[i].Item2; //results[i] = new Tuple<PointF[], double>(null, temp); results[i].HeadPoints = null; } } break; } } minIndex--; } maxIndex++; while (maxIndex < results.Count) { //Traverse backwards PointF[] lastPoints = results[maxIndex - 1].HeadPoints; if (lastPoints != null) { lastPoint = lastPoints[2]; } else { lastPoint = new PointF(-100, -100); } PointF[] headPoints = results[maxIndex].HeadPoints; if (headPoints == null) { //No head found, use alternative methods int previousThreshold = rbsk.Settings.BinaryThreshold; rbsk.Settings.BinaryThreshold = ThresholdValue2; Video.SetFrame(maxIndex); PointF[] headPoints2 = null; using (Image <Bgr, byte> frame = Video.GetFrameImage()) { if (frame == null) { break; } if (Roi != Rectangle.Empty) { frame.ROI = Roi; } headPoints2 = ProcessFrame(frame, rbsk, lastPoint, movementDelta); } rbsk.Settings.BinaryThreshold = previousThreshold; if (headPoints2 != null) { //We've got a good location //double temp = results[maxIndex].Item2; //results[maxIndex] = new Tuple<PointF[], double>(headPoints2, temp); results[maxIndex].HeadPoints = headPoints2; } else { int max = results.Keys.Max(); for (int i = maxIndex; i <= max; i++) { if (results.ContainsKey(i)) { //double temp = results[i].Item2; //results[i] = new Tuple<PointF[], double>(null, temp); results[i].HeadPoints = null; } } break; } maxIndex++; continue; } //Check against expected position PointF currentPoint = headPoints[2]; if (lastPoint.Distance(currentPoint) < movementDelta) { //Good point } else { //Wrong point, search for another rbsk that falls within range Video.SetFrame(maxIndex); PointF[] headPoints2 = null; using (Image <Bgr, byte> frame = Video.GetFrameImage()) { if (frame == null) { break; } if (Roi != Rectangle.Empty) { frame.ROI = Roi; } headPoints2 = ProcessFrame(frame, rbsk, lastPoint, movementDelta); } if (headPoints2 != null) { //We've got a good location //double temp = results[maxIndex].Item2; //results[maxIndex] = new Tuple<PointF[], double>(headPoints2, temp); results[maxIndex].HeadPoints = headPoints2; } else { //No other rbsk falls within range, use alternative methods //Console.WriteLine("Need to use alternative methods"); int max = results.Keys.Max(); for (int i = maxIndex; i <= max; i++) { if (results.ContainsKey(i)) { //double temp = results[i].Item2; //results[i] = new Tuple<PointF[], double>(null, temp); results[i].HeadPoints = null; } } break; } } maxIndex++; } return(results); }