コード例 #1
0
ファイル: PageIterator.cs プロジェクト: kn1m/briefCore
        public Pix GetBinaryImage(PageIteratorLevel level)
        {
            VerifyNotDisposed();
            if (handle.Handle == IntPtr.Zero)
            {
                return(null);
            }

            return(Pix.Create(TessApi.Native.PageIteratorGetBinaryImage(handle, level)));
        }
コード例 #2
0
ファイル: PageIterator.cs プロジェクト: kn1m/briefCore
        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(TessApi.Native.PageIteratorGetImage(handle, level, padding, page.Image.Handle, out x, out y)));
        }
コード例 #3
0
ファイル: Page.cs プロジェクト: kn1m/briefCore
        /// <summary>
        /// Gets the thresholded image that was OCR'd.
        /// </summary>
        /// <returns></returns>
        public Pix GetThresholdedImage()
        {
            Recognize();

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

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

            return(Pix.Create(pixHandle));
        }
コード例 #4
0
        /// <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);
                }
            }
        }