Пример #1
0
        private void DetectToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            if (openFileDialog1.FileName == null || openFileDialog1.FileName == "") return;

            var ObjectList = new List<Image<Gray, byte>>();
            var ObjectBoundList = new List<Rectangle>();

            var arrowSignDetector = new ArrowSignDetector();

            Image<Bgr, byte> image = new Image<Bgr, byte>(openFileDialog1.FileName);
            Image<Gray, byte> grayImage = null;
            Bitmap grayImg = arrowSignDetector.DetectObject(image, ObjectList, ObjectBoundList, grayImage, _setStandardPictureForm.target, ushort.Parse(nudBlackThreshold.Value.ToString()));

            for (int i = 0; i < ObjectList.Count; i++)
            {
                Rectangle rect = ObjectBoundList[i];
                image.Draw(rect, new Bgr(Color.Aquamarine), 2);
            }

            pbBlackWhite.Image = image.Bitmap;
            pbAfter.Image = grayImg;
        }
Пример #2
0
        // 分析条形码贴纸
        private void AnalyseSelectArea(ushort threshold)
        {
            var img = new Image<Bgr, byte>(bitmap);

            int left = Math.Min(selectAreaStartPoint.X, selectAreaEndPoint.X);
            int right = Math.Max(selectAreaStartPoint.X, selectAreaEndPoint.X);
            int top = Math.Min(selectAreaStartPoint.Y, selectAreaEndPoint.Y);
            int buttom = Math.Max(selectAreaStartPoint.Y, selectAreaEndPoint.Y);
            /*int left = selectAreaStartPoint.X;
            int right = selectAreaEndPoint.X;
            int top = selectAreaStartPoint.Y;
            int buttom = selectAreaEndPoint.Y;*/

            double xR = (double)bitmap.Width / (double)pbStandard.Width;
            double yR = (double)bitmap.Height / (double)pbStandard.Height;

            if(threshold == 0)
            {
               _threshold = threshold = ushort.Parse(thresholdUpDown.Value.ToString());
            }
            var detector = new ArrowSignDetector();
             target = detector.FindExernalDefault(img,
                (int) (left*xR),
                (int) (right*xR),
                (int) (top*yR),
                (int) (buttom*yR),
               threshold);

            areaPosition[0] = (int) (left*xR);
            areaPosition[1] = (int) (right*xR);
            areaPosition[2] =  (int) (top*yR);
            areaPosition[3] = (int) (buttom*yR);

            if (target == null )
                tsslInfo.Text = "未识别出目标图形";
            else
            {
                tsslInfo.Text = "已识别出目标图形";
                drawBarCodeTipCornerList.Clear();
            }
            pbStandard.Invalidate();
        }