Exemple #1
0
        public void Dispose()
        {
            image?.Dispose();
            image = null;

            descriptors?.Dispose();
            descriptors = null;

            keyPoints?.Dispose();
            keyPoints = null;
        }
Exemple #2
0
 protected override void DisposeObject()
 {
     if (_modelKeypoints != null)
     {
         _modelKeypoints.Dispose();
         _modelKeypoints = null;
     }
     if (_modelDescriptors != null)
     {
         _modelDescriptors.Dispose();
         _modelDescriptors = null;
     }
     if (_modelDescriptorMatcher != null)
     {
         _modelDescriptorMatcher.Dispose();
         _modelDescriptorMatcher = null;
     }
     if (_octagon != null)
     {
         _octagon.Dispose();
         _octagon = null;
     }
 }
        public void DrawSIFTDescriptor(string inputFile, string outputFile)
        {
            //SiFT Descriptor
            SIFT             siftAlgo           = null;
            VectorOfKeyPoint modelKeyPointsSift = null;

            try
            {
                siftAlgo           = new SIFT();
                modelKeyPointsSift = new VectorOfKeyPoint();

                using (Image <Bgr, byte> inputImage = new Image <Bgr, byte>(inputFile))
                {
                    MKeyPoint[] siftPoints = siftAlgo.Detect(inputImage);
                    modelKeyPointsSift.Push(siftPoints);
                    UMat siftDescriptors = new UMat();
                    siftAlgo.DetectAndCompute(inputImage, null, modelKeyPointsSift, siftDescriptors, true);
                    using (Image <Gray, Byte> outputImage = new Image <Gray, byte>(
                               inputImage.Width,
                               inputImage.Height))
                    {
                        Features2DToolbox.DrawKeypoints(
                            inputImage,
                            modelKeyPointsSift,
                            outputImage,
                            new Bgr(255, 255, 255),
                            Features2DToolbox.KeypointDrawType.Default);
                        outputImage.Save(outputFile);
                    }
                }
            }
            finally
            {
                siftAlgo.Dispose();
                modelKeyPointsSift.Dispose();
            }
        }
Exemple #4
0
 public void Dispose()
 {
     KeyPoints.Dispose();
     Descriptors.Dispose();
 }
Exemple #5
0
        private void DetectPeople(int w, int h, byte[] img)
        {
            Mat workingMatrix = new Mat(h, w, DepthType.Cv8U, 1);

            if (blobTrackerMaskMat != null)
            {
                for (int i = 0; i < img.Length; i++)
                {
                    if (maskPixel[i] == 0)
                    {
                        img[i] = 0;
                    }
                }
            }


            workingMatrix.SetTo(img);
            var workingImage = workingMatrix.ToImage <Gray, byte>().PyrDown().PyrUp();

            workingImage = workingImage.SmoothBlur(10, 10, true);

            Image <Gray, byte> cannyEdges = workingImage.Canny(130, 150);

            CannyMat.Source = ToBitmapSource(workingImage);
            Mat filled = Mat.Zeros(h, w, DepthType.Cv8U, 3);

            VectorOfKeyPoint kp = new VectorOfKeyPoint();

            if (blobTrackerMaskMat != null)
            {
                blobDetector.DetectRaw(workingImage, kp, blobTrackerMaskMat);
            }
            else
            {
                blobDetector.DetectRaw(workingImage, kp);
            }
            Tracked.Text = kp.Size.ToString();
            Features2DToolbox.DrawKeypoints(workingImage.Mat, kp, filled, new Bgr(0, 0, 255));//,Features2DToolbox.KeypointDrawType.DrawRichKeypoints);
            if (kp.Size > 0)
            {
                //   dataWriter.WriteLine($"{kp[0].Point.X},{kp[0].Point.Y}");

                oscSender?.Send(new OscMessage("/DTDT", kp[0].Point.X, kp[0].Point.Y));
            }

            kp.Dispose();

            using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())
            {
                CvInvoke.FindContours(cannyEdges, contours, null, RetrType.External,
                                      ChainApproxMethod.ChainApproxSimple);

                Image <Bgr, byte> filled2 = filled.ToImage <Bgr, byte>();
                for (int i = 0; i < contours.Size; i++)
                {
                    using (VectorOfPoint contour = contours[i])
                        using (VectorOfPoint approxContour = new VectorOfPoint())
                        {
                            CvInvoke.ApproxPolyDP(contour, approxContour, CvInvoke.ArcLength(contour, true) * 0.01, true);
                            //CvInvoke.DrawContours(filled,contours,i,new MCvScalar(0,0,255),2, LineType.Filled);
                            //  filled2.DrawPolyline(approxContour.ToArray(),true,new Bgr(0,0,255),2);
                        }
                }
            }

            TrackMat.Source = ToBitmapSource(filled);
        }