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: Setup colormap, if required if ((img.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { throw new NotImplementedException("Indexed bitmaps are not currently supported."); } // transfer data imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, img.PixelFormat); pixData = pix.GetData(); TransferData(imgData, pixData); return(pix); } catch (Exception) { pix.Dispose(); throw; } finally { if (imgData != null) { img.UnlockBits(imgData); } } }
/// <summary> /// Get the next IFD entry from this TIFF. /// </summary> /// <returns>null if there are no more images.</returns> public Pix NextPix() { if (reachedEndOfFile) { return(null); } IntPtr handle; if (Offsets.Count > 0) { int offset = Offsets[Offsets.Count - 1]; handle = Interop.LeptonicaApi.Native.pixReadFromMultipageTiff(Filename, ref offset); if (handle == IntPtr.Zero) { return(null); } if (offset != 0) { Offsets.Add(offset); } else { reachedEndOfFile = true; } } else { throw new IOException("Invalid state."); } return(Pix.Create(handle)); }
/// <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); pix.XRes = (int)Math.Round(img.HorizontalResolution); pix.YRes = (int)Math.Round(img.VerticalResolution); 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.Format32bppRgb) { TransferDataFormat32bppRgb(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); } } }
public Pix GetBinaryImage(PageIteratorLevel level) { VerifyNotDisposed(); if (handle.Handle == IntPtr.Zero) { return(null); } return(Pix.Create(Interop.TessApi.Native.PageIteratorGetBinaryImage(handle, level))); }
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))); }
/// <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)); }
public Pix Convert(Bitmap img) { var pixDepth = this.GetPixDepth(img.PixelFormat); var pix = Pix.Create(img.Width, img.Height, pixDepth); BitmapData imgData = null; try { // TODO: Set X and Y resolution if ((img.PixelFormat & PixelFormat.Indexed) == PixelFormat.Indexed) { this.CopyColormap(img, pix); } // transfer data imgData = img.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, img.PixelFormat); var pixData = pix.GetData(); switch (imgData.PixelFormat) { case PixelFormat.Format32bppArgb: this.TransferDataFormat32bppArgb(imgData, pixData); break; case PixelFormat.Format24bppRgb: this.TransferDataFormat24bppRgb(imgData, pixData); break; case PixelFormat.Format8bppIndexed: this.TransferDataFormat8bppIndexed(imgData, pixData); break; case PixelFormat.Format1bppIndexed: this.TransferDataFormat1bppIndexed(imgData, pixData); break; } return(pix); } catch (Exception) { pix.Dispose(); throw; } finally { if (imgData != null) { img.UnlockBits(imgData); } } }
/// <summary> /// Get an image corresponding to the TIFF's IFD number using the offset cache. If the offset has not /// been previously visited then the request is rejected. /// </summary> /// <param name="i">The IFD number, origin zero.</param> /// <returns>null if the IFD isn't present, or the image.</returns> public Pix GetPix(int i) { int offset = 0; if (i < Offsets.Count) { offset = Offsets[i]; } else { throw new IOException("Invalid sequence."); } IntPtr handle = Interop.LeptonicaApi.Native.pixReadFromMultipageTiff(Filename, ref offset); if (handle == IntPtr.Zero) { return(null); } return(Pix.Create(handle)); }
public Pix GetImage(PageIteratorLevel level, int padding, out int x, out int y) => Pix.Create(TessApi.Native.PageIteratorGetImage(this.handle, level, padding, out x, out y));
public Pix GetBinaryImage(PageIteratorLevel level) => Pix.Create(TessApi.Native.PageIteratorGetBinaryImage(this.handle, level));
public Pix GetImage(PageIteratorLevel level, int padding, out int x, out int y) { return(Pix.Create(Interop.TessApi.Native.PageIteratorGetImage(handle, level, padding, out x, out y))); }
public Pix GetBinaryImage(PageIteratorLevel level) { return(Pix.Create(Interop.TessApi.Native.PageIteratorGetBinaryImage(handle, level))); }
public Pix GetImage(PageIteratorLevel level, int padding, out int x, out int y) { return(Pix.Create(TesseractPrimitives.Api.PageIteratorGetImage(handle, level, padding, out x, out y))); }
public Pix GetBinaryImage(PageIteratorLevel level) { return(Pix.Create(TesseractPrimitives.Api.PageIteratorGetBinaryImage(handle, level))); }