Esempio n. 1
0
        // boxfunc3.c (634, 1)
        // boxaaDisplay(pixs, baa, linewba, linewb, colorba, colorb, w, h) as Pix
        // boxaaDisplay(PIX *, BOXAA *, l_int32, l_int32, l_uint32, l_uint32, l_int32, l_int32) as PIX *
        ///  <summary>
        /// (1) If %pixs exists, this renders the boxes over an 8 bpp version
        /// of it.  Otherwise, it renders the boxes over an empty image
        /// with a white background.<para/>
        ///
        /// (2) If %pixs exists, the dimensions of %pixd are the same,
        /// and input values of %w and %h are ignored.
        /// If %pixs is NULL, the dimensions of %pixd are determined by
        /// - %w and %h if both are  is greater  0, or
        /// - the minimum size required using all boxes in %baa.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/boxaaDisplay/*"/>
        ///  <param name="pixs">[in][optional] - 1 bpp</param>
        ///  <param name="baa">[in] - boxaa, typically from a 2d sort</param>
        ///  <param name="linewba">[in] - line width to display outline of each boxa</param>
        ///  <param name="linewb">[in] - line width to display outline of each box</param>
        ///  <param name="colorba">[in] - color to display boxa</param>
        ///  <param name="colorb">[in] - color to display box</param>
        ///  <param name="w">[in] - width of outupt pix use 0 if determined by %pixs or %baa</param>
        ///  <param name="h">[in] - height of outupt pix use 0 if determined by %pixs or %baa</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static Pix boxaaDisplay(
            Pix pixs,
            Boxaa baa,
            int linewba,
            int linewb,
            uint colorba,
            uint colorb,
            int w,
            int h)
        {
            if (baa == null)
            {
                throw new ArgumentNullException("baa cannot be Nothing");
            }

            if ((new List <int> {
                1
            }).Contains((int)pixs.d) == false)
            {
                throw new ArgumentException("1 bpp");
            }
            IntPtr pixsPtr = IntPtr.Zero;   if (pixs != null)
            {
                pixsPtr = pixs.Pointer;
            }
            IntPtr _Result = Natives.boxaaDisplay(pixsPtr, baa.Pointer, linewba, linewb, colorba, colorb, w, h);

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Pix(_Result));
        }
Esempio n. 2
0
        // boxfunc3.c (716, 1)
        // pixaDisplayBoxaa(pixas, baa, colorflag, width) as Pixa
        // pixaDisplayBoxaa(PIXA *, BOXAA *, l_int32, l_int32) as PIXA *
        ///  <summary>
        /// (1) All pix in %pixas that are not rgb are converted to rgb.<para/>
        ///
        /// (2) Each boxa in %baa contains boxes that will be drawn on
        /// the corresponding pix in %pixas.<para/>
        ///
        /// (3) The color of the boxes drawn on each pix are selected with
        /// %colorflag:
        /// For red, green or blue: use L_DRAW_RED, etc.
        /// For sequential r, g, b: use L_DRAW_RGB
        /// For random colors: use L_DRAW_RANDOM
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/pixaDisplayBoxaa/*"/>
        ///  <param name="pixas">[in] - any depth, can be cmapped</param>
        ///  <param name="baa">[in] - boxes to draw on input pixa</param>
        ///  <param name="colorflag">[in] - (L_DRAW_RED, L_DRAW_GREEN, etc)</param>
        ///  <param name="width">[in] - thickness of lines</param>
        ///   <returns>pixa with box outlines drawn on each pix, or NULL on error</returns>
        public static Pixa pixaDisplayBoxaa(
            Pixa pixas,
            Boxaa baa,
            int colorflag,
            int width)
        {
            if (pixas == null)
            {
                throw new ArgumentNullException("pixas cannot be Nothing");
            }

            if (baa == null)
            {
                throw new ArgumentNullException("baa cannot be Nothing");
            }

            IntPtr _Result = Natives.pixaDisplayBoxaa(pixas.Pointer, baa.Pointer, colorflag, width);

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Pixa(_Result));
        }
Esempio n. 3
0
        // boxfunc2.c (1478, 1)
        // boxaaFlattenToBoxa(baa, pnaindex, copyflag) as Boxa
        // boxaaFlattenToBoxa(BOXAA *, NUMA **, l_int32) as BOXA *
        ///  <summary>
        /// (1) This 'flattens' the baa to a boxa, taking the boxes in
        /// order in the first boxa, then the second, etc.<para/>
        ///
        /// (2) If a boxa is empty, we generate an invalid, placeholder box
        /// of zero size.  This is useful when converting from a baa
        /// where each boxa has either 0 or 1 boxes, and it is necessary
        /// to maintain a 1:1 correspondence between the initial
        /// boxa array and the resulting box array.<para/>
        ///
        /// (3) If [and]naindex is defined, we generate a Numa that gives, for
        /// each box in the baa, the index of the boxa to which it belongs.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/boxaaFlattenToBoxa/*"/>
        ///  <param name="baa">[in] - </param>
        ///  <param name="pnaindex">[out][optional] - the boxa index in the baa</param>
        ///  <param name="copyflag">[in] - L_COPY or L_CLONE</param>
        ///   <returns>boxa, or NULL on error</returns>
        public static Boxa boxaaFlattenToBoxa(
            Boxaa baa,
            out Numa pnaindex,
            int copyflag)
        {
            if (baa == null)
            {
                throw new ArgumentNullException("baa cannot be Nothing");
            }

            IntPtr pnaindexPtr = IntPtr.Zero;
            IntPtr _Result     = Natives.boxaaFlattenToBoxa(baa.Pointer, out pnaindexPtr, copyflag);

            if (pnaindexPtr == IntPtr.Zero)
            {
                pnaindex = null;
            }
            else
            {
                pnaindex = new Numa(pnaindexPtr);
            };

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Boxa(_Result));
        }
Esempio n. 4
0
        // boxfunc2.c (1398, 1)
        // boxaaGetExtent(baa, pw, ph, pbox, pboxa) as int
        // boxaaGetExtent(BOXAA *, l_int32 *, l_int32 *, BOX **, BOXA **) as l_ok
        ///  <summary>
        /// (1) The returned w and h are the minimum size image
        /// that would contain all boxes untranslated.<para/>
        ///
        /// (2) Each box in the returned boxa is the minimum box required to
        /// hold all the boxes in the respective boxa of baa.<para/>
        ///
        /// (3) If there are no valid boxes in a boxa, the box corresponding
        /// to its extent has all fields set to 0 (an invalid box).
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/boxaaGetExtent/*"/>
        ///  <param name="baa">[in] - </param>
        ///  <param name="pw">[out][optional] - width</param>
        ///  <param name="ph">[out][optional] - height</param>
        ///  <param name="pbox">[out][optional] - minimum box containing all boxa in boxaa</param>
        ///  <param name="pboxa">[out][optional] - boxa containing all boxes in each boxa in the boxaa</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int boxaaGetExtent(
            Boxaa baa,
            out int pw,
            out int ph,
            out Box pbox,
            out Boxa pboxa)
        {
            if (baa == null)
            {
                throw new ArgumentNullException("baa cannot be Nothing");
            }

            IntPtr pboxPtr  = IntPtr.Zero;
            IntPtr pboxaPtr = IntPtr.Zero;
            int    _Result  = Natives.boxaaGetExtent(baa.Pointer, out pw, out ph, out pboxPtr, out pboxaPtr);

            if (pboxPtr == IntPtr.Zero)
            {
                pbox = null;
            }
            else
            {
                pbox = new Box(pboxPtr);
            };
            if (pboxaPtr == IntPtr.Zero)
            {
                pboxa = null;
            }
            else
            {
                pboxa = new Boxa(pboxaPtr);
            };

            return(_Result);
        }
Esempio n. 5
0
        // boxfunc2.c (1656, 1)
        // boxaaTranspose(baas) as Boxaa
        // boxaaTranspose(BOXAA *) as BOXAA *
        ///  <summary>
        /// (1) If you think of a boxaa as a 2D array of boxes that is accessed
        /// row major, then each row is represented by one of the boxa.
        /// This function creates a new boxaa related to the input boxaa
        /// as a column major traversal of the input boxaa.<para/>
        ///
        /// (2) For example, if %baas has 2 boxa, each with 10 boxes, then
        /// %baad will have 10 boxa, each with 2 boxes.<para/>
        ///
        /// (3) Require for this transpose operation that each boxa in
        /// %baas has the same number of boxes.  This operation is useful
        /// when the i-th boxes in each boxa are meaningfully related.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/boxaaTranspose/*"/>
        ///  <param name="baas">[in] - </param>
        ///   <returns>baad, or NULL on error</returns>
        public static Boxaa boxaaTranspose(
            Boxaa baas)
        {
            if (baas == null)
            {
                throw new ArgumentNullException("baas cannot be Nothing");
            }

            IntPtr _Result = Natives.boxaaTranspose(baas.Pointer);

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Boxaa(_Result));
        }
Esempio n. 6
0
        // recogident.c (1761, 1)
        // showExtractNumbers(pixs, sa, baa, naa, ppixdb) as Pixa
        // showExtractNumbers(PIX *, SARRAY *, BOXAA *, NUMAA *, PIX **) as PIXA *
        ///  <summary>
        /// (1) This is a debugging routine on digit identification e.g.:
        /// recogIdentifyMultiple(recog, pixs, 0, 1, [and]boxa, NULL, NULL, 0)
        /// sa = recogExtractNumbers(recog, boxa, 0.8, -1, [and]baa, [and]naa)
        /// pixa = showExtractNumbers(pixs, sa, baa, naa, NULL)
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/showExtractNumbers/*"/>
        ///  <param name="pixs">[in] - input 1 bpp image</param>
        ///  <param name="sa">[in] - recognized text strings</param>
        ///  <param name="baa">[in] - boxa array for location of characters in each string</param>
        ///  <param name="naa">[in] - numa array for scores of characters in each string</param>
        ///  <param name="ppixdb">[out][optional] - input pixs with identified chars outlined</param>
        ///   <returns>pixa   of identified strings with text and scores, or NULL on error</returns>
        public static Pixa showExtractNumbers(
            Pix pixs,
            Sarray sa,
            Boxaa baa,
            Numaa naa,
            out Pix ppixdb)
        {
            if (pixs == null)
            {
                throw new ArgumentNullException("pixs cannot be Nothing");
            }

            if (sa == null)
            {
                throw new ArgumentNullException("sa cannot be Nothing");
            }

            if (baa == null)
            {
                throw new ArgumentNullException("baa cannot be Nothing");
            }

            if (naa == null)
            {
                throw new ArgumentNullException("naa cannot be Nothing");
            }

            IntPtr ppixdbPtr = IntPtr.Zero;
            IntPtr _Result   = Natives.showExtractNumbers(pixs.Pointer, sa.Pointer, baa.Pointer, naa.Pointer, out ppixdbPtr);

            if (ppixdbPtr == IntPtr.Zero)
            {
                ppixdb = null;
            }
            else
            {
                ppixdb = new Pix(ppixdbPtr);
            };

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Pixa(_Result));
        }
Esempio n. 7
0
        // recogident.c (1628, 1)
        // recogExtractNumbers(recog, boxas, scorethresh, spacethresh, pbaa, pnaa) as Sarray
        // recogExtractNumbers(L_RECOG *, BOXA *, l_float32, l_int32, BOXAA **, NUMAA **) as SARRAY *
        ///  <summary>
        /// (1) This extracts digit data after recogaIdentifyMultiple() or
        /// lower-level identification has taken place.<para/>
        ///
        /// (2) Each string in the returned sa contains a sequence of ascii
        /// digits in a number.<para/>
        ///
        /// (3) The horizontal distance between boxes (limited by %spacethresh)
        /// is the negative of the horizontal overlap.<para/>
        ///
        /// (4) Components with a score less than %scorethresh, which may
        /// be hyphens or other small characters, will signal the
        /// end of the current sequence of digits in the number.  A typical
        /// value for %scorethresh is 0.60.<para/>
        ///
        /// (5) We allow two digits to be combined if these conditions apply:
        /// (a) the first is to the left of the second
        /// (b) the second has a horizontal separation less than %spacethresh
        /// (c) the vertical overlap greater or equal 0 (vertical separation  is smaller 0)
        /// (d) both have a score that exceeds %scorethresh<para/>
        ///
        /// (6) Each numa in the optionally returned naa contains the digit
        /// scores of a number.  Each boxa in the optionally returned baa
        /// contains the bounding boxes of the digits in the number.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/recogExtractNumbers/*"/>
        ///  <param name="recog">[in] - </param>
        ///  <param name="boxas">[in] - location of components</param>
        ///  <param name="scorethresh">[in] - min score for which we accept a component</param>
        ///  <param name="spacethresh">[in] - max horizontal distance allowed between digits, use -1 for default</param>
        ///  <param name="pbaa">[out][optional] - bounding boxes of identified numbers</param>
        ///  <param name="pnaa">[out][optional] - scores of identified digits</param>
        ///   <returns>sa of identified numbers, or NULL on error</returns>
        public static Sarray recogExtractNumbers(
            L_Recog recog,
            Boxa boxas,
            Single scorethresh,
            int spacethresh,
            out Boxaa pbaa,
            out Numaa pnaa)
        {
            if (recog == null)
            {
                throw new ArgumentNullException("recog cannot be Nothing");
            }

            if (boxas == null)
            {
                throw new ArgumentNullException("boxas cannot be Nothing");
            }

            IntPtr pbaaPtr = IntPtr.Zero;
            IntPtr pnaaPtr = IntPtr.Zero;
            IntPtr _Result = Natives.recogExtractNumbers(recog.Pointer, boxas.Pointer, scorethresh, spacethresh, out pbaaPtr, out pnaaPtr);

            if (pbaaPtr == IntPtr.Zero)
            {
                pbaa = null;
            }
            else
            {
                pbaa = new Boxaa(pbaaPtr);
            };
            if (pnaaPtr == IntPtr.Zero)
            {
                pnaa = null;
            }
            else
            {
                pnaa = new Numaa(pnaaPtr);
            };

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Sarray(_Result));
        }
Esempio n. 8
0
        // boxfunc2.c (1715, 1)
        // boxaaAlignBox(baa, box, delta, pindex) as int
        // boxaaAlignBox(BOXAA *, BOX *, l_int32, l_int32 *) as l_ok
        ///  <summary>
        /// (1) This is not greedy.  It finds the boxa whose vertical
        /// extent has the closest overlap with the input box.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/boxaaAlignBox/*"/>
        ///  <param name="baa">[in] - </param>
        ///  <param name="box">[in] - to be aligned with the bext boxa in the baa, if possible</param>
        ///  <param name="delta">[in] - amount by which consecutive components can miss in overlap and still be included in the array</param>
        ///  <param name="pindex">[out] - index of boxa with best overlap, or if none match, this is the index of the next boxa to be generated</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int boxaaAlignBox(
            Boxaa baa,
            Box box,
            int delta,
            out int pindex)
        {
            if (baa == null)
            {
                throw new ArgumentNullException("baa cannot be Nothing");
            }

            if (box == null)
            {
                throw new ArgumentNullException("box cannot be Nothing");
            }

            int _Result = Natives.boxaaAlignBox(baa.Pointer, box.Pointer, delta, out pindex);

            return(_Result);
        }
Esempio n. 9
0
        // boxfunc2.c (1544, 1)
        // boxaaFlattenAligned(baa, num, fillerbox, copyflag) as Boxa
        // boxaaFlattenAligned(BOXAA *, l_int32, BOX *, l_int32) as BOXA *
        ///  <summary>
        /// (1) This 'flattens' the baa to a boxa, taking the first %num
        /// boxes from each boxa.<para/>
        ///
        /// (2) In each boxa, if there are less than %num boxes, we preserve
        /// the alignment between the input baa and the output boxa
        /// by inserting one or more fillerbox(es) or, if %fillerbox == NULL,
        /// one or more invalid placeholder boxes.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/boxaaFlattenAligned/*"/>
        ///  <param name="baa">[in] - </param>
        ///  <param name="num">[in] - number extracted from each</param>
        ///  <param name="fillerbox">[in][optional] - that fills if necessary</param>
        ///  <param name="copyflag">[in] - L_COPY or L_CLONE</param>
        ///   <returns>boxa, or NULL on error</returns>
        public static Boxa boxaaFlattenAligned(
            Boxaa baa,
            int num,
            Box fillerbox,
            int copyflag)
        {
            if (baa == null)
            {
                throw new ArgumentNullException("baa cannot be Nothing");
            }

            IntPtr fillerboxPtr = IntPtr.Zero;      if (fillerbox != null)
            {
                fillerboxPtr = fillerbox.Pointer;
            }
            IntPtr _Result = Natives.boxaaFlattenAligned(baa.Pointer, num, fillerboxPtr, copyflag);

            if (_Result == IntPtr.Zero)
            {
                return(null);
            }

            return(new Boxa(_Result));
        }