Exemplo n.º 1
0
        private void Btn_validate_Click(object sender, EventArgs e)
        {
            //思路:获取扫描结果的左上角定位点,-》计算偏移量-》整体偏移-》获取答案结果-》是否根据偏移块进行详细偏移

            //重新获取扫描结果的定位点
            var leftTopArea  = this.OriginalPaper.FixedPoint.LeftTop.GetEnlargeOuter();
            var cutBitmap    = PictureBoxReadCard.Cut(this.OriginalBitmap, leftTopArea.X, leftTopArea.Y, leftTopArea.Width, leftTopArea.Height);
            var leftTopInner = common.GetBigRectFromBitmap(cutBitmap, 2000, 6000, leftTopArea.X, leftTopArea.Y);

            CalcOffset(this.OriginalPaper.FixedPoint.LeftTop.Inner, leftTopInner, out int offsetX, out int offsetY);
            var scanPaper = this.OriginalPaper.NewPaperByOffset(offsetX, offsetY);

            //根据偏移块进行调整
            scanPaper = CalPaperByOffsetS(scanPaper, this.OriginalBitmap);

            var mat = new Image <Bgr, byte>(this.OriginalBitmap).Mat;

            PaperRegResultShowForm.DrawPaperRect(mat, scanPaper);


            this.picSrc.LoadImage(mat.Bitmap);

            //保存
            string calOffsetStr = this.IsCalOffset.Checked ? "并模块偏移" : "";

            common.SaveMat(mat, $"试卷结果校验后{ calOffsetStr }在扫描模板中显示");
        }
Exemplo n.º 2
0
        private void Btn_regWrap_Click(object sender, EventArgs e)
        {
            //思路:重新调整大小(根据四个定位点),获取扫描结果的定位点,获取答案结果

            //重新获取扫描结果的定位点
            var leftTopArea  = this.OriginalPaper.FixedPoint.LeftTop.GetEnlargeOuter();
            var cutBitmap    = PictureBoxReadCard.Cut(this.OriginalBitmap, leftTopArea.X, leftTopArea.Y, leftTopArea.Width, leftTopArea.Height);
            var leftTopInner = common.GetBigRectFromBitmap(cutBitmap, 2000, 6000, leftTopArea.X, leftTopArea.Y);

            CalcOffset(this.OriginalPaper.FixedPoint.LeftTop.Inner, leftTopInner, out int offsetX, out int offsetY);
            var scanPaper = this.OriginalPaper.NewPaperByOffset(offsetX, offsetY);


            var mat = new Image <Bgr, byte>(this.OriginalBitmap).Mat;
            //通过透视调整大小
            List <PointF> srcPoints = scanPaper.FixedPoint.GetPointsByClockwise();
            List <PointF> desPoints = new List <PointF>()
            {
                CVHelper.PointToPointF(scanPaper.FixedPoint.LeftTop.Inner.Location)
            };
            //右上
            var rightTopArea   = scanPaper.FixedPoint.RightTop.Outer;
            var rightTopBitmap = PictureBoxReadCard.Cut(this.OriginalBitmap, rightTopArea);
            var rightTopInner  = common.GetBigRectFromBitmap(rightTopBitmap, 2000, 6000, rightTopArea.X, rightTopArea.Y);

            desPoints.Add(CVHelper.PointToPointF(rightTopInner.Location));
            //右下
            var rightBottomArea   = scanPaper.FixedPoint.RightBottom.Outer;
            var rightBottomBitmap = PictureBoxReadCard.Cut(this.OriginalBitmap, rightBottomArea);
            var rightBottomInner  = common.GetBigRectFromBitmap(rightBottomBitmap, 2000, 6000, rightBottomArea.X, rightBottomArea.Y);

            desPoints.Add(CVHelper.PointToPointF(rightBottomInner.Location));
            //左下
            var leftBottomArea   = scanPaper.FixedPoint.LeftBottom.Outer;
            var leftBottomBitmap = PictureBoxReadCard.Cut(this.OriginalBitmap, leftBottomArea);
            var leftBottomInner  = common.GetBigRectFromBitmap(leftBottomBitmap, 2000, 6000, leftBottomArea.X, leftBottomArea.Y);

            desPoints.Add(CVHelper.PointToPointF(leftBottomInner.Location));

            //计算透视矩阵
            Mat data = CvInvoke.GetPerspectiveTransform(desPoints.ToArray(), srcPoints.ToArray());
            //进行透视操作
            //Mat src_gray = new Mat();
            Mat mat_Perspective = new Mat();

            CvInvoke.WarpPerspective(mat, mat_Perspective, data, this.OriginalBitmap.Size);

            //根据偏移块进行调整
            scanPaper = CalPaperByOffsetS(scanPaper, mat_Perspective.Bitmap);

            PaperRegResultShowForm.DrawPaperRect(mat_Perspective, scanPaper);


            this.picSrc.LoadImage(mat_Perspective.Bitmap);

            //保存
            string calOffsetStr = this.IsCalOffset.Checked ? "并模块偏移" : "";

            common.SaveMat(mat_Perspective, $"试卷结果校正透视后{calOffsetStr}在扫描模板中显示");
        }
Exemplo n.º 3
0
        private void Btn_validate2_Click(object sender, EventArgs e)
        {
            //思路获取偏移量,
            List <PointF> srcPoints = this.OriginalPaper.FixedPoint.GetPointsByClockwise();
            List <PointF> desPoints = new List <PointF>();
            //重新获取扫描结果的全部定位点-》重新调整大小(根据四个定位点透视)
            //左上
            var leftTopArea  = this.OriginalPaper.FixedPoint.LeftTop.GetEnlargeOuter();
            var cutBitmap    = PictureBoxReadCard.Cut(this.OriginalBitmap, leftTopArea.X, leftTopArea.Y, leftTopArea.Width, leftTopArea.Height);
            var leftTopInner = common.GetBigRectFromBitmap(cutBitmap, 500, 6000, leftTopArea.X, leftTopArea.Y);

            desPoints.Add(leftTopInner.Location);
            //右上
            var rightTopArea   = this.OriginalPaper.FixedPoint.RightTop.GetEnlargeOuter();
            var rightTopBitmap = PictureBoxReadCard.Cut(this.OriginalBitmap, rightTopArea);
            var rightTopInner  = common.GetBigRectFromBitmap(rightTopBitmap, 500, 6000, rightTopArea.X, rightTopArea.Y);

            desPoints.Add(CVHelper.PointToPointF(rightTopInner.Location));
            //右下
            var rightBottomArea   = this.OriginalPaper.FixedPoint.RightBottom.GetEnlargeOuter();
            var rightBottomBitmap = PictureBoxReadCard.Cut(this.OriginalBitmap, rightBottomArea);
            var rightBottomInner  = common.GetBigRectFromBitmap(rightBottomBitmap, 500, 6000, rightBottomArea.X, rightBottomArea.Y);

            desPoints.Add(CVHelper.PointToPointF(rightBottomInner.Location));
            //左下
            var leftBottomArea   = this.OriginalPaper.FixedPoint.LeftBottom.GetEnlargeOuter();
            var leftBottomBitmap = PictureBoxReadCard.Cut(this.OriginalBitmap, leftBottomArea);
            var leftBottomInner  = common.GetBigRectFromBitmap(leftBottomBitmap, 500, 6000, leftBottomArea.X, leftBottomArea.Y);

            desPoints.Add(CVHelper.PointToPointF(leftBottomInner.Location));



            //计算透视矩阵
            Mat data = CvInvoke.GetPerspectiveTransform(desPoints.ToArray(), srcPoints.ToArray());
            //进行透视操作
            var mat             = new Image <Bgr, byte>(this.OriginalBitmap).Mat;
            Mat mat_Perspective = new Mat();

            CvInvoke.WarpPerspective(mat, mat_Perspective, data, this.OriginalBitmap.Size, Inter.Nearest, Warp.Default, BorderType.Constant, new MCvScalar(255, 255, 255));

            //根据偏移块进行调整
            var paper = CalPaperByOffsetS(this.OriginalPaper, mat_Perspective.Bitmap);

            PaperRegResultShowForm.DrawPaperRect(mat_Perspective, paper);


            this.picSrc.LoadImage(mat_Perspective.Bitmap);


            //保存
            string calOffsetStr = this.IsCalOffset.Checked ? "并模块偏移" : "";

            common.SaveMat(mat_Perspective, $"试卷结果直接透视后{calOffsetStr}在扫描模板中显示");
        }
Exemplo n.º 4
0
        private void Btn_resultShow_Click(object sender, EventArgs e)
        {
            //先保存
            if (this.ckb_save.Checked)
            {
                this.SavePaper();
            }
            PaperRegResultShowForm form = new PaperRegResultShowForm(this.Paper, (Bitmap)this.ib_original.orignalBitmap.Clone());

            form.Show();
        }
Exemplo n.º 5
0
        private void Btn_recover_Click(object sender, EventArgs e)
        {
            var mat = new Image <Bgr, byte>(this.OriginalBitmap).Mat;



            PaperRegResultShowForm.DrawPaperRect(mat, this.OriginalPaper);


            this.picSrc.LoadImage(mat.Bitmap);

            //保存
            common.SaveMat(mat, "试卷结果在扫描模板中显示");
        }