示例#1
0
        /// <summary>
        /// Renders a captured image along with recognized contours
        /// </summary>
        private void DrawConturs(ContourFilter processor, System.Drawing.Bitmap imageBuffer)
        {
            System.Drawing.Font font = new System.Drawing.Font("Arial", 24);
            // visual style of contours and labels
            System.Drawing.Brush bgBrush   = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0));
            System.Drawing.Brush foreBrush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 255, 255, 255));
            System.Drawing.Pen   borderPen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(255, 0, 0, 255));
            borderPen.Width = 5;

            // we use double buffer -> the rendering will take its place once the image is ready
            System.Drawing.Graphics grBuffer = System.Drawing.Graphics.FromImage(imageBuffer);
            grBuffer.ScaleTransform((float)(width / 640), (float)((height - 20) / 480));
            foreach (FoundTemplateDesc found in processor.foundTemplates)
            {
                // draw detected contours along with their name and wrapping rectangle
                System.Drawing.Rectangle foundRect = found.sample.contour.SourceBoundingRect;
                System.Drawing.Point     p1        = new System.Drawing.Point((foundRect.Left + foundRect.Right) / 2, foundRect.Top);
                string text = found.template.name;

                grBuffer.DrawRectangle(borderPen, foundRect);
                grBuffer.DrawString(text, font, bgBrush, new System.Drawing.PointF(p1.X + 1 - font.Height / 3, p1.Y + 1 - font.Height));
                grBuffer.DrawString(text, font, foreBrush, new System.Drawing.PointF(p1.X - font.Height / 3, p1.Y - font.Height));
            }
            grBuffer.Dispose();
            captureBox.CreateGraphics().DrawImage(imageBuffer, 0, 0);
        }
示例#2
0
        private Boolean showAngle; // if true, normals of vertices will be shown


        public CaptureWindow()
        {
            InitializeComponent();

            this.resolutionComboBox.Items.Add("640x480");
            this.resolutionComboBox.Items.Add("320x240");
            this.resolutionComboBox.SelectedIndex = 1;
            Processor = new ContourFilter();
        }
示例#3
0
        /// <summary>
        /// Resizes captured image and renders it along with all contours
        /// </summary>
        /// <param name="tempFrame">captured image</param>
        /// <param name="processor">processor with detected contours</param>
        public void DrawImage(Image <Bgr, byte> tempFrame, ContourFilter processor)
        {
            // Save the variables asynchronously
            Dispatcher.BeginInvoke(new Action(() =>
            {
                width  = Width;
                height = Height;
            }));

            tempFrame = tempFrame.Resize((int)width, (int)(height - 20), Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR);
            DrawConturs(processor, tempFrame.Bitmap);
        }
示例#4
0
        private void LoadProcessor()
        {
            processor           = new ContourFilter();
            processor.templates = CommonAttribService.DEFAULT_TEMPLATES;

            // set default values

            processor.finder.maxRotateAngle            = CaptureSettings.Instance().DEFAULT_ROTATE_ANGLE *Math.PI / 180;
            processor.minContourArea                   = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_AREA;
            processor.minContourLength                 = CaptureSettings.Instance().DEFAULT_CONTOUR_MIN_LENGTH;
            processor.finder.maxACFDescriptorDeviation = CaptureSettings.Instance().DEFAULT_MAX_ACF;
            processor.finder.minACF              = CaptureSettings.Instance().DEFAULT_MIN_ACF;
            processor.finder.minICF              = CaptureSettings.Instance().DEFAULT_MIN_ICF;
            processor.noiseFilter                = CaptureSettings.Instance().DEFAULT_NOISE_ENABLED;
            processor.cannyThreshold             = CaptureSettings.Instance().DEFAULT_NOISE_FILTER;
            processor.adaptiveThresholdBlockSize = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_BLOCKSIZE;
            processor.adaptiveThresholdParameter = CaptureSettings.Instance().DEFAULT_ADAPTIVE_THRESHOLD_PARAMETER;
            processor.blur = CaptureSettings.Instance().DEFAULT_BLUR_ENABLED;

            realTableManager = new RealTableManager(tableManager.TableDepositor);
            realTableManager.Init(CommonAttribService.DEFAULT_TEMPLATES);
        }