Ejemplo n.º 1
0
 //-------------------------------------------------------------------------
 public Regions Clone(Regions regions)
 {
     Regions reg = new Regions();
     foreach (var item in regions.regions)
     {
         //reg.regions.a
     }
     return reg;
 }
Ejemplo n.º 2
0
        private void ProcessingRegions(ref Regions regions, ref Regions.Area[] areas, ref int regionOutputPosition, ref string barCodesPrompt
    , ref int x1, ref int y1, ref int x2, ref int y2, ref decimal kx, ref decimal ky, ref Rectangle curRect, ref Rectangle etRect, ref int deltaY, Bitmap bmp
    , ref string barcode, ref double filterType, ref object[] totalOutput
    , ref int indexOfFirstBubble, ref int numberOfBubblesRegion, ref Rectangle[] bubblesRegions, ref Rectangle[] bubblesOfRegion, ref int[] bubblesSubLinesCount
    , ref int[] bubblesSubLinesStep, ref int[] lineHeight, ref int answersPosition, ref int indexAnswersPosition, ref string[] bubbleLines)
        {
            for (int num = 0; num < regions.regions.Length; num++)
            {
                #region обработкa регионов processing regions
                string barcodeMem = "";
                string type = regions.regions[num].type;
                bool? active = regions.regions[num].active;
                string name = regions.regions[num].name;
                if (active != false && type != "marker" && name != "sheetIdentifier")
                {
                    areas = regions.regions[num].areas;
                    Regions.Area arr = areas[0];
                    Rectangle rArr = new Rectangle(arr.left, arr.top, arr.width, arr.height);
                    percent_confident_text_region = regions.regions[num].percent_confident_text_region;
                    regionOutputPosition = regions.regions[num].outputPosition;
                    int rotateParameter = regions.regions[num].rotate;
                    if (!barCodesPrompt.StartsWith("Markers"))
                    {
                        x1 = curRect.X + (int)Math.Round((decimal)(arr.left - etRect.X) * kx);
                        y1 = curRect.Y + (int)Math.Round((decimal)(arr.top - etRect.Y) * ky);
                        x2 = curRect.X + (int)Math.Round((decimal)(rArr.Right - etRect.X) * kx);
                        y2 = curRect.Y + (int)Math.Round((decimal)(rArr.Bottom - etRect.Y) * ky);
                        if (name == "lastBanner")
                        {
                            RecognitionTools.LastBannerFind(ref deltaY, bmp, x1, y1, x2, y2);
                        }
                    }
                    else { }
                    if (type.StartsWith("barCode"))
                    {
                        Rectangle rn = new Rectangle(x1, y1, x2 - x1, y2 - y1);
                        Array.Resize(ref barCodesRectangle, barCodesRectangle.Length + 1);
                        barCodesRectangle[barCodesRectangle.Length - 1] = rn;// rArr;
                        if (!barCodesPrompt.StartsWith("Markers"))
                        {
                            barCodesPrompt = "";
                            bool notConfident = false;
                            barcode = RecognitionTools.GetBarCode("", bmp, ref notConfident, ref barCodesPrompt, ref filterType, ref barcodeMem
                                , x1, x2, y1, y2, kx, ky, curRect, etRect, deltaY, regions.regions[num], false//dualControl
                                , percent_confident_text_region, defaults.PercentConfidentText, defaults.FontName, barCodesRectangle);
                        }
                        else
                        {
                            barcode = "";
                            barcodeMem = "";
                        }

                        NotifyUpdated(NotifyKey.FindedBarcodeControll, new string[] { name, arr.type, barcode, barcodeMem });

                        RecognitionTools.SetOutputValues(ref headers, ref headersValues, ref totalOutput, ref allBarCodeNames
                             , ref allBarCodeValues, name, barcode, regionOutputPosition);
                        try
                        {
                            switch (name)
                            {
                                case "amout_of_questions":
                                    amoutOfQuestions = Convert.ToInt32(barcode);
                                    break;
                                case "index_of_first_question":
                                    indexOfFirstQuestion = Convert.ToInt32(barcode);
                                    break;
                            }
                        }
                        catch (Exception)
                        { }
                    }//End if (type.StartsWith("barCode"))
                    else
                        if (type == "bubblesRegions")
                        {
                            indexOfFirstBubble = regions.regions[num].indexOfFirstBubble;
                            numberOfBubblesRegion = num;
                            RecognitionTools.SetSettings(ref bubblesRegions, ref bubblesOfRegion, ref bubblesSubLinesCount, ref bubblesSubLinesStep, ref bubblesPerLine
                                , ref lineHeight, ref linesPerArea, ref answersPosition, ref indexAnswersPosition, ref totalOutput, ref  bubbleLines, regions.regions[num]
                                , x1, x2, y1, y2, kx, ky, curRect, etRect, deltaY);
                        }
                }
                #endregion
            }//конец обработки регионов
        }
Ejemplo n.º 3
0
        public void Searchmarkers(string lastSheetIdentifier)
        {
            this.lastSheetIdentifier = lastSheetIdentifier;
            regions = RecognitionTools.GetSheetIdentifier(ref Image, ref kx, ref ky, ref sheetIdentifier, ref lastSheetIdentifier
                , regionsExt, ref filterType, ref barCodesPrompt, sheetIdentifiers, Image, ref regionOutputPosition
                , ref markerLTet, ref markerRTet, ref markerLBet, ref markerRBet, out curRect, out etRect, deltaY
                , defaults.DualControl, percent_confident_text_region, defaults.PercentConfidentText
                , RecognitionTools.limSymbols, defaults.FontName);
            if (barCodesPrompt != "" || regions == null)
            {
                NotifyUpdated(NotifyKey.ChangedBarCodesPrompt);
            }
            lastSheetIdentifier = sheetIdentifier;
            RecognitionTools.SetOutputValues(ref headers, ref headersValues, ref totalOutput, ref allBarCodeNames
                , ref allBarCodeValues, "sheetIdentifier", sheetIdentifier, regionOutputPosition);

            maxCountRectangles.Clear();

            if (lastSheetIdentifier != sheetIdentifier)
            {
                // regions = WaitingForUserResponse(ref barcode, sheetIdentifiers, ref  sheetIdentifier, regionsExt);
            }
        }
Ejemplo n.º 4
0
        //-------------------------------------------------------------------------
        public void ProcessingRegions(string qrCodeText = "")
        {
            string[] chars = new string[0];//, vals = new string[0]
            //string district_id = "D", test_id = "T", student_uid = "S", amout_of_questions = "Q", index_of_first_question = "F";
            string[] qrCodeFormatItemsId = new string[0];
            //string[] qrCodeFormatItems = new string[0];
            MatchCollection qrCodeFormatItemsVal = null;
            string barCodesPromptMem = barCodesPrompt;
            questionNumbers = new int[0];
            //QrCode = qrCodeText;
            if (qrCodeText != "")
            {
                var outputFileNameFormat = GetOutputFileNameFormat();
                chars = Regex.Split(qrCodeText, "\\d+");
                QrCodeValues = Regex.Split(qrCodeText.Remove(0, 1), "\\D+");
                for (int num = 0; num < regions.regions.Length; num++)
                {
                    Region regs = (Region)regions.regions[num];
                    bool? active = regs.active;
                    if (active == false)
                        continue;
                    if (regs.name != "qr_code")
                        continue;
                    qrCodeFormatItemsId = Regex.Split(regs.QRCodeFormat, "{\\w+}");
                    qrCodeFormatItemsVal = Regex.Matches(regs.QRCodeFormat, "{\\w+}");

                    QrCodeHeaders = new string[qrCodeFormatItemsVal.Count];
                    for (int i = 0; i < QrCodeHeaders.Length; i++)
                    {
                        QrCodeHeaders[i] = qrCodeFormatItemsVal[i].Value;
                    }
                }
            }
            if (QrCodeHeaders != null)
            {
                int index = Array.IndexOf(QrCodeHeaders, "{student_id}");
                if (index > -1)
                    student_id = QrCodeValues[index];
            }
            notConfident = false;
            Rectangle lastSymbolRectangle = Rectangle.Empty;
            //bool notRet = false;
            for (int num = 0; num < regions.regions.Length; num++)
            {
                if (cancellationToken.IsCancellationRequested)
                    return;
                string barcodeMem = "";
                string type = regions.regions[num].type;
                bool? active = regions.regions[num].active;
                string name = regions.regions[num].name;
                if (active != false && type != "marker" && name != "sheetIdentifier")
                {
                    areas = regions.regions[num].areas;
                    RegionsArea arr = areas[0];
                    Rectangle rArr = new Rectangle(arr.left, arr.top, arr.width, arr.height);
                    percent_confident_text_region = regions.regions[num].percent_confident_text_region;
                    regionOutputPosition = regions.regions[num].outputPosition;
                    int rotateParameter = regions.regions[num].rotate;
                    // if (!barCodesPrompt.StartsWith("Markers"))
                    //{

                    int deltaX = 0;// (int)((etRect.X - curRect.X) / kx);

                    x1 = curRect.X + deltaX + (int)Math.Round((decimal)(rArr.Left - etRect.X) * kx);
                    y1 = curRect.Y + (int)Math.Round((decimal)(rArr.Top - etRect.Y) * ky);
                    x2 = curRect.X + deltaX + (int)Math.Round((decimal)(rArr.Right - etRect.X) * kx);
                    y2 = curRect.Y + (int)Math.Round((decimal)(rArr.Bottom - etRect.Y) * ky);
                    if (name == "lastBanner")// && SheetIdentifier != "100POINT"
                    {
                        if (barCodesPromptMem.StartsWith("M") || barCodesPromptMem.StartsWith("A"))
                        {
                            barCodesPrompt = "Aligment error 2";
                            deltaY = 0;
                            continue;
                        }
                        deltaY = recTools.LastBannerFind(Bitmap, x1, y1, x2, y2, out lastBannerBottom);//, filterType
                        if (Math.Abs(deltaY) > ((y2 - y1) / 2) + 1)
                        {
                            // notConfident = true;
                            barCodesPrompt = "Aligment error 3";
                            deltaY = 0;
                        }
                    }
                    //}
                    // else { }//Когда заполняются дефолтные значения при Markers Not Found
                    if (type.StartsWith("barCode"))
                    {
                        if (name == "sheetIdentifier")
                            continue;

                        if (name == "question_number_1")
                            lastSymbolRectangle = Rectangle.Empty;
                        if (name.StartsWith("question_number"))
                            if (AmoutOfQuestions > 0 && questionNumbers.Length >= AmoutOfQuestions)
                                continue;
                        Rectangle rn = new Rectangle(x1, y1, x2 - x1, y2 - y1);
                        //  if (!barCodesPrompt.StartsWith("Markers"))
                        //{
                        //barCodesPrompt = "";
                        int id = 0;
                        //oldRec:
                        if (qrCodeText == "" || id == -1 || QrCodeHeaders == null)
                        {
                            if (rArr == Rectangle.Empty)
                                continue;
                            GetBarCode(ref lastSymbolRectangle, num, ref barcodeMem, name, ref rn);
                            if (!Auto && SheetIdentifier == "FLEX")
                            {
                                if (recTools.result1 != null && recTools.result1.ResultPoints[0].X > recTools.result1.ResultPoints[1].X)
                                {//перевёрнут на 180
                                    BarCodesPrompt = "Rotate180";
                                    return;
                                }
                            }
                            if (name == "question_number_1")// && barCodesPrompt != ""
                            {
                                try
                                {
                                    IndexOfFirstQuestion = Convert.ToInt32(barcodeMem);
                                }
                                catch (Exception)
                                {
                                }
                            }
                            if (Auto && barCodesPrompt != "")//вставить IndexOfFirstQuestion и index_of_first_question для FLEX
                                return;//if (name == "question_number_1")
                        }
                        else
                        {
                            if (defaults.useStudentId)
                            {
                                id = Array.IndexOf(QrCodeHeaders, "{" + name + "}");
                                if (id < 0)
                                    continue;
                                barcode = QrCodeValues[id];
                                if (barcode == "0")//(name == "student_uid" || name == "student_id") &&
                                {
                                    barcode = "";
                                    barcodeMem = barcode;
                                    barCodesPrompt = "Error in " + name;
                                    if (Auto)
                                        return;
                                }
                                barcodeMem = barcode;
                            }
                            else
                            {
                                if (name == "student_id")
                                    continue;
                                id = Array.IndexOf(QrCodeHeaders, "{" + name + "}");
                                if (id < 0)
                                {
                                    if (rArr == Rectangle.Empty)
                                        continue;
                                    GetBarCode(ref lastSymbolRectangle, num, ref barcodeMem, name, ref rn);
                                    if (Auto && barCodesPrompt != "")
                                        return;
                                }
                                else
                                {
                                    barcode = QrCodeValues[id];
                                    barcodeMem = barcode;
                                }
                            }
                        }
                        //var bItem = new BarCodeItem(name, arr.type, barcode, barcodeMem, rn);
                        var bItem = new BarCodeItem(name, areas[1].type, barcode, barcodeMem, rn);
                        recTools.SetOutputValues(ref headers, ref headersValues, ref totalOutput, ref allBarCodeNames
                             , ref allBarCodeValues, bItem.Name, bItem.Value, regionOutputPosition);
                        try
                        {
                            if (name.StartsWith("question_number"))
                            {
                                Array.Resize(ref questionNumbers, questionNumbers.Length + 1);
                                questionNumbers[questionNumbers.Length - 1] = Convert.ToInt32(bItem.Value);
                            }
                            switch (name)
                            {
                                case "amout_of_questions":
                                    AmoutOfQuestions = Convert.ToInt32(bItem.Value);
                                    break;
                                case "index_of_first_question":
                                case "question_number_1":
                                    IndexOfFirstQuestion = Convert.ToInt32(bItem.Value);
                                    //notRet = true;
                                    break;
                                case "bubbles_per_line":
                                    //singleArea = true;
                                    //areas[0].bubblesPerLine = Convert.ToInt32(bItem.Value);
                                    //if (bubblesPerLine.Length == 0)
                                    //    bubblesPerLine = new int[areas.Length];
                                    //bubblesPerLine[0] = areas[0].bubblesPerLine;
                                    try
                                    {
                                        bubbles_per_lineFLEX = Convert.ToInt32(bItem.Value);
                                        switch (bubbles_per_lineFLEX)
                                        {
                                            case 5:
                                            case 6:
                                                foreach (var item in regionsListFLEX)
                                                {
                                                    if (item.regions[item.regions.Length - 1].areas[0].bubblesPerLine == bubbles_per_lineFLEX)
                                                    {
                                                        regions = item;
                                                        break;
                                                    }
                                                }
                                                break;
                                            default:
                                                bItem.Value = "";
                                                break;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        bItem.Value = "";
                                    }
                                    //areas[0].bubblesPerLine;
                                    break;
                            }
                        }
                        catch (Exception)
                        {
                            if (name == "index_of_first_question" || name == "question_number_1")
                            {
                                bItem.Value = IndexOfFirstQuestion.ToString();
                            }
                        }
                        //FindOrAddAndSetValueBarcode(bItem.Name, bItem.Value);
                        BarCodeItems.Add(bItem);
                        NotifyUpdated(FindedBarcodeControllEvent, null, new BarcodeEventArgs(bItem));
                    }
                    else
                        if (type == "bubblesRegions")
                    {
                        //indexOfFirstBubble = regions.regions[num].indexOfFirstBubble;
                        numberOfBubblesRegion = num;
                        //if (SheetIdentifier == "FLEX")
                        //{
                        //    areas[0].bubblesPerLine = bubbles_per_lineFLEX;
                        //}
                        recTools.SetSettings(ref bubblesRegions, ref bubblesOfRegion, ref bubblesSubLinesCount
                            , ref bubblesSubLinesStep, ref bubblesPerLine, ref lineHeight, ref linesPerArea
                            , out answersPosition, out indexAnswersPosition, ref totalOutput
                            , ref bubbleLines, regions.regions[num], kx, ky, curRect, etRect);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        //-------------------------------------------------------------------------
        private void Searchmarkers(bool alignmentOnly, ref string qrCodeText
            , bool isRotate = false, bool isCut = false, bool ShetIdManualySet = false)
        {
            BubbleItems.Clear();
            if (alignmentOnly)
            {
                var tempbarCodesPrompt = barCodesPrompt;
                recTools.GetSheetIdentifier(ref bitmap, ref kx, ref ky, ref sheetIdentifier, ref lastSheetIdentifier
                    , regionsList, ref filterType, ref barCodesPrompt, out curRect, out etRect, deltaY
                    , defaults, ref sheetIdentifierBarCodeRectangle, alignmentOnly, ref qrCodeText, isRotate, isCut, ShetIdManualySet);
                if (barCodesPrompt != "" && tempbarCodesPrompt != "" && tempbarCodesPrompt != barCodesPrompt)
                    barCodesPrompt = tempbarCodesPrompt;
                sheetIdentifier = regions.SheetIdentifierName;
                lastSheetIdentifier = sheetIdentifier;
            }
            else
            {
                regions = recTools.GetSheetIdentifier(ref bitmap, ref kx, ref ky, ref sheetIdentifier, ref lastSheetIdentifier
                , regionsList, ref filterType, ref barCodesPrompt, out curRect, out etRect, deltaY
                , defaults, ref sheetIdentifierBarCodeRectangle, alignmentOnly, ref qrCodeText, isRotate, isCut, ShetIdManualySet);

                QrCode = qrCodeText;
                if (cancellationToken.IsCancellationRequested)
                    return;

                if (Auto && (barCodesPrompt != "" || regions == null) || !Auto && string.IsNullOrEmpty(QrCode) && (barCodesPrompt != "" || regions == null))//!!!
                {
                    filterType = 0;
                    //if (Auto || string.IsNullOrEmpty(QrCode))
                    //{
                    //    if (!Auto && barCodesPrompt != "Markers not found ")
                    //    {
                    //        return;
                    //    }

                    //    SheetIdentifierFixProblem();
                    //    return;
                    //}

                    //if (!string.IsNullOrEmpty(QrCode) && !Auto && barCodesPrompt == "Aligment error")
                    //{
                    //    QrCode = "";
                    //    //regions = null;
                    //}

                    //string pr = barCodesPrompt;
                    SheetIdentifierFixProblem();
                    lastSheetIdentifier = sheetIdentifier;
                    //barCodesPrompt = pr;
                    return;
                }
            }
            if (filterType > 0 && filterType < 10)
            {
                allFilterType += filterType;
                allFilterCount++;
            }
            //lastSheetIdentifier = sheetIdentifier;

            Status = RecognizeAction.SearchMarkersFinished;
        }
Ejemplo n.º 6
0
 //-------------------------------------------------------------------------
 public void SelectedSheetIdentifier(string BoxSheetSelectedValue, ref string qrCodeText, bool isRotate = false
     , bool isCut = false, bool ShetIdManualySet = false)
 {
     Status = RecognizeAction.InProcess;
     string barcode = BoxSheetSelectedValue;
     regions = recTools.GetRegions(barcode, regionsList);
     if (regions == null)
     {
         SheetIdentifierFixProblem();
         return;
     }
     lastSheetIdentifier = BoxSheetSelectedValue;
     sheetIdentifier = lastSheetIdentifier;
     Searchmarkers(true, ref qrCodeText, isRotate, isCut, ShetIdManualySet);
 }