Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
0
        private void SwitchFillType()
        {
            Bitmap bitmap;
            Color  fillColor = Color.FromArgb(64, blobImage.MeanColor);
            Color  backgroundColor = Color.FromArgb(232, 232, 232);
            bool   hasLines, hasCurves, isCircle;

            switch (blobFillType)
            {
            case 0:     // Get the Monochrome Bitmap Blob
                bitmap = GuiImaging.GetBitmapBlobImage(blobImage.BitmapBlob, blobImage.MeanColor, backgroundColor);
                FillDisplayImage(bitmap);
                return;

            case 1:     // Get BitmapBlob Initial Points
                bitmap = GuiImaging.GetBitmapBlobInitialPointsImage(blobImage.BitmapBlob, fillColor, backgroundColor,
                                                                    Color.Cyan, GuiPointShape.Cross);
                FillDisplayImage(bitmap);
                return;

            case 2:     // Get BitmapBlob Threshold Points
                bitmap = GuiImaging.GetThresholdBlobPointsImage(blobImage.BitmapBlob, fillColor, backgroundColor, Color.Cyan,
                                                                Color.Magenta, Color.Green, Color.Yellow, out hasLines, out hasCurves, out isCircle);
                FillDisplayImage(bitmap);

                if (isCircle)
                {
                    blobFillType += 2;
                }
                //if (!hasLines) blobFillType++;
                return;

            //case 3: // Get Vertex Intersection Points
            //    bitmap = GuiImaging.GetVertexIntersectionBlobPointsImage(blobImage.BitmapBlob, fillColor, Color.Cyan,
            //        Color.Magenta, Color.Green, Color.Yellow, out hasLines, out hasCurves, out isCircle);
            //    FillDisplayImage(bitmap);

            //    if (!hasCurves) blobFillType++;
            //    return;

            case 3:     // Get BitmapBlob Tangents
                bitmap = GuiImaging.GetTangentBlobPointsImage(blobImage.BitmapBlob, fillColor, backgroundColor, Color.Cyan,
                                                              Color.Magenta, Color.Green, Color.Yellow, out hasLines, out hasCurves, out isCircle);
                FillDisplayImage(bitmap);
                return;

            ////case 5: // Get Adjusted BitmapBlob Points
            ////    bitmap = GuiImaging.GetAdjustedBlobPointsImage(blobImage.BitmapBlob, fillColor,
            ////        Color.Cyan, Color.Magenta, Color.Green, Color.Yellow, out isCircle);

            ////    if (isCircle)
            ////    {
            ////        Program.Engine.Debugger.Log(Galatea.Runtime.Services.DebuggerLogLevel.Message, "It's a Circle!");
            ////        blobFillType = 0;
            ////    }
            ////    else
            ////    {
            ////        FillDisplayImage(bitmap);
            ////    }
            ////    return;

            ////case 6: // Get BitmapBlob Points with Properties
            ////    bitmap = GuiImaging.GetBlobPointsPropertiesImage(blobImage.BitmapBlob, fillColor, Color.Cyan,
            ////        Color.Orange, Color.DarkGreen, Color.Yellow, out isCircle);

            ////    if (isCircle)
            ////    {
            ////        Program.Engine.Debugger.Log(Galatea.Runtime.Services.DebuggerLogLevel.Message, "It's a Circle!");
            ////        blobFillType = 0;
            ////    }
            ////    else
            ////    {
            ////        FillDisplayImage(bitmap);
            ////    }
            ////    return;

            default:
                // Set the original Source Image
                SetDisplayImage(sourceImage);

                // Reset the Incrementer to zero
                blobFillType = 0;

                return;
            }
        }