AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Replace glyph with real image

Forum to discuss Glyph Recognition And Tracking Framework project, its features, applications, etc.

Replace glyph with real image

Postby mitko29 » Wed Jan 04, 2012 9:12 pm

Hello all I successfully created glyph recognize application and I am trying to replace the glyph image and create 2D Augmented Reality but with no success.
So my question is how can I do this in my application.

I share my code for video processing:
Code: Select all
     void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
            Bitmap image = (Bitmap)eventArgs.Frame.Clone();
            Bitmap copyimage = (Bitmap)eventArgs.Frame.Clone();
            image = filter.Apply(image);
            BitmapData imageData = image.LockBits(
                new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadWrite, image.PixelFormat);
            UnmanagedImage grayImage = new UnmanagedImage(imageData);
            DifferenceEdgeDetector edgeDetector = new DifferenceEdgeDetector();
            UnmanagedImage edgesImage = edgeDetector.Apply(grayImage);
            Threshold thresholdFilter = new Threshold(40);
            thresholdFilter.ApplyInPlace(edgesImage);
            BlobCounter blobCounter = new BlobCounter();
            blobCounter.MinHeight = 48;
            blobCounter.MinWidth = 48;
            blobCounter.FilterBlobs = true;
            blobCounter.ObjectsOrder = ObjectsOrder.Size;
            blobCounter.ProcessImage(edgesImage);           
            Blob[] blobs = blobCounter.GetObjectsInformation();         
            for (int i = 0, n = blobs.Length; i < n; i++)
            {
                List<IntPoint> edgePoints = blobCounter.GetBlobsEdgePoints(blobs[i]);
                List<IntPoint> corners = new List<IntPoint>();
                corners.Add(new IntPoint(99, 99));
                corners.Add(new IntPoint(156, 79));
                corners.Add(new IntPoint(184, 126));
                corners.Add(new IntPoint(122, 150));
                if (shapeChecker.IsQuadrilateral(edgePoints, out corners))
                {
                    List<IntPoint> leftEdgePoints, rightEdgePoints;
                    blobCounter.GetBlobsLeftAndRightEdges(blobs[i],
                        out leftEdgePoints, out rightEdgePoints);
                    float diff = CalculateAverageEdgesBrightnessDifference(
                        leftEdgePoints, rightEdgePoints, grayImage);
                    if (diff > 20)
                    {
                        Quadrilateral = corners;
                        Bitmap sourceImage = new Bitmap(@"C:\Users\XaKeRA\Desktop\icon.png");
                        BackwardQuadrilateralTransformation backfilter =
    new BackwardQuadrilateralTransformation(sourceImage, Quadrilateral);                       
                        QuadrilateralTransformation quadrilateralTransformation =
                        new QuadrilateralTransformation(Quadrilateral, 100, 100);
                        glyphImage = quadrilateralTransformation.Apply(grayImage);
                        newImage = backfilter.Apply(copyimage);
                        OtsuThreshold otsuThresholdFilter = new OtsuThreshold();
                        otsuThresholdFilter.ApplyInPlace(glyphImage);
                        byte[,] glyphValues = Recognize(glyphImage,
    new Rectangle(0, 0, glyphImage.Width, glyphImage.Height), out confidence);
                        if (confidence >= minConfidenceLevel)
                        {
                            resMatching = CheckForMatching(Glyph_01, glyphValues);
                            if (resMatching != -1)
                            {
                                rotation = CheckForMatching(Glyph_01, glyphValues);
                                glif = "Glyph_01";
                            }
                            resMatching = CheckForMatching(Glyph_02, glyphValues);
                            if (resMatching != -1)
                            {
                                rotation = CheckForMatching(Glyph_02, glyphValues);
                                glif = "Glyph_02";
                            }
                            resMatching = CheckForMatching(Glyph_03, glyphValues);
                            if (resMatching != -1)
                            {
                                rotation = CheckForMatching(Glyph_03, glyphValues);
                                glif = "Glyph_03";
                            }
                            resMatching = CheckForMatching(Glyph_04, glyphValues);
                            if (resMatching != -1)
                            {
                                rotation = CheckForMatching(Glyph_04, glyphValues);
                                glif = "Glyph_04";
                            }
                            ImgRes.Image = glyphImage.ToManagedImage();
                            updateLabelText(glif);
                        }
                    }
                }
            }
            pictureBox1.Image = grayImage.ToManagedImage();
        }
mitko29
 
Posts: 15
Joined: Wed Jan 04, 2012 9:06 pm

Re: Replace glyph with real image

Postby andrew.kirillov » Thu Jan 05, 2012 9:24 am

Hello,

Some code samples are here. Some more code is here. And of course Glyph Recognition Studio is a good sample as well.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3243
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Replace glyph with real image

Postby mitko29 » Sun Jan 15, 2012 1:38 pm

andrew.kirillov wrote:Hello,

Some code samples are here. Some more code is here. And of course Glyph Recognition Studio is a good sample as well.


Well thanks for your reply I already checked these articles and I sucessufully rewrite xna 3.1 to version 4 , but they are only 2 error that I am not able to repair :
Image
I will really appreciate if you help me to resolve them :)
mitko29
 
Posts: 15
Joined: Wed Jan 04, 2012 9:06 pm

Re: Replace glyph with real image

Postby aram » Tue Feb 21, 2012 6:50 pm

just add arguments to event lines.
The old code:
Code: Select all
      public event EventHandler DeviceCreated;
      public event EventHandler DeviceDisposing;
      public event EventHandler DeviceReset;
      public event EventHandler DeviceResetting;

The correct code:
Code: Select all
      public event EventHandler<EventArgs> DeviceCreated;
      public event EventHandler<EventArgs> DeviceDisposing;
      public event EventHandler<EventArgs> DeviceReset;
      public event EventHandler<EventArgs> DeviceResetting;


and here's a cheat sheet in case you run into more errors:
http://nelxon.com/resources/xna-3-1-to-xna-4-0-cheatsheet/
aram
 
Posts: 10
Joined: Wed Mar 25, 2009 8:11 am




Return to GRATF

cron