dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Compare the equality of objects in 2 images c#

  1. #1
    Join Date
    Jul 2014
    Posts
    1

    Compare the equality of objects in 2 images c#

    I'm trying to compare the equality of rectangles in 2 bitmaps. I'm using the AForge library. one is the template and the other is the form. I have tried this but it seems very crude to me because the it has so many iterations which makes the program very slow. It works but the problem is that the program hangs because of too many iterations. Please is there something I'm missing? I'm I on the right track or something? Please help and pardon my crude codes below.

    Bitmap bitmap = new Bitmap(pictureBox1.Image);
    Bitmap bitmap2 = new Bitmap(pictureBox2.Image);


    // create an instance of blob counter algorithm
    BlobCounter blobCounter = new BlobCounter();
    blobCounter.MinWidth = 5;
    blobCounter.MinHeight = 5;
    blobCounter.FilterBlobs = true;
    blobCounter.ObjectsOrder = ObjectsOrder.Size;
    blobCounter.ProcessImage(bitmap);
    BlobCounter blobCounter2 = new BlobCounter();
    blobCounter2.MinWidth = 5;
    blobCounter2.MinHeight = 5;
    blobCounter2.FilterBlobs = true;
    blobCounter2.ObjectsOrder = ObjectsOrder.Size;
    blobCounter2.ProcessImage(bitmap2);


    Rectangle[] rects = blobCounter.GetObjectsRectangles();

    Rectangle[] rects2 = blobCounter2.GetObjectsRectangles();

    foreach (Rectangle recs in rects)
    foreach (Rectangle recs2 in rects2)

    if (rects.Length > 0 )
    {
    if (rects2.Length > 0)
    {
    for (int x = 0; x < recs.Width & x < recs.Height; x++)
    {
    // for (int x2 = 0; x2 < recs2.Width; x2++)
    for (int y = 0; y < recs2.Width & y < recs2.Height; y++)
    {
    // for (int y2 = 0; y2 < recs2.Height; y2++)

    if (recs.Equals(recs2))
    {
    this.Refresh();
    //listBox1.Items.Add("TRUE");
    Console.WriteLine("TRUE");



    }
    else
    {
    //listBox1.Items.Add("FALSE");
    Console.WriteLine("FALSE");
    }
    .....

  2. #2
    Join Date
    Apr 2014
    Location
    in northeast ohio
    Posts
    94

    Re: Compare the equality of objects in 2 images c#

    not sure what is meant by
    the equality of two objects in two images
    when your comparing sets of rectangles in two images
    when the fields are called blob this and that implying irregular shapes

    maybe you can clarify more specifically what conditions must be
    checked and what the limits are in order to evaluate success or failure

    are you simply checking that two images are the same size or
    that two array's have matching rectangles that are found from blobCounter.GetObjectsRectangles();
    the question is a little confusing
    it appears your instead trying to build a list of matching rectangles
    that are given by that function from analyzing the images

    either way i noticed that you might have a typo in that code
    in both for loops you have & instead of && these two are not the same
    the first & is a bitmath or-ing operator
    were && is a boolean conditional operator
    for (int x = 0; x < recs.Width & x < recs.Height; x++)
    i don't think you intend to be using &

    i didn't test this , maybe something like so is what your after
    this is not particularly fast its n^2 i think but it should work
    Code:
    for(i = 0; i < recs.Length;i++){
     for(j = 0; j < recs2.Length;j++){
       Rectangle a = recs[i];
       Rectangle b = recs2[j];
       if(a.X == b.X && a.Y == b.Y && a.Width == b.Width && a.Height == b.Height)
       {
        Console.WriteLine("TRUE  recs index "+ i +" ,recs2 index " + j);
       }
     }
    }
    if you really need something faster then you will need to look into using
    a spacial partitioning algorithm a quad tree or simpler grid bucket
    Last edited by willmotil; September 12th, 2014 at 04:41 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)