/// <summary>
        ///   <p>This is called when a horizontal scan finds a possible alignment pattern. It will
        /// cross check with a vertical scan, and if successful, will, ah, cross-cross-check
        /// with another horizontal scan. This is needed primarily to locate the real horizontal
        /// center of the pattern in cases of extreme skew.
        /// And then we cross-cross-cross check with another diagonal scan.</p>
        /// If that succeeds the finder pattern location is added to a list that tracks
        /// the number of times each location has been nearly-matched as a finder pattern.
        /// Each additional find is more evidence that the location is in fact a finder
        /// pattern center
        /// </summary>
        /// <param name="stateCount">reading state module counts from horizontal scan</param>
        /// <param name="i">row where finder pattern may be found</param>
        /// <param name="j">end of possible finder pattern in row</param>
        /// <param name="pureBarcode">true if in "pure barcode" mode</param>
        /// <returns>
        /// true if a finder pattern candidate was found this time
        /// </returns>
        bool HandlePossibleCenter(int[] stateCount, int i, int j)
        {
            int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] +
                                  stateCount[4];
            float?centerJ = CenterFromEnd(stateCount, j);

            if (centerJ == null)
            {
                return(false);
            }
            float?centerI = CrossCheckVertical(i, (int)centerJ.Value, stateCount[2], stateCountTotal);

            if (centerI != null)
            {
                // Re-cross check
                centerJ = CrossCheckHorizontal((int)centerJ.Value, (int)centerI.Value, stateCount[2], stateCountTotal);
                if (centerJ != null)
                {
                    float estimatedModuleSize = stateCountTotal / 7.0f;
                    bool  found = false;
                    for (int index = 0; index < PossibleCenters.Count; index++)
                    {
                        var center = PossibleCenters[index];
                        // Look for about the same center and module size:
                        if (center.AboutEquals(estimatedModuleSize, centerI.Value, centerJ.Value))
                        {
                            PossibleCenters.RemoveAt(index);
                            PossibleCenters.Insert(index, center.CombineEstimate(centerI.Value, centerJ.Value, estimatedModuleSize));

                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        var point = new FinderPattern(centerJ.Value, centerI.Value, estimatedModuleSize);

                        PossibleCenters.Add(point);
                    }
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary> <para>
        /// <p>This is called when a horizontal scan finds a possible alignment pattern. It will
        /// cross check with a vertical scan, and if successful, will, ah, cross-cross-check
        /// with another horizontal scan. This is needed primarily to locate the real horizontal
        /// center of the pattern in cases of extreme skew.</p>
        /// </para>
        /// <para>
        /// <p>If that succeeds the finder pattern location is added to a list that tracks
        /// the number of times each location has been nearly-matched as a finder pattern.
        /// Each additional find is more evidence that the location is in fact a finder
        /// pattern center</p>
        /// </para>
        ///
        /// </summary>
        /// <param name="stateCount">reading state module counts from horizontal scan
        /// </param>
        /// <param name="i">row where finder pattern may be found
        /// </param>
        /// <param name="j">end of possible finder pattern in row
        /// </param>
        /// <returns> true if a finder pattern candidate was found this time
        /// </returns>
        private bool HandlePossibleCenter(int[] stateCount, int i, int j)
        {
            int   stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
            float centerJ         = CenterFromEnd(stateCount, j);
            //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
            float centerI = CrossCheckVertical(i, (int)centerJ, stateCount[2], stateCountTotal);

            if (!float.IsNaN(centerI))
            {
                // Re-cross check
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                centerJ = CrossCheckHorizontal((int)centerJ, (int)centerI, stateCount[2], stateCountTotal);
                if (!float.IsNaN(centerJ))
                {
                    //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                    float estimatedModuleSize = stateCountTotal / 7.0f;
                    bool  found = false;
                    int   max   = PossibleCenters.Count;
                    for (int index = 0; index < max; index++)
                    {
                        FinderPattern center = (FinderPattern)PossibleCenters[index];
                        // Look for about the same center and module size:
                        if (center.AboutEquals(estimatedModuleSize, centerI, centerJ))
                        {
                            center.IncrementCount();
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ResultPoint point = new FinderPattern(centerJ, centerI, estimatedModuleSize);
                        PossibleCenters.Add(point);
                        resultPointCallback?.FoundPossibleResultPoint(point);
                    }
                    return(true);
                }
            }
            return(false);
        }