Exemple #1
0
        internal Matrix <float> getFeaturesAsMatrix()
        {
            Dictionary <string, string> featuresDict = this.getFeaturesAsDict();

            float[] featuresVector = featuresDict.Where(f => f.Key != "id" && f.Key != "class").Select(f => Convert.ToSingle(f.Value)).ToArray();
            //Console.WriteLine(String.Join(",", featuresVector));
            Matrix <float> row = FeaturesUtilities.vector2matrix(featuresVector);

            return(row);
        }
Exemple #2
0
        internal Task computeFeatures()
        {
            return(Task.Run(delegate() {
                using (Image <Bgr, Byte> src = this.blob.Image.ToManagedImage().ToImage <Bgr, Byte>()){
                    VectorOfPoint contour = FeaturesUtilities.getMaxContour(src);
                    if (contour != null && contour.Size > 5)
                    {
                        CircleF circle = CvInvoke.MinEnclosingCircle(contour);
                        RotatedRect ellipse = CvInvoke.FitEllipse(contour);
                        // extract shape features
                        Rectangle bounds = CvInvoke.BoundingRectangle(contour);
                        this.area = CvInvoke.ContourArea(contour, false);
                        this.perimeter = CvInvoke.ArcLength(contour, true);
                        this.shape = (4 * Math.PI * area) / Math.Pow(perimeter, 2);
                        this.npoints = contour.Size;
                        this.width = bounds.Width;
                        this.height = bounds.Height;
                        this.centroideY = circle.Center.Y;
                        this.centroideX = circle.Center.X;
                        this.radius = circle.Radius;
                        this.aspectRatio = width / height;
                        this.extent = area / (width * height);

                        //extract texture features
                        using (Image <Gray, Byte> gray = src.Convert <Gray, Byte>()){
                            var glcm = new GrayLevelCooccurrenceMatrix(distance: 1, degree: CooccurrenceDegree.Degree0, normalize: true);
                            // Extract the matrix from the image
                            double[,] matrix = glcm.Compute(gray.ToBitmap());
                            HaralickDescriptor haralick = new HaralickDescriptor(matrix);
                            double[] haralickFeatures = haralick.GetVector();
                            this.homogeneity = haralick.AngularSecondMomentum;
                            this.contrast = haralick.Contrast;
                            this.haralickFeatures = haralickFeatures;
                        }

                        using (Image <Hsv, Byte> hsv = src.Convert <Hsv, Byte>()) {
                            this.hsvColor = new MCvScalar()
                            {
                                V0 = hsv.Data[(int)circle.Center.Y, (int)circle.Center.X, 0],
                                V1 = hsv.Data[(int)circle.Center.Y, (int)circle.Center.X, 1],
                                V2 = hsv.Data[(int)circle.Center.Y, (int)circle.Center.X, 2]
                            };
                        }

                        this.bgrColor = new MCvScalar()
                        {
                            V0 = src.Data[(int)circle.Center.Y, (int)circle.Center.X, 0],
                            V1 = src.Data[(int)circle.Center.Y, (int)circle.Center.X, 1],
                            V2 = src.Data[(int)circle.Center.Y, (int)circle.Center.X, 2]
                        };
                    }
                }
            }));
        }