/// <summary> /// Detects the page orientation, with corresponding confidence when using <see cref="PageSegMode.OsdOnly"/>. /// </summary> /// <remarks> /// If using full page segmentation mode (i.e. AutoOsd) then consider using <see cref="AnalyseLayout"/> instead as this also provides a /// deskew angle which isn't available when just performing orientation detection. /// </remarks> /// <param name="orientation">The detected clockwise page rotation in degrees (0, 90, 180, or 270).</param> /// <param name="confidence">The confidence level of the orientation (15 is reasonably confident).</param> /// <param name="scriptName">The name of the script (e.g. Latin)<param> /// <param name="scriptConfidence">The confidence level in the script</param> public void DetectBestOrientationAndScript(out int orientation, out float confidence, out string scriptName, out float scriptConfidence) { int orient_deg; float orient_conf; IntPtr script_nameHandle; float script_conf; if (Interop.TessApi.Native.TessBaseAPIDetectOrientationScript(Engine.Handle, out orient_deg, out orient_conf, out script_nameHandle, out script_conf) != 0) { orientation = orient_deg; confidence = orient_conf; if (script_nameHandle != IntPtr.Zero) { scriptName = MarshalHelper.PtrToString(script_nameHandle, Encoding.ASCII); // Don't delete script_nameHandle as it points to internal memory managed by Tesseract. } else { scriptName = null; } scriptConfidence = script_conf; } else { throw new TesseractException("Failed to detect image orientation."); } }
public FontAttributes GetWordFontAttributes() { VerifyNotDisposed(); if (handle.Handle == IntPtr.Zero) { return(null); } bool isBold, isItalic, isUnderlined, isMonospace, isSerif, isSmallCaps; int pointSize, fontId; // per docs (ltrresultiterator.h:104 as of 4897796 in github:tesseract-ocr/tesseract) // this return value points to an internal table and should not be deleted. IntPtr nameHandle = Interop.TessApi.Native.ResultIteratorWordFontAttributes( handle, out isBold, out isItalic, out isUnderlined, out isMonospace, out isSerif, out isSmallCaps, out pointSize, out fontId); // This can happen in certain error conditions if (nameHandle == IntPtr.Zero) { return(null); } FontInfo fontInfo; if (!_fontInfoCache.TryGetValue(fontId, out fontInfo)) { string fontName = MarshalHelper.PtrToString(nameHandle, Encoding.UTF8); fontInfo = new FontInfo(fontName, fontId, isItalic, isBold, isMonospace, isSerif); _fontInfoCache.Add(fontId, fontInfo); } return(new FontAttributes(fontInfo, isUnderlined, isSmallCaps, pointSize)); }