Exemple #1
0
            void Method()
            {
                MyBlob blob = _blobAssetReference.Value;

                EnsureNotOptimizedAway(blob.myfloats.Length);
            }
            // Get array of objects rectangles
            public List <MyBlob> GetBlobs(Bitmap srcImg)
            {
                Process(srcImg);
                ushort[] labels = this.objectLabels;
                int      count  = this.objectsCount;

                this.objectSize = new int[count + 1];
                double[] center_x = new double[count + 1];
                double[] center_y = new double[count + 1];
                // LBF off for now
                //LineOfBestFit[] lbf = new LineOfBestFit[count + 1];
                // image size
                int width = srcImg.Width;
                int height = srcImg.Height;
                int i = 0, label;

                // create object coordinates arrays
                int[] x1       = new int[count + 1];
                int[] y1       = new int[count + 1];
                int[] x2       = new int[count + 1];
                int[] y2       = new int[count + 1];
                int[] sample_x = new int[count + 1];
                int[] sample_y = new int[count + 1];
                for (int j = 1; j <= count; j++)
                {
                    x1[j] = width;
                    y1[j] = height;
                }
                // walk through labels array, skip one row and one col
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++, i++)
                    {
                        // get current label
                        label = labels[i];
                        // skip unlabeled pixels
                        if (label == 0)
                        {
                            continue;
                        }
                        // LBF off for now
                        //if (lbf[label] == null)
                        //    lbf[label] = new LineOfBestFit();
                        //lbf[label].Update(x, height - y);
                        this.objectSize[label]++;
                        // check and update all coordinates
                        center_x[label] += x;
                        center_y[label] += y;
                        sample_x[label]  = x; // record the last point as a sample
                        sample_y[label]  = y;
                        if (x < x1[label])
                        {
                            x1[label] = x;
                        }
                        if (x > x2[label])
                        {
                            x2[label] = x;
                        }
                        if (y < y1[label])
                        {
                            y1[label] = y;
                        }
                        if (y > y2[label])
                        {
                            y2[label] = y;
                        }
                    }
                }
                List <MyBlob> blobs = new List <MyBlob>();

                for (int j = 1; j <= count; j++)
                {
                    MyBlob b = new MyBlob();
                    b.bbx         = new Rectangle(x1[j], y1[j], x2[j] - x1[j] + 1, y2[j] - y1[j] + 1);
                    b.pixel_count = this.objectSize[j];
                    b.mass_center = new Point(Convert.ToInt32(center_x[j] / (double)b.pixel_count), Convert.ToInt32(center_y[j] / (double)b.pixel_count));
                    b.area        = (x2[j] - x1[j] + 1) * (y2[j] - y1[j] + 1);
                    b.pixel_id    = j;
                    b.sample_x    = sample_x[j];
                    b.sample_y    = sample_y[j];
                    // LBF off for now
                    if (b.bbx.Width == 1)
                    {
                        b.orientation = 90;
                        b.m           = Double.NaN;
                        b.b           = x1[j]; // x = 4
                    }
                    else if (b.bbx.Height == 1)
                    {
                        b.orientation = 180;
                        b.m           = 0;
                        b.b           = y1[j]; // y = 4
                    }
                    else
                    {
                        //   b.orientation = lbf[j].GetOrientation();
                        //  b.m = lbf[j].m;
                        // b.b = lbf[j].b;
                    }
                    blobs.Add(b);
                }
                return(blobs);
            }
 void Method()
 {
     MyBlob blob = _blobAssetReference.Value;
 }
 // Get array of objects rectangles
 public List<MyBlob> GetBlobs(Bitmap srcImg)
 {
     Process(srcImg);
     ushort[] labels = this.objectLabels;
     int count = this.objectsCount;
     this.objectSize = new int[count + 1];
     double[] center_x = new double[count + 1];
     double[] center_y = new double[count + 1];
     // LBF off for now
     LineOfBestFit[] lbf = new LineOfBestFit[count + 1];
     // image size
     int width = srcImg.Width;
     int height = srcImg.Height;
     int i = 0, label;
     // create object coordinates arrays
     int[] x1 = new int[count + 1];
     int[] y1 = new int[count + 1];
     int[] x2 = new int[count + 1];
     int[] y2 = new int[count + 1];
     int[] sample_x = new int[count + 1];
     int[] sample_y = new int[count + 1];
     for (int j = 1; j <= count; j++)
     {
         x1[j] = width;
         y1[j] = height;
     }
     // walk through labels array, skip one row and one col
     for (int y = 0; y < height; y++)
     {
         for (int x = 0; x < width; x++, i++)
         {
             // get current label
             label = labels[i];
             // skip unlabeled pixels
             if (label == 0)
                 continue;
             // LBF off for now
             if (lbf[label] == null)
                 lbf[label] = new LineOfBestFit();
             lbf[label].Update(x, height - y);
             this.objectSize[label]++;
             // check and update all coordinates
             center_x[label] += x;
             center_y[label] += y;
             sample_x[label] = x; // record the last point as a sample
             sample_y[label] = y;
             if (x < x1[label])
             {
                 x1[label] = x;
             }
             if (x > x2[label])
             {
                 x2[label] = x;
             }
             if (y < y1[label])
             {
                 y1[label] = y;
             }
             if (y > y2[label])
             {
                 y2[label] = y;
             }
         }
     }
     List<MyBlob> blobs = new List<MyBlob>();
     for (int j = 1; j <= count; j++)
     {
         MyBlob b = new MyBlob();
         b.bbx = new Rectangle(x1[j], y1[j], x2[j] - x1[j] + 1, y2[j] - y1[j] + 1);
         b.pixel_count = this.objectSize[j];
         b.mass_center = new Point(Convert.ToInt32(center_x[j] / (double)b.pixel_count), Convert.ToInt32(center_y[j] / (double)b.pixel_count));
         b.area = (x2[j] - x1[j] + 1) * (y2[j] - y1[j] + 1);
         b.pixel_id = j;
         b.sample_x = sample_x[j];
         b.sample_y = sample_y[j];
         // LBF off for now
         if (b.bbx.Width == 1)
         {
             b.orientation = 90;
             b.m = Double.NaN;
             b.b = x1[j]; // x = 4
         }
         else if (b.bbx.Height == 1)
         {
             b.orientation = 180;
             b.m = 0;
             b.b = y1[j]; // y = 4
         }
         else
         {
             b.orientation = lbf[j].GetOrientation();
             b.m = lbf[j].m;
             b.b = lbf[j].b;
         }
         blobs.Add(b);
     }
     return blobs;
 }