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");
}
.....