Ejemplo n.º 1
0
 //-------------------------------------------------------------------------
 public void InvertSelectedBubble(Bubble bubble)
 {
     BubbleItem item = null;
     try
     {
         //item = rec.BubbleItems[bubble.index];
         item = rec.BubbleItems.First(z => z.Bubble.Equals(SelectedBubble));
     }
     catch (Exception)
     {
     }
     if (item != null)
         item.CheckedBubble.isChecked = !item.CheckedBubble.isChecked;
 }
Ejemplo n.º 2
0
        //-------------------------------------------------------------------------
        public void MouseEnterBubble(Bubble bubble)
        {
            try
            {
                var item = rec.BubbleItems.First(z => z.Bubble.Equals(bubble));
                //var item = rec.BubbleItems[bubble.index];
                int x = (int)Math.Round(item.CheckedBubble.rectangle.X * Zoom);
                int y = (int)Math.Round(item.CheckedBubble.rectangle.Y * Zoom);

                pictureBox1_MouseMove(null, new MouseEventArgs(MouseButtons.Left, 1, x + 1, y + 1, 1));
                pnlScrollBubble.Width = (int)Math.Round(item.CheckedBubble.rectangle.Width * Zoom);
                pnlScrollBubble.Height = (int)Math.Round(item.CheckedBubble.rectangle.Height * Zoom);
                pnlScrollBubble.Location = new Point(x, y);
                SetScroll();
                ImagePanel.ScrollControlIntoView(pnlScrollBubble);
            }
            catch (Exception)
            { }
        }
Ejemplo n.º 3
0
        //-------------------------------------------------------------------------
        public void FindBubble(Rectangle[] factRectangle, Dictionary<Bubble, Point[]> allContourMultiLine
            , bool grid = false)
        {
            int bubblesPerWidth = 0, bubbleStepX = 0, bubbleStepY = 0;
            int areaNumber = -1;
            int goodBubbleNumber = 0;
            int prevGoodLine = 0, prevGoodLineY = 0;
            int maxBubblesDist = 12900;//25;//
            int[] axisX = new int[1];
            int[] axisY = new int[1];
            int[] axisYSubline = new int[1];
            //Rectangle bubble1 = Rectangle.Empty;
            Rectangle bubble1 = bubblesOfRegion[0];
            Rectangle prevRectangle = Rectangle.Empty;
            Bubble bubble = new Bubble();
            double factStepY = bubble1.Height + bubbleStepY;

            //for (int i = 0; i < maxCountRectangles.Count; i++)
            //{
            //    var itm = maxCountRectangles.ElementAt(i);
            //    BubbleItems[i].CheckedBubble = itm.Value;
            //}

            if (axisX.Length == 1)
            {
                recTools.GetAxis
                    (
                      ref axisX
                    , ref axisY
                    , ref factRectangle
                    , allContourMultiLine
                    , bubble1
                    , ref axisYSubline
                    //, smartResize
                    //, factor
                    );
            }
            BubbleItem FirstBubbleItemOfArea = null;
            for (int k = 0; k < BubbleItems.Count; k++)
            {
                BubbleItem item = BubbleItems[k];
                //KeyValuePair<Bubble, CheckedBubble> item = maxCountRectangles.ElementAt(k);
                int bubblesRegion = item.Bubble.areaNumber;
                if (String.IsNullOrEmpty(areas[0].bubblesOrientation) || areas[0].bubblesOrientation == "horizontal")
                {
                    bubbleStepY = (int)Math.Round((decimal)(lineHeight[bubblesRegion] - bubble1.Height));
                }
                else
                {
                    bubbleStepY = (int)Math.Round((decimal)(bubblesRegions[bubblesRegion].Height
                        - bubble1.Height * bubblesPerWidth) / (bubblesPerWidth - 1));
                }

                if (areaNumber != bubblesRegion)
                {
                    areaNumber = bubblesRegion;
                    //factStepY = (int)Math.Round((decimal)(bubblesRegions[bubblesRegion].Height
                    // bubblesPerLine[bubblesRegion]));
                    if (String.IsNullOrEmpty(areas[0].bubblesOrientation)
                      || areas[0].bubblesOrientation == "horizontal")
                        bubbleStepY = (int)Math.Round((decimal)(lineHeight[bubblesRegion] - bubble1.Height));
                    else
                        bubbleStepY = (int)Math.Round((decimal)(bubblesRegions[bubblesRegion].Height
                            - bubble1.Height * bubblesPerWidth) / (bubblesPerWidth - 1));
                    factStepY = bubble1.Height + bubbleStepY;

                    prevGoodLineY = 0; prevGoodLine = 0;
                    recTools.GetLineFactStep
                     (
                       ref factStepY
                     , ref prevGoodLine
                     , ref prevGoodLineY
                     , k
                     , areas[bubblesRegion]
                     , factRectangle
                     , allContourMultiLine
                     , bubblesRegion
                     //, minContourLength
                     );
                    bubblesPerWidth = bubblesPerLine[bubblesRegion];
                    bubble1 = bubblesOfRegion[bubblesRegion];
                    if (string.IsNullOrEmpty(areas[bubblesRegion].bubblesOrientation)
                        || areas[bubblesRegion].bubblesOrientation == "horizontal"
                        )
                        bubbleStepX = (int)Math.Round((decimal)(bubblesRegions[bubblesRegion].Width
                            - bubble1.Width * bubblesPerWidth) / (bubblesPerWidth - 1));
                    else
                    {
                        if (areas[bubblesRegion].subLinesAmount == 0)
                        {
                            bubblesSubLinesStep[bubblesRegion] = (int)Math.Round((decimal)(areas[0].bubble.Width * 2) * kx);
                        }
                        bubbleStepX = bubblesSubLinesStep[bubblesRegion];
                        bubbleStepY = (int)Math.Round((decimal)(bubblesRegions[bubblesRegion].Height
                            / bubblesPerLine[bubblesRegion] - bubble1.Height));
                    }
                }
                if (item.CheckedBubble.rectangle.Size == new Size())
                {
                    //#region плохой пузырь // almost like in Recognize -> BadBubble()
                    if (!grid)
                        BadBubble
                            (item
                            , k
                            , maxBubblesDist
                            , bubblesRegion
                            , bubble1
                            , ref prevRectangle
                            , bubbleStepX
                            , factStepY
                            , axisY
                            );
                }
                else
                {//хороший пузырь
                    int factRect = Array.IndexOf(factRectangle, item.CheckedBubble.rectangle);
                    GoodBubble(item, k, bubblesRegion, ref factStepY, ref bubble, ref prevGoodLineY, item.CheckedBubble.rectangle.Y);
                    goodBubbleNumber = factRect;// k;
                    prevRectangle = new Rectangle(item.CheckedBubble.rectangle.X, item.CheckedBubble.rectangle.Y
                        , item.CheckedBubble.rectangle.Width, item.CheckedBubble.rectangle.Height);
                }
            }
            for (int k = 0; k < BubbleItems.Count; k++)
            {
                BubbleItem item = BubbleItems[k];
                int bubblesRegion = item.Bubble.areaNumber;
                if (String.IsNullOrEmpty(areas[bubblesRegion].bubblesOrientation) || areas[bubblesRegion].bubblesOrientation == "horizontal")
                {
                    bubbleStepY = (int)Math.Round((decimal)(lineHeight[bubblesRegion] - bubble1.Height));
                    if (k == 0)
                    {
                        FirstBubbleItemOfArea = BubbleItems[0];
                    }
                    else
                    {
                        if (FirstBubbleItemOfArea != null && FirstBubbleItemOfArea.Bubble.areaNumber != item.Bubble.areaNumber)
                        {
                            if (Math.Abs(item.CheckedBubble.rectangle.Y - FirstBubbleItemOfArea.CheckedBubble.rectangle.Y)
                                >= FirstBubbleItemOfArea.CheckedBubble.rectangle.Height)
                            {
                                //Exception = new Exception("Calibration error 3");
                                barCodesPrompt = "Calibration error 3";
                                var maxCountRectangles = AddMaxCountRectangles();
                                BubbleItems.Clear();
                                FillBubbleItems(maxCountRectangles);
                                break;
                            }
                            FirstBubbleItemOfArea = item;
                        }
                        else
                        {
                            if (FirstBubbleItemOfArea != null && item.Bubble.point.X == 0 && FirstBubbleItemOfArea.Bubble.point.Y != item.Bubble.point.Y)
                            {
                                if (Math.Abs(item.CheckedBubble.rectangle.X - FirstBubbleItemOfArea.CheckedBubble.rectangle.X)
                                    >= FirstBubbleItemOfArea.CheckedBubble.rectangle.Height)
                                {
                                    //Exception = new Exception("Calibration error 4");
                                    barCodesPrompt = "Calibration error 4";
                                    var maxCountRectangles = AddMaxCountRectangles();
                                    BubbleItems.Clear();
                                    FillBubbleItems(maxCountRectangles);
                                    break;
                                }
                            }
                        }
                    }
                }
                //else
                //{//для vertical

                //}
            }
        }
Ejemplo n.º 4
0
        //-------------------------------------------------------------------------
        void btnOk_Click(object sender, EventArgs e)
        {
            Status = StatusMessage.NULL;
            try
            {
                RecognizeBubblesButton.Enabled = false;
                for (int i = 0; i < factAreasManualSet.Length; i++)
                {
                    if (!factAreasManualSet[i])
                    {
                        int x = (int)Math.Round(factAreas[i].left * Zoom);
                        int y = (int)Math.Round(factAreas[i].top * Zoom);
                        areaNaturalSize = allAreasNaturalSize[i];
                        pictureBox1_MouseUp(null, new MouseEventArgs(MouseButtons.Left, 0, x, y, 0));
                        factAreasManualSet[i] = false;
                    }
                }
                eDoctrinaOcrEd.TestUids testUid = new TestUids();
                string testUidAmoutOfQuestions = "", testUidIndexOfFirstQuestion = "";
                for (int i = 0; i < barCodeList.ControlList.Count; i++)
                {
                    BarCodeListItemControl item = (BarCodeListItemControl)barCodeList.ControlList[i];
                    //}
                    //foreach (BarCodeListItemControl item in barCodeList.ControlList)
                    //{
                    RecognizeBubblesButton.Enabled = false;
                    if (item.Name == "amout_of_questions")
                    {
                        amout_of_questionsIndex = i;
                        if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text))
                        {
                            if (factLinesPerArea[0] == 0)
                            {
                                item.btnCheck.PerformClick();
                                return;
                            }
                            item.comboBox1.Text = factLinesPerArea.Sum().ToString();
                            if (errList.Contains("Error in " + item.Name))
                            {
                                errList.Remove("Error in " + item.Name);
                                VerifyErrList();
                            }
                            break;
                        }
                        else
                        {
                            testUidAmoutOfQuestions = item.comboBox1.Text;
                        }
                    }
                    else if (item.Name == "index_of_first_question" || item.Name == "question_number_1")
                    {
                        if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text))
                        {
                            item.comboBox1.Text = "1";
                            if (errList.Contains("Error in " + item.Name))
                            {
                                errList.Remove("Error in " + item.Name);
                                VerifyErrList();
                            }
                        }
                        else
                        {
                            testUidIndexOfFirstQuestion = item.comboBox1.Text;
                        }
                    }
                    else if (item.Name == "test_id")
                    {
                        if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text))
                        {

                        }
                        else
                        {
                            testId = item.comboBox1.Text;
                        }
                    }
                    else if (item.Name == "district_id")
                    {
                        if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text))
                        {

                        }
                        else
                        {
                            districtId = item.comboBox1.Text;
                        }
                    }

                }
                PrevRecognizeBubbles();
                //testUidTestId = testId;
                //testUidShetId = rec.SheetIdentifier;
                string key = rec.SheetIdentifier + "_" + testId + "_" + amoutOfQuestions + "_" + indexOfQuestion;
                //int index=testUids.
                eDoctrinaOcrEd.TestUids.AreaSettings[] arrs = new TestUids.AreaSettings[factAreas.Length];
                if (rec.SheetIdentifier == "FLEX")
                {
                    if (factAreas[0].bubblesPerLine > rec.bubbles_per_lineFLEX)
                    {
                        MessageBox.Show("Invalid value of cols."
                           , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        rbtnGrid.Checked = true;
                        return;
                    }
                }
                for (int i = 0; i < factAreas.Length; i++)
                {
                    arrs[i].BubblesPrrLine = factAreas[i].bubblesPerLine;
                    arrs[i].SubLineAmout = factAreas[i].subLinesAmount;
                    //if (rec.areas[i].bubblesPerLine < factAreas[i].bubblesPerLine)
                    //{
                    //}
                }
                if (testUids.Test.ContainsKey(key))
                {
                    testUids.Test[key] = arrs;//factAreas;
                }
                else
                {
                    testUids.Test.Add(key, arrs);
                }
                areaNaturalSize = Rectangle.Empty;
                for (int i = 0; i < factAreas.Length; i++)
                {
                    if (factAreas[i].width == 0 && allAreasNaturalSize[i].Width != 0)
                    {
                        factAreas[i].left = allAreasNaturalSize[i].X;
                        factAreas[i].top = allAreasNaturalSize[i].Y;
                        factAreas[i].width = allAreasNaturalSize[i].Width;
                        factAreas[i].height = allAreasNaturalSize[i].Height;
                    }
                }
                double heightEt;
                double kx, ky;
                //rec.Status = RecognizeAction.SearchBublesFinished;
                rec.allContourMultiLine = new Dictionary<Bubble, Point[]>();
                rec.factRectangle = new Rectangle[0];
                Rectangle bubble = Rectangle.Empty;
                double factStepX, factStepY;
                int amout_of_questions = 0;
                Bubble bubble1 = new Bubble();
                //bubble1.point = new Point(rec.indexOfFirstBubble, rec.IndexOfFirstQuestion - 1);
                bubble1.point = new Point(0, rec.IndexOfFirstQuestion - 1);
                for (int i = 0; i < factAreas.Length; i++)
                {//Areas++
                    if (factAreas[i].left < 0 || factAreas[i].left > pictureBox1.Image.Width
                        || factAreas[i].width <= 0 || factAreas[i].width > pictureBox1.Image.Width
                        || factAreas[i].top < 0 || factAreas[i].top > pictureBox1.Image.Height
                        || factAreas[i].height <= 0 || factAreas[i].height > pictureBox1.Image.Height
                        || factAreas[i].lineHeight < 0)
                    {

                        factAreas[i] = new RegionsArea();
                    }
                    if (factAreas.Length > 1 && factAreas[0].height == 0 || (i > 0 && factAreas[i - 1].height == 0))
                    {
                        MessageBox.Show("You must specify all areas of bubbles."
                            , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        rbtnGrid.Checked = true;
                        return;
                    }
                    if (factAreas[i].height == 0)
                        continue;
                    amout_of_questions += factLinesPerArea[i];

                    if (rec.kx == 0)
                        rec.kx = 1;
                    if (rec.ky == 0)
                        rec.ky = 1;

                    if (rec.kx != 1 || rec.ky != 1)
                    {//EditorForm.cs:строка 3737
                        rec.bubblesOfRegion[i] = new Rectangle((int)Math.Round(rec.bubblesOfRegion[i].X / rec.kx)
                        , (int)Math.Round(rec.bubblesOfRegion[i].Y / rec.ky), rec.bubblesOfRegion[i].Width, rec.bubblesOfRegion[i].Height);
                        rec.bubblesRegions[i].Width = (int)Math.Round(rec.bubblesRegions[i].Width / rec.kx);
                        rec.bubblesRegions[i].Height = (int)Math.Round(rec.bubblesRegions[i].Height / rec.ky);
                    }
                    double EtStepX = (double)
                        (bubblesRegions.areas[i].width - bubblesRegions.areas[i].bubble.Width
                        * bubblesRegions.areas[i].bubblesPerLine)
                        / (bubblesRegions.areas[i].bubblesPerLine - 1);
                    int widthEt = (int)(bubblesRegions.areas[i].bubble.Width
                        * factAreas[i].bubblesPerLine + EtStepX * (factAreas[i].bubblesPerLine - 1));//(int)linsForm.nudCols.Value - 1);
                    kx = (double)factAreas[i].width / widthEt;
                    rec.kx = (decimal)kx;
                    double EtStepY = 0;
                    if (rec.linesPerArea[i] > 1)
                    {
                        EtStepY = (double)(bubblesRegions.areas[i].height
                            - bubblesRegions.areas[i].bubble.Height * rec.linesPerArea[i]) / (rec.linesPerArea[i] - 1);
                    }
                    //double EtStepY = bubblesRegions.areas[i].lineHeight - bubblesRegions.areas[i].bubble.Height;
                    heightEt = bubblesRegions.areas[i].bubble.Height * factLinesPerArea[i]
                       + EtStepY * (factLinesPerArea[i] - 1)
                       + (bubblesRegions.areas[i].subLineHeight
                       * (factAreas[i].subLinesAmount));//bubblesRegions.areas[i].subLinesAmount -
                    ky = (double)factAreas[i].height / heightEt;
                    rec.ky = (decimal)ky;

                    //rec.ProcessingRegions();

                    bubble.Width = (int)Math.Round(bubblesRegions.areas[i].bubble.Width * kx);
                    bubble.Height = (int)Math.Round(bubblesRegions.areas[i].bubble.Height * ky);
                    factStepX = (double)(factAreas[i].width + EtStepX * kx) / (double)factAreas[i].bubblesPerLine;
                    double distX = (double)factStepX - bubble.Width;
                    //double halfDistX = (double)distX / 2;
                    factAreas[i].lineHeight = (int)Math.Round(bubblesRegions.areas[i].lineHeight * ky);
                    factAreas[i].subLineHeight = (int)Math.Round(bubblesRegions.areas[i].subLineHeight * ky);
                    factAreas[i].bubble = new Rectangle((int)(rec.bubblesOfRegion[i].X * kx)
                                                            , (int)(rec.bubblesOfRegion[i].Y * ky)
                                                            , bubble.Width
                                                            , bubble.Height
                                                            );//???

                    rec.bubblesOfRegion[i] = new Rectangle((int)(rec.bubblesOfRegion[i].X * kx)
                        , (int)(rec.bubblesOfRegion[i].Y * ky), bubble.Width, bubble.Height);

                    rec.bubblesRegions[i].Width = (int)Math.Round(rec.bubblesRegions[i].Width * rec.kx);
                    rec.bubblesRegions[i].Height = (int)Math.Round(rec.bubblesRegions[i].Height * rec.ky);

                    factStepY = (double)((factAreas[i].height + EtStepY * ky)
                        - factAreas[i].subLineHeight * factAreas[i].subLinesAmount) / (double)factLinesPerArea[i];
                    Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1);
                    rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle
                        (
                          factAreas[i].left
                        , factAreas[i].top
                        , bubble.Width
                        , bubble.Height
                        );

                    bubble1.areaNumber = i;
                    //bubble1.point = new System.Drawing.Point(rec.indexOfFirstBubble, bubble1.point.Y + 1);
                    bubble1.point = new System.Drawing.Point(0, bubble1.point.Y + 1);
                    bubble1.subLine = 0;
                    rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5]
                {
                 new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                });

                    //Bitmap b2 = (Bitmap)pictureBox1.Image.Clone();
                    //using (Graphics g = Graphics.FromImage(b2))
                    //{
                    for (int j = 0; j < factLinesPerArea[i]; j++)//(int)linsForm.nudRows.Value
                    {//line++
                        //g.DrawLine
                        //    (
                        //      new Pen(Color.Blue)
                        //    , factAreas[i].left
                        //    , (int)(factAreas[i].top + factStepY * j)
                        //    , factAreas[i].left + factAreas[i].width
                        //    , (int)(factAreas[i].top + factStepY * j)
                        //    );
                        if (j > 0)
                        {
                            Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1);
                            rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle
                                (
                                  factAreas[i].left
                                , factAreas[i].top + (int)Math.Round((factStepY) * j)
                                , bubble.Width
                                , bubble.Height
                                );

                            //bubble1.point = new Point(rec.indexOfFirstBubble, bubble1.point.Y + 1);
                            bubble1.point = new Point(0, bubble1.point.Y + 1);
                            bubble1.subLine = 0;

                            rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5]
                                {
                                 new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                });

                        }
                        for (int k = 0; k <= (int)bubblesRegions.areas[i].subLinesAmount; k++)
                        {
                            if (k > 0)
                            {//subLine++
                                Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1);
                                rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle
                                (
                                  factAreas[i].left
                                , rec.factRectangle[rec.factRectangle.Length - 2].Y + factAreas[i].subLineHeight
                                , bubble.Width
                                , bubble.Height
                                );

                                bubble1.subLine = bubble1.subLine + 1;
                                //bubble1.point = new Point(rec.indexOfFirstBubble, bubble1.point.Y);
                                bubble1.point = new Point(0, bubble1.point.Y);
                                rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5]
                                {
                                 new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                });
                            }

                            for (int l = 1; l < factAreas[i].bubblesPerLine; l++)//(int)linsForm.nudCols.Value
                            {//point.X++

                                //    g.DrawLine
                                //(
                                //new Pen(Color.Blue)
                                //, (int)(factAreas[i].left + factStepX * l)
                                //, factAreas[i].top
                                //, (int)(factAreas[i].left + factStepX * l)
                                //, factAreas[i].top + factAreas[i].height
                                //);

                                Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1);
                                rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle
                                   (
                                     factAreas[i].left + (int)Math.Round((factStepX) * l)
                                   , rec.factRectangle[rec.factRectangle.Length - 2].Y
                                   , bubble.Width
                                   , bubble.Height
                                  );
                                bubble1.point = new Point(bubble1.point.X + 1, bubble1.point.Y);
                                rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5]
                                {
                                 new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom)
                                ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top)
                                });
                            }
                        }
                    }
                    //    g.DrawRectangle(new Pen(Color.Red), area);
                    //}
                    //b2.Save("Rectangles.bmp", ImageFormat.Bmp);
                    //b2.Dispose();
                }
                //rec.BubblesRecognition();
                //ShowProcessingForm();
                linsForm.btnOk.Enabled = false;

                rec.AmoutOfQuestions = amout_of_questions;
                BarCodeItems[amout_of_questionsIndex].Value = amout_of_questions.ToString();
                rec.areas = bubblesRegions.areas;// factAreas;
                //rec.UpdateGui();

                barCodesPrompt = "";
                maxCountRectangles = rec.AddMaxCountRectangles();
                rec.BubblesRecognition();
                //rec.BubblesRecognition(false);
                if (backgroundWorker.IsBusy)
                {
                    CancelBackgroundWorker();
                    //do
                    //{
                    //    Application.DoEvents();
                    //} while (backgroundWorker.IsBusy);
                    //System.Threading.Thread.Sleep(500);
                }
                backgroundWorker.RunWorkerAsync(new string[] { "BubblesRecognition2" });
                //Focus();
                ShowProcessingForm();

                //Bitmap b = (Bitmap)pictureBox1.Image.Clone();
                //using (Graphics g = Graphics.FromImage(b))
                //{
                //    foreach (Rectangle item in rec.factRectangle)
                //    {
                //        g.DrawRectangle(new Pen(Color.Red), item);
                //    }
                //}
                //b.Save("factRectangles.bmp", ImageFormat.Bmp);
                //b.Dispose();

                //area= Rectangle.Empty;
                linsForm.btnOk.Enabled = true;
                rpf = null;
                //Focus();
                //linsForm.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Send this sheet to developers for fixing problem."
                 , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                log.LogMessage(ex);
                string message = "Send log file to developers for fixing problem.";
                log.LogMessage(message);

                linsForm.btnOk.Enabled = true;
                rpf = null;
            }
        }
Ejemplo n.º 5
0
 //-------------------------------------------------------------------------
 public Dictionary<Bubble, CheckedBubble> AddMaxCountRectangles()
 {
     Dictionary<Bubble, CheckedBubble> maxCountRectangles = new Dictionary<Bubble, CheckedBubble>();
     //if (SheetIdentifier != "FLEX")
     //{
     int nextLine = 0;
     for (int k = 0; k < areas.Length; k++)
     {
         if (k > 0)
         {
             nextLine += linesPerArea[k];
         }
         for (int o = 0; o < linesPerArea[k]; o++)
         {
             if (o + 1 + nextLine > AmoutOfQuestions)
                 break;
             for (int m = 0; m < areas[k].subLinesAmount + 1; m++)
             {
                 if (o + 1 + nextLine > AmoutOfQuestions)
                     break;
                 for (int l = 0; l < areas[k].bubblesPerLine; l++)
                 {
                     if (o + 1 + nextLine > AmoutOfQuestions)
                         break;
                     Bubble b = new Bubble();
                     b.point = new Point(l, o + nextLine + IndexOfFirstQuestion);
                     b.subLine = m;
                     b.areaNumber = k;
                     //b.index = maxCountRectangles.Count;
                     maxCountRectangles.Add(b, new CheckedBubble());
                 }
             }
         }
     }
     //}
     //else
     //{
     //    for (int o = 0; o < linesPerArea[0]; o++)
     //    {
     //        for (int l = 0; l < bubbles_per_lineFLEX; l++)
     //        {
     //            Bubble b = new Bubble();
     //            b.point = new Point(l, o + IndexOfFirstQuestion);
     //            b.subLine = 0;
     //            b.areaNumber = 0;
     //            //b.index = maxCountRectangles.Count;
     //            maxCountRectangles.Add(b, new CheckedBubble());
     //        }
     //    }
     //}
     return maxCountRectangles;
 }
Ejemplo n.º 6
0
 //-------------------------------------------------------------------------
 private void GoodBubble(BubbleItem item, int k, int bubblesRegion
     , ref double factStepY, ref Bubble bubble, ref int prevGoodLineY, int factRectangle_k_Y)
 {
     //хороший пузырь
     if (bubble.Equals(new Bubble()) && item.Bubble.subLine == 0)
     {
         bubble = item.Bubble;
         prevGoodLineY = factRectangle_k_Y;
     }
     else
     {
         try
         {
             if (String.IsNullOrEmpty(areas[bubblesRegion].bubblesOrientation) || areas[bubblesRegion].bubblesOrientation == "horizontal")
             {//определение текущего значения lineFactStep
                 if (item.Bubble.subLine == 0 && bubble.areaNumber == item.Bubble.areaNumber && bubble.point.Y != item.Bubble.point.Y)
                 {
                     factStepY = (double)(factRectangle_k_Y - prevGoodLineY) / (item.Bubble.point.Y - bubble.point.Y);
                     bubble = item.Bubble;
                     prevGoodLineY = factRectangle_k_Y;
                 }
             }
             else
             {
                 if (bubble.areaNumber == item.Bubble.areaNumber && bubble.subLine == item.Bubble.subLine && item.Bubble.point.X != bubble.point.X)
                 {
                     factStepY = (double)(factRectangle_k_Y - prevGoodLineY) / (item.Bubble.point.X - bubble.point.X);
                     bubble = item.Bubble;
                     prevGoodLineY = factRectangle_k_Y; //item.Key.point.X;
                 }
             }
         }
         catch (Exception)
         { }
     }
 }
Ejemplo n.º 7
0
 //-------------------------------------------------------------------------
 //public string Base64Encode(string plainText)
 //{
 //    var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
 //    return System.Convert.ToBase64String(plainTextBytes);
 //}
 ////-------------------------------------------------------------------------
 //public string Base64Encode(byte[] bytes)
 //{
 //    return System.Convert.ToBase64String(bytes);
 //}
 //-------------------------------------------------------------------------
 //private string SetBubbleRect(string coordinanes, BubbleItem item)
 //{
 //    coordinanes += Environment.NewLine
 //                + "{ \"pos\": " + item.Bubble.point.X.ToString()
 //                + " \"x\": " + item.CheckedBubble.rectangle.X.ToString()
 //                + ", \"y\": " + item.CheckedBubble.rectangle.Y.ToString()
 //                + ", \"height\": " + item.CheckedBubble.rectangle.Height.ToString()
 //                + ", \"width\": " + item.CheckedBubble.rectangle.Width.ToString() + " },";
 //    return coordinanes;
 //}
 //-------------------------------------------------------------------------
 private void FillBubbleItemsToTotalOutput()
 {
     Bubble[] currentLineBubbles = new Bubble[0];
     Bubble bubble2 = BubbleItems[0].Bubble;
     int currentLine = bubble2.point.Y;
     totalOutput[indexAnswersPosition - 1] = new string[0];
     totalOutput[answersPosition - 1] = new string[0];
     int[] subStrSet = new int[areas[bubble2.areaNumber].subLinesAmount];
     recTools.AppendOutput(ref totalOutput, indexAnswersPosition, currentLine.ToString(), indexAnswersPosition, indexOfFirstBubble);
     for (int k = 0; k < BubbleItems.Count; k++)
     {
         var item = BubbleItems[k];
         bubble2 = item.Bubble;
         if (bubble2.point.Y == currentLine)//есть ли значения в строке
         {
             if (item.CheckedBubble.isChecked)
             {
                 Array.Resize(ref currentLineBubbles, currentLineBubbles.Length + 1);
                 currentLineBubbles[currentLineBubbles.Length - 1] = bubble2;
             }
             if (k < BubbleItems.Count - 1)
             {
                 continue;
             }
         }
         if (currentLineBubbles.Length == 0)//если в строке нет значений
         {
             if (subStrSet.Length > 0 && areas[bubble2.areaNumber].bubblesFormat == "multiple")
             {
                 for (int n = 0; n < subStrSet.Length; n++)
                 {
                     subStrSet[n] = n;
                     recTools.AppendOutput(ref totalOutput, answersPosition, "~", indexAnswersPosition, indexOfFirstBubble);
                 }
             }
             else
             {
                 recTools.AppendOutput(ref totalOutput, answersPosition, "", indexAnswersPosition, indexOfFirstBubble);
             }
         }
         else//записываем значения текущей строки в totalOutput
         {
             for (int j = 0; j < currentLineBubbles.Length; j++)
             {
                 Bubble b2 = currentLineBubbles[j];
                 AppendOutput(b2, j, ref subStrSet, currentLineBubbles.Length - 1);
             }
         }
         if (k < BubbleItems.Count - 1)
         {
             Array.Resize(ref currentLineBubbles, 0);
             currentLine = bubble2.point.Y;
             recTools.AppendOutput(ref totalOutput, indexAnswersPosition, currentLine.ToString(), indexAnswersPosition, indexOfFirstBubble);
             subStrSet = new int[areas[bubble2.areaNumber].subLinesAmount];
             k--;
         }
     }
 }
Ejemplo n.º 8
0
 //-------------------------------------------------------------------------
 private void AppendOutput(Bubble bubble, int positionInLine, ref int[] subStrSet, int lengthcurrentLineBubbles)
 {
     if ((areas[bubble.areaNumber].bubblesFormat == "single") || bubble.subLine == 0)
     {
         if (positionInLine > 0)
         {
             recTools.AppendOutput(ref totalOutput, answersPosition, "|", indexAnswersPosition, indexOfFirstBubble);
         }
     }
     else
     {
         if (subStrSet.Length > 0)
         {
             for (int n = 0; n < bubble.subLine; n++)
             {
                 if (subStrSet.Length > 0)
                 {
                     if (Array.IndexOf(subStrSet, bubble.subLine) < 0)
                     {
                         subStrSet[bubble.subLine - 1] = bubble.subLine;
                         recTools.AppendOutput(ref totalOutput, answersPosition, "~", indexAnswersPosition, indexOfFirstBubble);
                         break;
                     }
                     else
                     {
                         recTools.AppendOutput(ref totalOutput, answersPosition, "|", indexAnswersPosition, indexOfFirstBubble);
                         break;
                     }
                 }
             }
         }
     }
     if ((areas[bubble.areaNumber].bubblesFormat == "single"))
     {
         int index = indexOfFirstBubble;
         if (areas[bubble.areaNumber].indexOfFirstBubble != 0)
             index = areas[bubble.areaNumber].indexOfFirstBubble;
         recTools.AppendOutput(
               ref totalOutput
             , answersPosition
             , (bubble.point.X + (bubble.subLine * areas[bubble.areaNumber].bubblesPerLine)).ToString()
             , indexAnswersPosition
             , index//indexOfFirstBubble
             );
     }
     else
     {
         recTools.AppendOutput(ref totalOutput, answersPosition, bubble.point.X.ToString(), indexAnswersPosition, indexOfFirstBubble);
         if (bubble.subLine < subStrSet.Length && lengthcurrentLineBubbles == positionInLine)
         {
             for (int n = bubble.subLine; n < subStrSet.Length; n++)
             {
                 recTools.AppendOutput(ref totalOutput, answersPosition, "~", indexAnswersPosition, indexOfFirstBubble);
             }
         }
     }
 }
Ejemplo n.º 9
0
 public BubbleItem(Bubble bubble, CheckedBubble checkedBubble)
 {
     Bubble = bubble;
     CheckedBubble = checkedBubble;
 }