Ejemplo n.º 1
0
        public Pix GetBinaryImage(PageIteratorLevel level)
        {
            VerifyNotDisposed();
            if (handle.Handle == IntPtr.Zero)
            {
                return(null);
            }

            return(Pix.Create(Interop.TessApi.Native.PageIteratorGetBinaryImage(handle, level)));
        }
        /// <summary>
        /// Converts the specified <paramref name="img"/> to a <see cref="Pix"/>.
        /// </summary>
        /// <param name="img">The source image to be converted.</param>
        /// <returns>The converted pix.</returns>
        public Pix Convert(Bitmap img)
        {
            var pixDepth = GetPixDepth(img.PixelFormat);
            var pix      = Pix.Create(img.Width, img.Height, pixDepth);

            BitmapData imgData = null;
            PixData    pixData = null;

            try
            {
                // TODO: Set X and Y resolution

                if ((img.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed)
                {
                    CopyColormap(img, pix);
                }

                // transfer data
                imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, img.PixelFormat);
                pixData = pix.GetData();

                if (imgData.PixelFormat == PixelFormat.Format32bppArgb)
                {
                    TransferDataFormat32bppArgb(imgData, pixData);
                }
                else if (imgData.PixelFormat == PixelFormat.Format24bppRgb)
                {
                    TransferDataFormat24bppRgb(imgData, pixData);
                }
                else if (imgData.PixelFormat == PixelFormat.Format8bppIndexed)
                {
                    TransferDataFormat8bppIndexed(imgData, pixData);
                }
                else if (imgData.PixelFormat == PixelFormat.Format1bppIndexed)
                {
                    TransferDataFormat1bppIndexed(imgData, pixData);
                }
                return(pix);
            }
            catch (Exception)
            {
                pix.Dispose();
                throw;
            }
            finally
            {
                if (imgData != null)
                {
                    img.UnlockBits(imgData);
                }
            }
        }
Ejemplo n.º 3
0
        public Pix GetImage(PageIteratorLevel level, int padding, out int x, out int y)
        {
            VerifyNotDisposed();
            if (handle.Handle == IntPtr.Zero)
            {
                x = 0;
                y = 0;

                return(null);
            }

            return(Pix.Create(Interop.TessApi.Native.PageIteratorGetImage(handle, level, padding, page.Image.Handle, out x, out y)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the thresholded image that was OCR'd.
        /// </summary>
        /// <returns></returns>
        public Pix GetThresholdedImage()
        {
            Recognize();

            var pixHandle = Interop.TessApi.Native.BaseAPIGetThresholdedImage(Engine.Handle);

            if (pixHandle == IntPtr.Zero)
            {
                throw new TesseractException("Failed to get thresholded image.");
            }

            return(Pix.Create(pixHandle));
        }