コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: SettingsViewModel.cs プロジェクト: BrettHewitt/ARWT
        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);
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: RBSKVideo.cs プロジェクト: BrettHewitt/ART
        private PointF[] ProcessFrame(Image <Bgr, Byte> image, AutomatedRodentTracker.Services.RBSK.RBSK rbsk, out double waist, out double waistArea, out double waistArea2, out double waistArea3, out double waistArea4, out PointF centroid, bool useBackground = false)
        {
            //Rectangle roi = Rectangle.Empty;

            //if (image.IsROISet)
            //{
            //    roi = image.ROI;
            //    image.ROI = Rectangle.Empty;
            //}

            if (BackgroundImage != null && useBackground)
            {
                using (Image <Gray, Byte> grayImage = image.Convert <Gray, Byte>())
                    //using (Image<Gray, Byte> filteredImage = grayImage.SmoothMedian(rbsk.Settings.FilterLevel))
                    using (Image <Gray, Byte> binaryImage = grayImage.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> filteredImage = finalImage.SmoothMedian(rbsk.Settings.FilterLevel))
                                {
                                    //ImageViewer.Show(finalImage);
                                    PointF[] result = RBSKService.RBSK(filteredImage, rbsk);

                                    IBodyDetection bodyDetection = ModelResolver.Resolve <IBodyDetection>();
                                    bodyDetection.BinaryBackground = BackgroundImage;
                                    //bodyDetection.ThresholdValue = ThresholdValue;

                                    if (result == null)
                                    {
                                        waist      = -1;
                                        waistArea  = -1;
                                        waistArea2 = -1;
                                        waistArea3 = -1;
                                        waistArea4 = -1;
                                        bodyDetection.GetBody(grayImage, out centroid);
                                        return(null);
                                    }

                                    bodyDetection.FindBody(grayImage, out waist, out waistArea, out waistArea2, out waistArea3, out waistArea4, out centroid);

                                    return(result);
                                }
            }

            waist      = -1;
            waistArea  = -1;
            waistArea2 = -1;
            waistArea3 = -1;
            waistArea4 = -1;
            centroid   = PointF.Empty;
            return(RBSKService.RBSK(image, rbsk));
        }
コード例 #5
0
        private PointF[] ProcessFrame(Image <Bgr, Byte> image, RBSK rbsk, bool useBackground = false)
        {
            if (BinaryBackground != null && useBackground)
            {
                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 = BinaryBackground.Not())
                                using (Image <Gray, Byte> finalImage = binaryImage.Add(backgroundNot))
                                {
                                    PointF[] result = RBSKService.RBSK(finalImage, rbsk);
                                    return(result);
                                }
            }


            return(RBSKService.RBSK(image, rbsk));
        }
コード例 #6
0
ファイル: RBSKVideo.cs プロジェクト: BrettHewitt/ART
        private PointF[] ProcessFrame(Image <Bgr, Byte> image, AutomatedRodentTracker.Services.RBSK.RBSK rbsk, PointF previousPoint, double movementDelta, bool useBackground = false)
        {
            if (BackgroundImage != null && useBackground)
            {
                using (Image <Gray, Byte> grayImage = image.Convert <Gray, Byte>())
                    using (Image <Gray, Byte> binaryImage = grayImage.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> filteredImage = finalImage.SmoothMedian(rbsk.Settings.FilterLevel))
                                {
                                    PointF[] result = RBSKService.RBSK(filteredImage, rbsk, previousPoint, movementDelta);
                                    return(result);
                                }
            }


            return(RBSKService.RBSK(image, rbsk, previousPoint, movementDelta));
        }
コード例 #7
0
        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);
                                        }
                                    }
        }
コード例 #8
0
ファイル: RBSKVideo2Image.cs プロジェクト: BrettHewitt/ARWT
        private PointF[] ProcessFrame(Image <Gray, Byte> grayImage, RBSK rbsk, out double waist, out double waistArea, out double waistArea2, out double waistArea3, out double waistArea4, out PointF centroid, out Point[] bodyContour, bool useBackground = false)
        {
            //Rectangle roi = Rectangle.Empty;

            //if (image.IsROISet)
            //{
            //    roi = image.ROI;
            //    image.ROI = Rectangle.Empty;
            //}

            if (BackgroundImage != null && useBackground)
            {
                //using (Image<Gray, Byte> grayImage = image.Convert<Gray, Byte>())
                using (Image <Gray, Byte> binaryImage = grayImage.ThresholdBinary(new Gray(rbsk.Settings.BinaryThreshold), new Gray(255)))
                    using (Image <Gray, Byte> backgroundNot = BackgroundImage.Not())
                        using (Image <Gray, Byte> binaryFinal = binaryImage.Add(backgroundNot))
                            using (Image <Gray, Byte> finalImage = binaryFinal.SmoothMedian(rbsk.Settings.FilterLevel))
                            //using (Image<Gray, Byte> finalImageNot = finalImage.Not())
                            {
                                //ImageViewer.Show(finalImage);
                                ImageViewer.Show(finalImage);
                                PointF[] result = RBSKService.RBSK(finalImage, rbsk);

                                IBodyDetection bodyDetection = ModelResolver.Resolve <IBodyDetection>();
                                bodyDetection.BinaryBackground = BackgroundImage;
                                //bodyDetection.ThresholdValue = ThresholdValue;

                                if (result == null)
                                {
                                    waist      = -1;
                                    waistArea  = -1;
                                    waistArea2 = -1;
                                    waistArea3 = -1;
                                    waistArea4 = -1;
                                    //bodyDetection.GetBody(finalImage, out centroid, out bodyContour);
                                    bodyContour = null;
                                    centroid    = PointF.Empty;
                                    return(null);
                                }


                                //double vol2, vol3, vol4;
                                //image.

                                //if (!roi.IsEmpty)
                                //{
                                //    image.ROI = roi;
                                //}

                                //PointF dummy;
                                //ImageViewer.Show(finalImage);
                                bodyDetection.FindBody(finalImage, out waist, out waistArea, out waistArea2, out waistArea3, out waistArea4, out centroid, out bodyContour);

                                //if (!centroid.IsEmpty)
                                //{
                                //    ImageViewer.Show(finalImage);
                                //    Console.WriteLine("Showing");
                                //}

                                //CvBlobs blobs = new CvBlobs();
                                //BlobDetector.Detect(finalImage, blobs);

                                //CvBlob mouseBlob = null;
                                //double maxArea = -1;
                                //foreach (var blob in blobs.Values)
                                //{
                                //    if (blob.Area > maxArea)
                                //    {
                                //        mouseBlob = blob;
                                //        maxArea = blob.Area;
                                //    }
                                //}
                                //waist = -1;
                                //waistArea = -1;
                                return(result);
                            }
            }

            waist       = -1;
            waistArea   = -1;
            waistArea2  = -1;
            waistArea3  = -1;
            waistArea4  = -1;
            centroid    = PointF.Empty;
            bodyContour = null;
            return(null);
        }