Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

C# AForge

Hi guys, i need your help

I tried finding images on screen using this code snippet:
PHP Code

<?php 
System
.Drawing.Bitmap sourceImage = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\1.jpg");
            
System.Drawing.Bitmap template = (Bitmap)Bitmap.FromFile(@"C:\SavedBMPs\2.jpg");
            
// create template matching algorithm's instance
            // (set similarity threshold to 92.1%)

           
ExhaustiveTemplateMatching tm = new ExhaustiveTemplateMatching(0.921f);
                
// find all matchings with specified above similarity

                
TemplateMatch[] matchings = tm.ProcessImage(sourceImage, template);
                
// highlight found matchings

           
BitmapData data = sourceImage.LockBits(
                new 
Rectangle(0, 0, sourceImage.Width, sourceImage.Height),
                
ImageLockMode.ReadWrite, sourceImage.PixelFormat);
            foreach (
TemplateMatch m in matchings)
            {

                    
Drawing.Rectangle(data, m.Rectangle, Color.White);

                
MessageBox.Show(m.Rectangle.Location.ToString());
                
// do something else with matching
            
}
            
sourceImage.UnlockBits(data); 


and my code is:(which give me an error):
PHP Code

<?php 
foreach(AForge.Imaging.TemplateMatch m in matchings)
            {
               
Rectangle(data,m.Rectangle,Color.White);/*Drawing.Rectangle(data, m.Rectangle, Color.White);*/
            
}
            return 
true; 

PHP Code

<?php 
Error    2    
'System.Drawing.Rectangle' is a 'type' but is used like a 'variable'    C:\Users\גיא\documents\visual studio 2013\Projects\FIFACsharp_Imagebot\FIFACsharp_Imagebot\Form1.cs    55    16    FIFACsharp_Imagebot 

what am i doing wrong? Please bare in mind I am new to C# and spent hours googling
גיא 🙂 i didnt use AForge but from ur error seems that TemplateMatch is variable and not type (Rectangle)
(Dec 13, 2014 04:23 PM)Only3 Wrote:  גיא 🙂 i didnt use AForge but from ur error seems that TemplateMatch is variable and not type (Rectangle)

Thank you for your reply , but the code in stack overflow was reported to be working , and the error is referring to the rectangle . תודה
Hey mate,

try this:

Code
foreach(AForge.Imaging.TemplateMatch m in matchings)
      {
             AForge.Imaging.Drawing.Rectangle(data,m.Rectangle,Color.White);/*Drawing.Rectangle(data, m.Rectangle, Color.White);*/
      }
      return true;

It should work now :)

Greetings!
use AForge.Imaging.Drawing.Rectangle(data, m.Rectangle, Color.White);
and not System.Drawing.Rectangle(data, m.Rectangle, Color.White);
Edit - the site lag 😊 as above ... aforge have rectangle method too
(Dec 14, 2014 05:08 AM)FSayan93 Wrote:  Hey mate,

try this:

Code
foreach(AForge.Imaging.TemplateMatch m in matchings)
      {
      AForge.Imaging.Drawing.Rectangle(data,m.Rectangle,Color.White);/*Drawing.Rectangle(data, m.Rectangle, Color.White);*/
      }
      return true;

It should work now :)

Greetings!

Thank you both this worked for me!
I didn't know that AForge has that too


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Key PunchNov 1, 2014 04:38 PM 1 94 Nov 1, 2014 04:38 PM
Last Post: idb.
[.NET] by imi-tat0rOct 21, 2014 05:21 AM 3 196 Oct 21, 2014 05:21 AM
Last Post: Nikey646
[C#] by NovJul 21, 2014 07:37 AM 2 192 Jul 21, 2014 07:37 AM
Last Post: Nov