예제 #1
0
        public void Analyze(float sure, float doubt, ref PageStatus status)
        {
            // If the image has been analyzed earlier it has to be reloaded
            if (ProcessedImage)
            {
                LoadImage();
                status.Reset();
            }

            // Resizing can only happen as part of RotateAndCrop
            int resize = (int)((Math.Max(Program.Test.Paper.Dimensions.Pixel.Width, Program.Test.Paper.Dimensions.Pixel.Height) * 150) / Math.Max(ScannedImage.GetLength(0), ScannedImage.GetLength(1)));

            // Half searchsize must be bigger than calibrationpoint, but not too big (border / other points) => Difficult, depends on how it is scanned (rotation)
            // After resize the picture is at a standard size ==> fixed searchsize
            int searchSize = 40;

            // Midpoints of itemalts
            ItemAltsLocation = Calibration.RotateAndCrop(Program.Test, ref ScannedImage, ref BarCodeBytes, resize, searchSize);

            if (ItemAltsLocation[0, 0].X != 0 && ItemAltsLocation[0, 0].Y != 0)
            {
                ItemAltsCheckedState = new ItemCheckedState[Program.Test.Paper.Blocks.X, Program.Test.Paper.Blocks.Y];
                ObservedBlockSize    = new SizeF(
                    (float)ScannedImage.GetLength(0) / Program.Test.Paper.Blocks.X,
                    (float)ScannedImage.GetLength(1) / Program.Test.Paper.Blocks.Y);
                ColorDistribution = new ColorDistribution();

                if (!BarError(BarCodeBytes))
                {
                    // BarCodeBytes[0] is page number (0 based) ==> has to be smaller than count
                    // Only BarMatch for first three bytes (first is page number, second and third are hash, rest doesn't matter)
                    if (BarCodeBytes[0] < Program.Test.Pages.Count && BarMatch(BarCodeBytes, Program.Test.Pages[BarCodeBytes[0]].Hash(), 3))
                    {
                        CalculateInitialItemAltsCheckedState(BarCodeBytes[0], sure, doubt); // Other way to reach this is after manually setting page number
                    }
                    else
                    {
                        status.PageNumberOrHashError = true; // Fail: invalid page number according to barcode or page hash not correct
                    }
                }
                else
                {
                    status.BarCodeError = true; // Fail: could not read barcode, or not correctly (parity check fail)
                }
            }
            else
            {
                status.CalibrationError = true; // Fail: probably couldn't calibrate
            }
            ProcessedImage  = true;
            status.Analyzed = true;
        }