Beispiel #1
0
        public static int dewarpWriteMem(out IntPtr pdata, IntPtr psize, L_Dewarp dew)
        {
            if (IntPtr.Zero == psize ||
                null == dew)
            {
                throw new ArgumentNullException("psize, dew cannot be null.");
            }

            return(Native.DllImports.dewarpWriteMem(out pdata, psize, (HandleRef)dew));
        }
Beispiel #2
0
        public static int dewarpWriteStream(IntPtr fp, L_Dewarp dew)
        {
            if (IntPtr.Zero == fp ||
                null == dew)
            {
                throw new ArgumentNullException("fp, dew cannot be null.");
            }

            return(Native.DllImports.dewarpWriteStream(fp, (HandleRef)dew));
        }
Beispiel #3
0
        public static int dewarpWrite(string filename, L_Dewarp dew)
        {
            if (null == dew ||
                string.IsNullOrWhiteSpace(filename))
            {
                throw new ArgumentNullException("filename, dewa cannot be null.");
            }

            return(Native.DllImports.dewarpWrite(filename, (HandleRef)dew));
        }
Beispiel #4
0
        public static void dewarpDestroy(this L_Dewarp pdew)
        {
            if (null == pdew)
            {
                throw new ArgumentNullException("pdew cannot be null");
            }

            var pointer = (IntPtr)pdew;

            Native.DllImports.dewarpDestroy(ref pointer);
        }
Beispiel #5
0
        // dewarp3.c (729, 1)
        // dewarpMinimize(dew) as int
        // dewarpMinimize(L_DEWARP *) as l_ok
        ///  <summary>
        /// (1) This removes all data that is not needed for serialization.
        /// It keeps the subsampled disparity array(s), so the full
        /// resolution arrays can be reconstructed.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpMinimize/*"/>
        ///  <param name="dew">[in] - </param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpMinimize(
            L_Dewarp dew)
        {
            if (dew == null)
            {
                throw new ArgumentNullException("dew cannot be Nothing");
            }

            int _Result = Natives.dewarpMinimize(dew.Pointer);

            return(_Result);
        }
Beispiel #6
0
        // Dewarpa insertion/extraction
        public static int dewarpaInsertDewarp(this L_Dewarpa dewa, L_Dewarp dew)
        {
            if (null == dewa ||
                null == dew)
            {
                throw new ArgumentNullException("dewa, dew cannot be null");
            }

            var pointer = (IntPtr)dewa;

            return(Native.DllImports.dewarpaInsertDewarp((HandleRef)dewa, (HandleRef)dew));
        }
Beispiel #7
0
        // dewarp2.c (148, 1)
        // dewarpBuildPageModel(dew, debugfile) as int
        // dewarpBuildPageModel(L_DEWARP *, const char *) as l_ok
        ///  <summary>
        /// (1) This is the basic function that builds the horizontal and
        /// vertical disparity arrays, which allow determination of the
        /// src pixel in the input image corresponding to each
        /// dest pixel in the dewarped image.<para/>
        ///
        /// (2) Sets vsuccess = 1 if the vertical disparity array builds.
        /// Always attempts to build the horizontal disparity array,
        /// even if it will not be requested (useboth == 0).
        /// Sets hsuccess = 1 if horizontal disparity builds.<para/>
        ///
        /// (3) The method is as follows:
        /// (a) Estimate the points along the centers of all the
        /// long textlines.  If there are too few lines, no
        /// disparity models are built.
        /// (b) From the vertical deviation of the lines, estimate
        /// the vertical disparity.
        /// (c) From the ends of the lines, estimate the horizontal
        /// disparity, assuming that the text is made of lines
        /// that are close to left and right justified.
        /// (d) One can also compute an additional contribution to the
        /// horizontal disparity, inferred from slopes of the top
        /// and bottom lines.  We do not do this.<para/>
        ///
        /// (4) In more detail for the vertical disparity:
        /// (a) Fit a LS quadratic to center locations along each line.
        /// This smooths the curves.
        /// (b) Sample each curve at a regular interval, find the y-value
        /// of the mid-point on each curve, and subtract the sampled
        /// curve value from this value.  This is the vertical
        /// disparity at sampled points along each curve.
        /// (c) Fit a LS quadratic to each set of vertically aligned
        /// disparity samples.  This smooths the disparity values
        /// in the vertical direction.  Then resample at the same
        /// regular interval.  We now have a regular grid of smoothed
        /// vertical disparity valuels.<para/>
        ///
        /// (5) Once the sampled vertical disparity array is found, it can be
        /// interpolated to get a full resolution vertical disparity map.
        /// This can be applied directly to the src image pixels
        /// to dewarp the image in the vertical direction, making
        /// all textlines horizontal.  Likewise, the horizontal
        /// disparity array is used to left- and right-align the
        /// longest textlines.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpBuildPageModel/*"/>
        ///  <param name="dew">[in] - </param>
        ///  <param name="debugfile">[in]use NULL to skip - writing this</param>
        ///   <returns>0 if OK, 1 if unable to build the model or on error</returns>
        public static int dewarpBuildPageModel(
            L_Dewarp dew,
            String debugfile = "")
        {
            if (dew == null)
            {
                throw new ArgumentNullException("dew cannot be Nothing");
            }

            int _Result = Natives.dewarpBuildPageModel(dew.Pointer, debugfile);

            return(_Result);
        }
Beispiel #8
0
        // dewarp1.c (1330, 1)
        // dewarpWriteStream(fp, dew) as int
        // dewarpWriteStream(FILE *, L_DEWARP *) as l_ok
        ///  <summary>
        /// (1) This should not be written if there is no sampled
        /// vertical disparity array, which means that no model has
        /// been built for this page.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpWriteStream/*"/>
        ///  <param name="fp">[in] - file stream opened for "wb"</param>
        ///  <param name="dew">[in] - </param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpWriteStream(
            FILE fp,
            L_Dewarp dew)
        {
            if (fp == null)
            {
                throw new ArgumentNullException("fp cannot be Nothing");
            }

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

            int _Result = Natives.dewarpWriteStream(fp.Pointer, dew.Pointer);

            return(_Result);
        }
Beispiel #9
0
        // dewarp1.c (1292, 1)
        // dewarpWrite(filename, dew) as int
        // dewarpWrite(const char *, L_DEWARP *) as l_ok
        ///  <summary>
        /// dewarpWrite()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpWrite/*"/>
        ///  <param name="filename">[in] - </param>
        ///  <param name="dew">[in] - </param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpWrite(
            String filename,
            L_Dewarp dew)
        {
            if (filename == null)
            {
                throw new ArgumentNullException("filename cannot be Nothing");
            }

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

            int _Result = Natives.dewarpWrite(filename, dew.Pointer);

            return(_Result);
        }
Beispiel #10
0
        // dewarp1.c (805, 1)
        // dewarpaInsertDewarp(dewa, dew) as int
        // dewarpaInsertDewarp(L_DEWARPA *, L_DEWARP *) as l_ok
        ///  <summary>
        /// (1) This inserts the dewarp into the array, which now owns it.
        /// It also keeps track of the largest page number stored.
        /// It must be done before the disparity model is built.<para/>
        ///
        /// (2) Note that this differs from the usual method of filling out
        /// arrays in leptonica, where the arrays are compact and
        /// new elements are typically added to the end.  Here,
        /// the dewarp can be added anywhere, even beyond the initial
        /// allocation.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpaInsertDewarp/*"/>
        ///  <param name="dewa">[in] - </param>
        ///  <param name="dew">[in] - to be added</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpaInsertDewarp(
            L_Dewarpa dewa,
            L_Dewarp dew)
        {
            if (dewa == null)
            {
                throw new ArgumentNullException("dewa cannot be Nothing");
            }

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

            int _Result = Natives.dewarpaInsertDewarp(dewa.Pointer, dew.Pointer);

            return(_Result);
        }
Beispiel #11
0
        // dewarp2.c (558, 1)
        // dewarpFindHorizDisparity(dew, ptaa) as int
        // dewarpFindHorizDisparity(L_DEWARP *, PTAA *) as l_ok
        ///  <summary>
        /// (1) This builds a horizontal disparity model (HDM), but
        /// does not check it against constraints for validity.
        /// Constraint checking is done at rendering time.<para/>
        ///
        /// (2) Horizontal disparity is not required for a successful model
        /// only the vertical disparity is required.  This will not be
        /// called if the function to build the vertical disparity fails.<para/>
        ///
        /// (3) This sets the hsuccess flag to 1 on success.<para/>
        ///
        /// (4) Internally in ptal1, ptar1, ptal2, ptar2: x and y are reversed,
        /// so the 'y' value is horizontal distance across the image width.<para/>
        ///
        /// (5) Debug output goes to /tmp/lept/dewmod/ for collection into a pdf.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpFindHorizDisparity/*"/>
        ///  <param name="dew">[in] - </param>
        ///  <param name="ptaa">[in] - unsmoothed lines, not vertically ordered</param>
        ///   <returns>0 if OK, 1 if horizontal disparity array is not built, or on error</returns>
        public static int dewarpFindHorizDisparity(
            L_Dewarp dew,
            Ptaa ptaa)
        {
            if (dew == null)
            {
                throw new ArgumentNullException("dew cannot be Nothing");
            }

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

            int _Result = Natives.dewarpFindHorizDisparity(dew.Pointer, ptaa.Pointer);

            return(_Result);
        }
Beispiel #12
0
        // dewarp3.c (785, 1)
        // dewarpPopulateFullRes(dew, pix, x, y) as int
        // dewarpPopulateFullRes(L_DEWARP *, PIX *, l_int32, l_int32) as l_ok
        ///  <summary>
        /// (1) If the full resolution vertical and horizontal disparity
        /// arrays do not exist, they are built from the subsampled ones.<para/>
        ///
        /// (2) If pixs is not given, the size of the arrays is determined
        /// by the original image from which the sampled version was
        /// generated.  Any values of (x,y) are ignored.<para/>
        ///
        /// (3) If pixs is given, the full resolution disparity arrays must
        /// be large enough to accommodate it.
        /// (a) If the arrays do not exist, the value of (x,y) determines
        /// the origin of the full resolution arrays without extension,
        /// relative to pixs.  Thus, (x,y) gives the amount of
        /// slope extension in (left, top).  The (right, bottom)
        /// extension is then determined by the size of pixs and
        /// (x,y) the values should never be  is smaller 0.
        /// (b) If the arrays exist and pixs is too large, the existing
        /// full res arrays are destroyed and new ones are made,
        /// again using (x,y) to determine the extension in the
        /// four directions.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpPopulateFullRes/*"/>
        ///  <param name="dew">[in] - </param>
        ///  <param name="pix">[in][optional] - , to give size of actual image</param>
        ///  <param name="x">[in] - origin for generation of disparity arrays</param>
        ///  <param name="y">[in] - origin for generation of disparity arrays</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpPopulateFullRes(
            L_Dewarp dew,
            Pix pix,
            int x,
            int y)
        {
            if (dew == null)
            {
                throw new ArgumentNullException("dew cannot be Nothing");
            }

            IntPtr pixPtr = IntPtr.Zero;    if (pix != null)
            {
                pixPtr = pix.Pointer;
            }
            int _Result = Natives.dewarpPopulateFullRes(dew.Pointer, pixPtr, x, y);

            return(_Result);
        }
Beispiel #13
0
        // dewarp1.c (509, 1)
        // dewarpDestroy(pdew) as Object
        // dewarpDestroy(L_DEWARP **) as void
        ///  <summary>
        /// dewarpDestroy()
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpDestroy/*"/>
        ///  <param name="pdew">[in,out] - will be set to null before returning</param>
        public static void dewarpDestroy(
            ref L_Dewarp pdew)
        {
            IntPtr pdewPtr = IntPtr.Zero;   if (pdew != null)

            {
                pdewPtr = pdew.Pointer;
            }

            Natives.dewarpDestroy(ref pdewPtr);
            if (pdewPtr == IntPtr.Zero)
            {
                pdew = null;
            }
            else
            {
                pdew = new L_Dewarp(pdewPtr);
            };
        }
Beispiel #14
0
        // dewarp4.c (1008, 1)
        // dewarpDebug(dew, subdirs, index) as int
        // dewarpDebug(L_DEWARP *, const char *, l_int32) as l_ok
        ///  <summary>
        /// (1) Prints dewarp fields and generates disparity array contour images.
        /// The contour images are written to file:
        /// /tmp/[subdirs]/pixv_[index].png
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpDebug/*"/>
        ///  <param name="dew">[in] - </param>
        ///  <param name="subdirs">[in] - one or more subdirectories of /tmp e.g., "dew1"</param>
        ///  <param name="index">[in] - to help label output images e.g., the page number</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpDebug(
            L_Dewarp dew,
            String subdirs,
            int index)
        {
            if (dew == null)
            {
                throw new ArgumentNullException("dew cannot be Nothing");
            }

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

            int _Result = Natives.dewarpDebug(dew.Pointer, subdirs, index);

            return(_Result);
        }
Beispiel #15
0
        // dewarp2.c (1378, 1)
        // dewarpFindHorizSlopeDisparity(dew, pixb, fractthresh, parity) as int
        // dewarpFindHorizSlopeDisparity(L_DEWARP *, PIX *, l_float32, l_int32) as l_ok
        ///  <summary>
        /// (1) %fractthresh is a threshold on the fractional difference in stroke
        /// density between between left and right sides.  Process this
        /// disparity only if the absolute value of the fractional
        /// difference equals or exceeds this threshold.<para/>
        ///
        /// (2) %parity indicates where the binding is: on the left for
        /// %parity == 0 and on the right for %parity == 1.<para/>
        ///
        /// (3) This takes a 1 bpp %pixb where both vertical and horizontal
        /// disparity have been applied, so the text lines are straight and,
        /// more importantly, the line end points are vertically aligned.
        /// It estimates the foreshortening of the characters on the
        /// binding side, and if significant, computes a one-dimensional
        /// horizontal disparity function to compensate.<para/>
        ///
        /// (4) The first attempt was to use the average width of the
        /// connected components (c.c.) in vertical slices.  This does not work
        /// reliably, because the horizontal compression of the text is
        /// often accompanied by horizontal joining of c.c.<para/>
        ///
        /// (5) We use the density of vertical strokes, measured by first using
        /// a vertical opening, which improves the signal.  The result
        /// is relatively insensitive to the size of the opening we use
        /// a 10-pixel opening.  The relative density is measured by
        /// finding the number of c.c. in a full height sliding window
        /// of width 50 pixels, and compute every 25 pixels.  Similar results
        /// are obtained counting c.c. that either intersect the window
        /// or are fully contained within it.<para/>
        ///
        /// (6) Debug output goes to /tmp/lept/dewmod/ for collection into a pdf.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpFindHorizSlopeDisparity/*"/>
        ///  <param name="dew">[in] - </param>
        ///  <param name="pixb">[in] - (1 bpp, with vertical and horizontal disparity removed)</param>
        ///  <param name="fractthresh">[in] - (threshold fractional difference in density)</param>
        ///  <param name="parity">[in] - (0 if even page, 1 if odd page)</param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpFindHorizSlopeDisparity(
            L_Dewarp dew,
            Pix pixb,
            Single fractthresh,
            int parity)
        {
            if (dew == null)
            {
                throw new ArgumentNullException("dew cannot be Nothing");
            }

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

            int _Result = Natives.dewarpFindHorizSlopeDisparity(dew.Pointer, pixb.Pointer, fractthresh, parity);

            return(_Result);
        }
Beispiel #16
0
        // dewarp1.c (1386, 1)
        // dewarpWriteMem(pdata, psize, dew) as int
        // dewarpWriteMem(l_uint8 **, size_t *, L_DEWARP *) as l_ok
        ///  <summary>
        /// (1) Serializes a dewarp in memory and puts the result in a buffer.
        ///  </summary>
        ///  <remarks>
        ///  </remarks>
        ///  <include file="..\CHM_Help\IncludeComments.xml" path="Comments/dewarpWriteMem/*"/>
        ///  <param name="pdata">[out] - data of serialized dewarp (not ascii)</param>
        ///  <param name="psize">[out] - size of returned data</param>
        ///  <param name="dew">[in] - </param>
        ///   <returns>0 if OK, 1 on error</returns>
        public static int dewarpWriteMem(
            out Byte[] pdata,
            out uint psize,
            L_Dewarp dew)
        {
            if (dew == null)
            {
                throw new ArgumentNullException("dew cannot be Nothing");
            }

            IntPtr pdataPtr = IntPtr.Zero;
            int    _Result  = Natives.dewarpWriteMem(out pdataPtr, out psize, dew.Pointer);

            Byte[] pdataGen = new Byte[psize];

            if (pdataPtr != IntPtr.Zero)
            {
                Marshal.Copy(pdataPtr, pdataGen, 0, pdataGen.Length);
            }

            pdata = pdataGen;
            return(_Result);
        }