Problems on CreateBitmap with additional code
Posted: 06 November 2012 07:25 AM   [ Ignore ]
New Member
Rank
Total Posts:  2
Joined  2012-10-31

Hi, im new here and i was wondering if anyone could help me with some code. I want to do blobtraking, so i found some Aforge source codes that work just fine i bitmaps, but can not manage to make it right on my project.
http://www.aforgenet.com/articles/shape_checker/

So i start from the example CLEyeWinFormTest code of codelaboratories, and i am tyring to add _form.ProccesImage(bmpGraph); on the CreateBitmap(w,h) method but picturebox1 go to black even though i created another picturebox to process the other image…

I think the program might get stucked on a line, but i don’t manage to see it.

here’s the new code:

public void ProcessImage(Bitmap bitmap)
      {
        BitmapData bitmapData = bitmap.LockBits(
          new Rectangle(0, 0, bitmap.Width, bitmap.Height),
          ImageLockMode.ReadWrite, bitmap.PixelFormat);

        // step 1 - turn background to black
        ColorFiltering colorFilter = new ColorFiltering();
        colorFilter.Red = new IntRange(0, 64);
        colorFilter.Green = new IntRange(0, 64);
        colorFilter.Blue = new IntRange(0, 64);
        colorFilter.FillOutsideRange = false;

        //colorFilter.ApplyInPlace(bitmapData);

        BlobCounter blobCounter = new BlobCounter();
        blobCounter.FilterBlobs = true;
        blobCounter.MinHeight = 5;
        blobCounter.MinWidth = 5;

        blobCounter.ProcessImage(bitmapData);
        Blob[] blobs = blobCounter.GetObjectsInformation();
        bitmap.UnlockBits(bitmapData);
        // locate objects using blob counter
       
        // create Graphics object to draw on the image and a pen
        Graphics g = Graphics.FromImage(bitmap);
        Pen redPen = new Pen(Color.Red, 2);
        SimpleShapeChecker shapeChecker = new SimpleShapeChecker();

        // check each object and draw circle around objects, which
        // are recognized as circles
        for (int i = 0, n = blobs.Length; i < n; i++)
{
List edgePoints = blobCounter.GetBlobsEdgePoints(blobs);

          DoublePoint center;
          double radius;

          if (shapeChecker.IsCircle(edgePoints, out center, out radius))
          {
              g.DrawEllipse(redPen,
                (int)(center.X - radius),
                (int)(center.Y - radius),
                (int)(radius * 2),
                (int)(radius * 2));
          }
        }
        redPen.Dispose();
        g.Dispose();
        pictureBox2.Image = bitmap;
      }

Profile
 
 
Posted: 12 November 2012 05:08 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

diheinso,

Could you upload your full project so that I can test it and try to figure out where the problem is?

Thanks
Alex

diheinso - 06 November 2012 07:25 AM
Hi, im new here and i was wondering if anyone could help me with some code. I want to do blobtraking, so i found some Aforge source codes that work just fine i bitmaps, but can not manage to make it right on my project. http://www.aforgenet.com/articles/shape_checker/ So i start from the example CLEyeWinFormTest code of codelaboratories, and i am tyring to add _form.ProccesImage(bmpGraph); on the CreateBitmap(w,h) method but picturebox1 go to black even though i created another picturebox to process the other image… I think the program might get stucked on a line, but i don’t manage to see it. here’s the new code: public void ProcessImage(Bitmap bitmap)       {         BitmapData bitmapData = bitmap.LockBits(           new Rectangle(0, 0, bitmap.Width, bitmap.Height),           ImageLockMode.ReadWrite, bitmap.PixelFormat);         // step 1 - turn background to black         ColorFiltering colorFilter = new ColorFiltering();         colorFilter.Red = new IntRange(0, 64);         colorFilter.Green = new IntRange(0, 64);         colorFilter.Blue = new IntRange(0, 64);         colorFilter.FillOutsideRange = false;         //colorFilter.ApplyInPlace(bitmapData);         BlobCounter blobCounter = new BlobCounter();         blobCounter.FilterBlobs = true;         blobCounter.MinHeight = 5;         blobCounter.MinWidth = 5;         blobCounter.ProcessImage(bitmapData);         Blob[] blobs = blobCounter.GetObjectsInformation();         bitmap.UnlockBits(bitmapData);         // locate objects using blob counter                 // create Graphics object to draw on the image and a pen         Graphics g = Graphics.FromImage(bitmap);         Pen redPen = new Pen(Color.Red, 2);         SimpleShapeChecker shapeChecker = new SimpleShapeChecker();         // check each object and draw circle around objects, which         // are recognized as circles         for (int i = 0, n = blobs.Length; i < n; i++) { List edgePoints = blobCounter.GetBlobsEdgePoints(blobs);           DoublePoint center;           double radius;           if (shapeChecker.IsCircle(edgePoints, out center, out radius))           {               g.DrawEllipse(redPen,                 (int)(center.X - radius),                 (int)(center.Y - radius),                 (int)(radius * 2),                 (int)(radius * 2));           }         }         redPen.Dispose();         g.Dispose();         pictureBox2.Image = bitmap;       }
Profile
 
 
 
 


RSS 2.0     Atom Feed