private void ExecutiveFunctions_ContextRecognition(object sender, ContextRecognitionEventArgs e)
        {
            Bitmap    bitmap;
            BlobImage blobImage       = Program.Engine.Vision.ImageAnalyzer.ContextBlobImage;
            Color     fillColor       = Color.FromArgb(255, blobImage.MeanColor);
            Color     backgroundColor = Color.FromArgb(232, 232, 232);

            // Cheat a little bit
            if (!StaticMode)
            {
                Accord.Imaging.HSL hsl = new Accord.Imaging.HSL((int)fillColor.GetHue(), fillColor.GetSaturation(), fillColor.GetBrightness());
                hsl.NormalizeSaturation();
                fillColor = hsl.ToRGB().Color;
            }

            if (e.TemplateType != TemplateType.Shape || !(e.NamedTemplate is ShapeTemplate))
            {
                bitmap = GuiImaging.GetBitmapBlobImage(blobImage.BitmapBlob, fillColor, backgroundColor);
                ImageDump(bitmap, "Color");
            }
            else
            {
                ShapeTemplate st              = e.NamedTemplate as ShapeTemplate;
                Color         pointColor      = Color.FromArgb(64, Color.Cyan);
                Color         firstPointColor = Color.FromArgb(64, Color.Red);
                Color         lastPointColor  = Color.FromArgb(64, Color.Blue);
                bitmap = GuiImaging.GetBitmapBlobImage(st.BitmapBlob, fillColor, backgroundColor);

                if (st.BlobPoints != null)
                {
                    // Get Initial Points
                    GuiPointsGraphics.DrawInitialPoints(pointColor, firstPointColor, lastPointColor, GuiPointShape.Cross, st.BlobPoints.InitialPoints, bitmap);

                    // Get final Blob Points
                    GuiPointsGraphics.DrawBlobPoints(bitmap, st.BlobPoints, Color.Magenta, Color.Red, Color.Blue, Color.Green, Color.Yellow);
                }

                ImageDump(bitmap, "Shape");
            }

            // Update Display
            FillDisplayImage(blobImage, bitmap);
        }
Example #2
0
 public static void NormalizeSaturation(this Accord.Imaging.HSL hsl)
 {
     if (hsl.Saturation < 0.25F)
     {
         hsl.Saturation *= 3.6F;
     }
     else if (hsl.Saturation < 0.5F)
     {
         hsl.Saturation *= 2.0F;
     }
     else if (hsl.Saturation < 0.7F)
     {
         hsl.Saturation *= 1.6F;
     }
     else if (hsl.Saturation < 0.8F)
     {
         hsl.Saturation *= 1.24F;
     }
     else if (hsl.Saturation < 0.9F)
     {
         hsl.Saturation *= 1.12F;
     }
 }
Example #3
0
        private void ExecutiveFunctions_ContextRecognition(object sender, ContextRecognitionEventArgs e)
        {
            if (e.TemplateType != TemplateType.Shape || !(e.NamedTemplate is ShapeTemplate))
            {
                return;
            }

            //if (e.NamedTemplate.ID != 0)    // The ShapeTemplate has already been identified
            //    return;e

            ShapeTemplate st              = e.NamedTemplate as ShapeTemplate;
            Color         fillColor       = Color.FromArgb(255, blobImage.MeanColor);
            Color         backgroundColor = blobImage.BitmapBlob.BackgroundIsBlack ? Color.Black : Color.White;

            // Cheat a little bit
            Accord.Imaging.HSL hsl = new Accord.Imaging.HSL((int)fillColor.GetHue(), fillColor.GetSaturation(), fillColor.GetBrightness());
            hsl.NormalizeSaturation();

            fillColor = hsl.ToRGB().Color;

            Color  pointColor      = Color.FromArgb(64, Color.Cyan);
            Color  firstPointColor = Color.FromArgb(64, Color.Red);
            Color  lastPointColor  = Color.FromArgb(64, Color.Blue);
            Bitmap bitmap          = GuiImaging.GetBitmapBlobImage(st.BitmapBlob, fillColor, backgroundColor);

#if DEBUG
            if (Settings.Default.ImagingSettings.DebugRecognitionSaveImages)
            {
                bitmap.Save("bitmap.png", System.Drawing.Imaging.ImageFormat.Png);
            }
#endif
            //// Reverse any Rotation
            //if (st.BitmapBlob.Rotation > 0)
            //    bitmap = Galatea.AI.Imaging.Filters.RotateFilter.Rotate(bitmap, st.BitmapBlob.Rotation * -1);

            if (st.BlobPoints != null)
            {
                // Get Initial Points
                GuiPointsGraphics.DrawInitialPoints(pointColor, firstPointColor, lastPointColor, GuiPointShape.Cross, st.BlobPoints.InitialPoints, bitmap);

                // Get final Blob Points
                GuiPointsGraphics.DrawBlobPoints(bitmap, st.BlobPoints, Color.Magenta, Color.Red, Color.Blue, Color.Green, Color.Yellow);
            }

            // Put the blob in the rectangle
            Bitmap newBitmap = null;

            try
            {
                newBitmap = new Bitmap(sourceImage.Width, sourceImage.Height);
                Graphics gfx = Graphics.FromImage(newBitmap);
                gfx.Clear(backgroundColor);

                //if (blobImage.BitmapBlob.BackgroundIsBlack) gfx.Clear(Color.Black);
                gfx.DrawImage(bitmap, blobImage.Location);

                // Update Display
                SetDisplayImage(newBitmap);
                //display.BackColor = backgroundColor;
            }
            catch
            {
                if (newBitmap != null)
                {
                    newBitmap.Dispose();
                }
                throw;
            }
        }