### Complete Flutter App Example Source: https://context7.com/letterassist-ai/flusseract/llms.txt Full example demonstrating image loading from assets, OCR processing, and displaying results in a Flutter widget. ```APIDOC ## Complete Flutter App Example ### Description Full example demonstrating image loading from assets, OCR processing, and displaying results in a Flutter widget. ### Method N/A (This is a complete application example) ### Endpoint N/A ### Parameters N/A ### Request Example ```dart import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flusseract/flusseract.dart' as flusseract; void main() async { WidgetsFlutterBinding.ensureInitialized(); flusseract.LibFlusseractLogger.init(); await flusseract.TessData.init(); runApp(const OcrApp()); } class OcrApp extends StatefulWidget { const OcrApp({super.key}); @override State createState() => _OcrAppState(); } class _OcrAppState extends State { String? _ocrText; bool _isProcessing = false; Future _performOcr() async { setState(() => _isProcessing = true); flusseract.PixImage? image; flusseract.Tesseract? tesseract; try { final imageData = await rootBundle.load('assets/document.png'); image = flusseract.PixImage.fromBytes(imageData.buffer.asUint8List()); tesseract = flusseract.Tesseract( tessDataPath: flusseract.TessData.tessDataPath, ); final text = await tesseract.utf8Text(image); setState(() => _ocrText = text.trim()); } catch (e) { setState(() => _ocrText = 'Error: $e'); } finally { image?.dispose(); tesseract?.dispose(); setState(() => _isProcessing = false); } } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Flusseract OCR')), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text('Tesseract: ${flusseract.Tesseract.version}'), ElevatedButton( onPressed: _isProcessing ? null : _performOcr, child: Text(_isProcessing ? 'Processing...' : 'Extract Text'), ), if (_ocrText != null) Padding( padding: const EdgeInsets.all(16), child: Text(_ocrText!), ), ], ), ), ), ); } } ``` ### Response N/A (This is a UI example) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Install Build Dependencies on macOS Source: https://github.com/letterassist-ai/flusseract/blob/main/README.md Install required system packages via Homebrew for building the plugin on macOS. ```bash # Packages which are always needed. brew install \ nasm \ automake \ autoconf \ libtool \ pkgconfig # Optional package for builds using g++. brew install gcc # Packages required for training tools. brew install pango # Build dependencoes. brew install \ icu4c \ leptonica \ tesseract # Optional packages for extra features. brew install libarchive ``` -------------------------------- ### Setup Flutter interface target Source: https://github.com/letterassist-ai/flusseract/blob/main/example/linux/flutter/CMakeLists.txt Creates an interface library target and links the necessary dependencies and include directories. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Install Flutter Assets Directory Source: https://github.com/letterassist-ai/flusseract/blob/main/example/linux/CMakeLists.txt Installs the Flutter assets directory to the application's data directory. Removes any existing directory before installation. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Flusseract Dependency Source: https://github.com/letterassist-ai/flusseract/blob/main/README.md Add the plugin to your Flutter project's pubspec.yaml file. ```yaml dependencies: . . flusseract: ^0.1.1 . . ``` -------------------------------- ### Install AOT Library (Non-Debug) Source: https://github.com/letterassist-ai/flusseract/blob/main/example/linux/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library on non-Debug builds. Ensure the AOT_LIBRARY variable is correctly set. ```cmake if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Tesseract Static Methods - Version and Cache Management Source: https://context7.com/letterassist-ai/flusseract/llms.txt Static utility methods for getting Tesseract version info, default data paths, and clearing memory caches. ```APIDOC ## Tesseract Static Methods - Version and Cache Management ### Description Static utility methods for getting Tesseract version info, default data paths, and clearing memory caches. ### Method Static methods on the `Tesseract` class. ### Endpoint N/A (Static methods) ### Parameters None ### Request Example ```dart import 'package:flusseract/flusseract.dart'; void checkTesseractInfo() { // Get Tesseract library version final version = Tesseract.version; print('Tesseract version: $version'); // e.g., "5.3.4" // Get default tessdata path final defaultPath = Tesseract.defaultTessDataPath; print('Default data path: $defaultPath'); // e.g., "/usr/local/share/tessdata/" // Clear expensive cached data structures (language dictionaries) // Useful for memory management in long-running applications Tesseract.clearPersistentCache(); } ``` ### Response None (returns information or performs an action) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Set Minimum CMake Version and Module Path Source: https://github.com/letterassist-ai/flusseract/blob/main/src/CMakeLists.txt Specifies the minimum required CMake version and includes a custom module path for build functions. Ensure CMake 3.10 or later is installed. ```cmake cmake_minimum_required(VERSION 3.22) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(ExternalProject) include(BuildFunctions) ``` -------------------------------- ### Tesseract.getBoundingBoxes - Get Word Positions and Confidence Source: https://context7.com/letterassist-ai/flusseract/llms.txt Retrieves bounding boxes for detected text elements at various granularity levels (block, paragraph, line, or word). Includes position coordinates, text content, and confidence scores. ```APIDOC ## Tesseract.getBoundingBoxes - Get Word Positions and Confidence ### Description Retrieves bounding boxes for detected text elements at various granularity levels (block, paragraph, line, or word). Includes position coordinates, text content, and confidence scores. ### Method POST (Assumed, as it requires prior OCR processing) ### Endpoint /ocr/bounding-boxes ### Parameters #### Query Parameters - **level** (String) - Required - The granularity level for bounding boxes (e.g., 'block', 'paragraph', 'line', 'word'). #### Request Body - **image** (File) - Required - The image file to perform OCR on. - **tessDataPath** (String) - Required - Path to the Tesseract language data files. ### Request Example ```json { "image": "", "tessDataPath": "/path/to/tessdata/" } ``` Query Parameter Example: `?level=word` ### Response #### Success Response (200) - **boxes** (Array[Object]) - A list of bounding box objects. - **word** (String) - The detected word. - **x1** (Integer) - The x-coordinate of the top-left corner. - **y1** (Integer) - The y-coordinate of the top-left corner. - **x2** (Integer) - The x-coordinate of the bottom-right corner. - **y2** (Integer) - The y-coordinate of the bottom-right corner. - **confidence** (Float) - The confidence score of the detection. - **blockNum** (Integer) - The block number. - **lineNum** (Integer) - The line number. - **wordNum** (Integer) - The word number. #### Response Example ```json [ { "word": "Hello,", "x1": 74, "y1": 64, "x2": 524, "y2": 190, "confidence": 94.81, "blockNum": 1, "lineNum": 1, "wordNum": 1 }, { "word": "World!", "x1": 638, "y1": 64, "x2": 1099, "y2": 170, "confidence": 96.12, "blockNum": 1, "lineNum": 1, "wordNum": 2 } ] ``` ``` -------------------------------- ### Build and Run Unit Tests Source: https://github.com/letterassist-ai/flusseract/blob/main/README.md Commands to configure the build environment and execute unit tests on macOS. ```bash mkdir build cd build PLATFORM_NAME=macosx cmake ../src make test ``` -------------------------------- ### Initialize Tesseract Data Files Source: https://context7.com/letterassist-ai/flusseract/llms.txt Copies trained language models from the app's asset bundle to a sandbox folder. This must be called asynchronously before any OCR operations. ```dart import 'package:flusseract/flusseract.dart' as flusseract; void main() async { WidgetsFlutterBinding.ensureInitialized(); // Initialize tessdata - copies trained models from assets to sandbox await flusseract.TessData.init(); // Access the initialized paths print('TessData Path: ${flusseract.TessData.tessDataPath}'); print('Config Path: ${flusseract.TessData.tessConfigPath}'); runApp(const MyApp()); } ``` -------------------------------- ### Add Dependencies and Include Directories Source: https://github.com/letterassist-ai/flusseract/blob/main/example/windows/runner/CMakeLists.txt Links necessary libraries and specifies include directories for the application target. Custom application-specific dependencies can also be added here. ```cmake # Add dependency libraries and include directories. Add any application-specific # dependencies here. target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### TessData Initialization Source: https://context7.com/letterassist-ai/flusseract/llms.txt Initializes the tessdata directory by copying trained language models from the app's asset bundle to a sandbox folder. This async call must complete before performing any text extraction. Requires at least the default English trained data file (eng.traineddata). ```APIDOC ## TessData.init ### Description Initializes the tessdata directory by copying trained language models from the app's asset bundle to a sandbox folder. This async call must complete before performing any text extraction. Requires at least the default English trained data file (eng.traineddata). ### Method Async function ### Endpoint N/A (Plugin method) ### Parameters None ### Request Example ```dart import 'package:flusseract/flusseract.dart' as flusseract; void main() async { WidgetsFlutterBinding.ensureInitialized(); await flusseract.TessData.init(); print('TessData Path: ${flusseract.TessData.tessDataPath}'); print('Config Path: ${flusseract.TessData.tessConfigPath}'); runApp(const MyApp()); } ``` ### Response None (initializes internal state) ### Response Example None ``` -------------------------------- ### Initialize Native Logging Source: https://context7.com/letterassist-ai/flusseract/llms.txt Routes Tesseract C++ library output to the Flutter logging system. Call this early during app initialization. ```dart import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; import 'package:flusseract/flusseract.dart' as flusseract; void main() { WidgetsFlutterBinding.ensureInitialized(); // Configure Flutter logging Logger.root.level = Level.ALL; Logger.root.onRecord.listen((record) { if (kDebugMode) { print('${record.level.name}: ${record.loggerName}.${record.message}'); } }); // Initialize native library logger flusseract.LibFlusseractLogger.init(); // Initialize tessdata then run app flusseract.TessData.init().then((_) { runApp(const MyApp()); }); } ``` -------------------------------- ### Create Multi-Arch iOS Simulator Library Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Creates a multi-architecture target library for the iOS simulator, combining builds for arm64 and x86_64 architectures. ```cmake ext_create_target_library( iphonesimulator "iphonesimulator-arm64;iphonesimulator-x86_64" ) ``` -------------------------------- ### Get Word Positions and Confidence Source: https://context7.com/letterassist-ai/flusseract/llms.txt Retrieves bounding boxes for detected text elements at various granularity levels. Requires calling a text extraction method first to populate internal data. ```dart import 'package:flusseract/flusseract.dart'; Future getTextWithPositions() async { PixImage? image; Tesseract? tesseract; try { image = PixImage.fromFile('test/data/images/test-helloworld.png'); tesseract = Tesseract( tessDataPath: '/path/to/tessdata/', ); // First extract text to populate internal data await tesseract.utf8Text(image); // Get bounding boxes at word level final boxes = tesseract.getBoundingBoxes(PageIteratorLevel.word); for (final box in boxes) { print('Word: "${box.word}"'); print(' Position: (${box.x1}, ${box.y1}) to (${box.x2}, ${box.y2})'); print(' Confidence: ${box.confidence.toStringAsFixed(2)}%'); print(' Block: ${box.blockNum}, Line: ${box.lineNum}, Word: ${box.wordNum}'); } // Output: // Word: "Hello," // Position: (74, 64) to (524, 190) // Confidence: 94.81% // Block: 1, Line: 1, Word: 1 // Word: "World!" // Position: (638, 64) to (1099, 170) // Confidence: 96.12% // Block: 1, Line: 1, Word: 2 } finally { image?.dispose(); tesseract?.dispose(); } } ``` -------------------------------- ### Create Multi-Arch Library for iOS Simulator Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libzstd/CMakeLists.txt Creates a multi-architecture library for iOS simulators, combining arm64 and x86_64 architectures. ```cmake # Create multi-arch library for iOS ext_create_target_library( iphonesimulator "iphonesimulator-arm64;iphonesimulator-x86_64" ) ``` -------------------------------- ### Build libpng for iOS Simulator (x86_64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the iOS simulator x86_64 architecture. This command downloads the source and prepares it for iOS simulator compilation. ```cmake ext_build_library_from_url( iphonesimulator x86_64 darwin ${URL} ${URL_HASH} ) ``` -------------------------------- ### Configure Flutter system dependencies Source: https://github.com/letterassist-ai/flusseract/blob/main/example/linux/flutter/CMakeLists.txt Locates and configures required system libraries including GTK, GLIB, and GIO using PkgConfig. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Build libpng for iOS Simulator (arm64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the iOS simulator arm64 architecture. This command downloads the source and prepares it for iOS simulator compilation. ```cmake ext_build_library_from_url( iphonesimulator arm64 darwin ${URL} ${URL_HASH} ) ``` -------------------------------- ### Build and Package libjpeg-turbo for macOSX Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libjpeg/CMakeLists.txt Builds library components for macOSX architectures and creates a combined multi-architecture target. ```cmake ext_build_library_from_git( macosx arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ``` ```cmake ext_build_library_from_git( macosx x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ``` ```cmake ext_create_target_library( macosx "macosx-arm64;macosx-x86_64" ) ``` -------------------------------- ### Define libpng URL and Hash Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Sets the download URL and SHA256 hash for the libpng library source. Ensure these are kept up-to-date for security and compatibility. ```cmake set(URL https://phoenixnap.dl.sourceforge.net/project/libpng/libpng16/1.6.43/libpng-1.6.43.tar.gz) set(URL_HASH SHA256=e804e465d4b109b5ad285a8fb71f0dd3f74f0068f91ce3cdfde618180c174925) ``` -------------------------------- ### Glob Source Files and Build Flusseract Library Source: https://github.com/letterassist-ai/flusseract/blob/main/src/CMakeLists.txt Finds all C and C++ source files in the current directory and builds the Flusseract shared library. Includes a compile option to suppress unused result warnings. ```cmake # Source files file(GLOB C_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.c) file(GLOB CXX_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) # Flusseract library build add_library(${LIB} SHARED ${C_SRCS} ${CXX_SRCS}) add_compile_options(-Wno-unused-result) ``` -------------------------------- ### Build libpng for macOS (x86_64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the macOS x86_64 architecture. This command downloads the source and prepares it for macOS compilation. ```cmake ext_build_library_from_url( macosx x86_64 darwin ${URL} ${URL_HASH} ) ``` -------------------------------- ### Build libpng for macOS (arm64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the macOS arm64 architecture. This command downloads the source and prepares it for macOS compilation. ```cmake ext_build_library_from_url( macosx arm64 darwin ${URL} ${URL_HASH} ) ``` -------------------------------- ### Create Multi-Arch macOS Library Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Creates a multi-architecture target library for macOS, combining builds for arm64 and x86_64 architectures. ```cmake ext_create_target_library( macosx "macosx-arm64;macosx-x86_64" ) ``` -------------------------------- ### Create Multi-Arch Library for macOS Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libzstd/CMakeLists.txt Creates a multi-architecture library for macOS, combining arm64 and x86_64 architectures. ```cmake # Create multi-arch library for macOSX ext_create_target_library( macosx "macosx-arm64;macosx-x86_64" ) ``` -------------------------------- ### LibFlusseractLogger.init - Initialize Native Logging Source: https://context7.com/letterassist-ai/flusseract/llms.txt Initializes the logging bridge to route Tesseract C++ library output to Flutter's logging system. Should be called early in app initialization. ```APIDOC ## LibFlusseractLogger.init - Initialize Native Logging ### Description Initializes the logging bridge to route Tesseract C++ library output to Flutter's logging system. Should be called early in app initialization. ### Method Static method on the `LibFlusseractLogger` class. ### Endpoint N/A (Static method) ### Parameters None ### Request Example ```dart import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; import 'package:flusseract/flusseract.dart' as flusseract; void main() { WidgetsFlutterBinding.ensureInitialized(); // Configure Flutter logging Logger.root.level = Level.ALL; Logger.root.onRecord.listen((record) { if (kDebugMode) { print('${record.level.name}: ${record.loggerName}.${record.message}'); } }); // Initialize native library logger flusseract.LibFlusseractLogger.init(); // Initialize tessdata then run app flusseract.TessData.init().then((_) { runApp(const MyApp()); }); } ``` ### Response None (initializes logging) #### Success Response (200) N/A #### Response Example N/A ``` -------------------------------- ### Configure Leptonica Build Variables Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libleptonica/CMakeLists.txt Sets the source repository, version tag, and required dependencies for the build process. ```cmake set(GIT_REPOSITORY https://github.com/DanBloomberg/leptonica.git) set(GIT_TAG 1.84.1) set(DEPENDS "libjpeg;libpng;libtiff") ``` -------------------------------- ### Build libjpeg-turbo for Android Architectures Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libjpeg/CMakeLists.txt Configures the build process for Android using specific ABI targets. ```cmake ext_build_library_from_git( android armeabi-v7a android ${GIT_REPOSITORY} ${GIT_TAG} ) ``` ```cmake ext_build_library_from_git( android arm64-v8a android ${GIT_REPOSITORY} ${GIT_TAG} ) ``` ```cmake ext_build_library_from_git( android x86 android ${GIT_REPOSITORY} ${GIT_TAG} ) ``` ```cmake ext_build_library_from_git( android x86_64 android ${GIT_REPOSITORY} ${GIT_TAG} ) ``` -------------------------------- ### Create Tesseract OCR Instance Source: https://context7.com/letterassist-ai/flusseract/llms.txt Initializes a Tesseract instance with support for multiple languages and configurable page segmentation modes. ```dart import 'package:flusseract/flusseract.dart'; // Basic usage with defaults (English, auto page segmentation) final tesseract = Tesseract( tessDataPath: TessData.tessDataPath, ); // Multi-language support final multiLangTesseract = Tesseract( languages: ['eng', 'fra', 'deu'], // English, French, German tessDataPath: TessData.tessDataPath, ); // Custom page segmentation for single-line text final singleLineTesseract = Tesseract( languages: ['eng'], pageSegMode: PageSegMode.singleLine, tessDataPath: TessData.tessDataPath, configFilePath: '/path/to/tessconfig', ); // Don't forget to dispose tesseract.dispose(); ``` -------------------------------- ### Initialize and Use Tesseract OCR Source: https://github.com/letterassist-ai/flusseract/blob/main/README.md Initialize the Tesseract data and perform text extraction on an image loaded from the asset bundle. ```dart . . import 'package:flusseract/flusseract.dart' as flusseract; . . await TessData.init(); . . rootBundle.load('assets/test-helloworld.png').then( (imageData) { final image = flusseract.PixImage.fromBytes( imageData.buffer.asUint8List(), ); final tesseract = flusseract.Tesseract( tessDataPath: TessData.tessDataPath, ); tesseract.utf8Text(image).then( (ocrText) { setState(() { _ocrText = ocrText; }); } ); }, ); ``` -------------------------------- ### Build libpng for iOS Device (arm64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the iOS device arm64 architecture. This command downloads the source and prepares it for iOS compilation. ```cmake ext_build_library_from_url( iphoneos arm64 darwin ${URL} ${URL_HASH} ) ``` -------------------------------- ### Build and Package libjpeg-turbo for iOS Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libjpeg/CMakeLists.txt Builds library components for iOS devices and simulators, then creates multi-architecture targets. ```cmake ext_build_library_from_git( iphoneos arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ext_create_target_library( iphoneos "iphoneos-arm64" ) ``` ```cmake ext_build_library_from_git( iphonesimulator arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) ``` ```cmake ext_build_library_from_git( iphonesimulator x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ``` ```cmake ext_create_target_library( iphonesimulator "iphonesimulator-arm64;iphonesimulator-x86_64" ) ``` -------------------------------- ### Build libpng for Android (x86_64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the Android x86_64 architecture. This command downloads the source from the specified URL and builds it for the Android NDK. ```cmake ext_build_library_from_url( android x86_64 android ${URL} ${URL_HASH} ) ``` -------------------------------- ### PixImage Loading Source: https://context7.com/letterassist-ai/flusseract/llms.txt Provides methods to load images into a PixImage instance, either from a file path or from raw bytes in memory. ```APIDOC ## PixImage.fromFile ### Description Creates a PixImage instance from a file path. Supports common image formats including PNG, TIFF, and JPEG. The image dimensions can be accessed via width and height properties. ### Method Static method ### Endpoint N/A (Plugin method) ### Parameters #### Path Parameters - **filePath** (String) - Required - The path to the image file. ### Request Example ```dart import 'package:flusseract/flusseract.dart'; final image = PixImage.fromFile('path/to/document.png'); print('Width: ${image.width}'); print('Height: ${image.height}'); image.dispose(); ``` ## PixImage.fromBytes ### Description Creates a PixImage instance from image bytes in memory (Uint8List). Useful when loading images from Flutter's asset bundle or network responses. ### Method Static method ### Endpoint N/A (Plugin method) ### Parameters #### Path Parameters - **bytes** (Uint8List) - Required - The image data as a byte list. ### Request Example ```dart import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flusseract/flusseract.dart'; // From Flutter asset bundle final imageData = await rootBundle.load('assets/document.png'); final image = PixImage.fromBytes(imageData.buffer.asUint8List()); // Or from a File final file = File('path/to/document.png'); final imageFromFile = PixImage.fromBytes(file.readAsBytesSync()); print('Loaded image: ${image.width}x${image.height}'); image.dispose(); ``` ### Response - **PixImage** - An instance of PixImage representing the loaded image. ### Response Example ```json { "width": 1024, "height": 576 } ``` ``` -------------------------------- ### Build libpng for Android (x86) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the Android x86 architecture. This command downloads the source from the specified URL and builds it for the Android NDK. ```cmake ext_build_library_from_url( android x86 android ${URL} ${URL_HASH} ) ``` -------------------------------- ### Build Tesseract OCR for Android (ARMv7) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libtesseract/CMakeLists.txt Builds the Tesseract OCR library for Android devices with ARMv7 architecture from a Git repository. Requires 'libleptonica' as a dependency. ```cmake set(GIT_REPOSITORY https://github.com/tesseract-ocr/tesseract.git) set(GIT_TAG 5.3.4) set(DEPENDS "libleptonica") # android device arm32 architecture ext_build_library_from_git( android armeabi-v7a android ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) ``` -------------------------------- ### Integrate Flutter Tool Build Steps Source: https://github.com/letterassist-ai/flusseract/blob/main/example/windows/runner/CMakeLists.txt Ensures that the Flutter tool's build processes are executed as part of the main application target's dependencies. This step is crucial and should not be removed. ```cmake # Run the Flutter tool portions of the build. This must not be removed. add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Build Leptonica for Android Architectures Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libleptonica/CMakeLists.txt Invokes the build process for various Android ABIs using the defined repository and dependencies. ```cmake # android device arm32 architecture ext_build_library_from_git( android armeabi-v7a android ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # android device arm64 architecture ext_build_library_from_git( android arm64-v8a android ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # android device x86 architecture ext_build_library_from_git( android x86 android ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # android device x86_64 architecture ext_build_library_from_git( android x86_64 android ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) ``` -------------------------------- ### Load Image from File Path Source: https://context7.com/letterassist-ai/flusseract/llms.txt Creates a PixImage instance from a file path, supporting formats like PNG, TIFF, and JPEG. Always call dispose() to free native resources. ```dart import 'package:flusseract/flusseract.dart'; // Load image from file final image = PixImage.fromFile('path/to/document.png'); // Access image dimensions print('Width: ${image.width}'); // e.g., 1024 print('Height: ${image.height}'); // e.g., 576 // Always dispose when done to free native resources image.dispose(); ``` -------------------------------- ### Tesseract OCR Instance Source: https://context7.com/letterassist-ai/flusseract/llms.txt Creates a Tesseract instance with configurable language detection, page segmentation mode, and data paths. Supports multiple languages and various segmentation modes for different document layouts. ```APIDOC ## Tesseract Constructor ### Description Creates a Tesseract instance with configurable language detection, page segmentation mode, and data paths. Supports multiple languages and various segmentation modes for different document layouts. ### Method Constructor ### Endpoint N/A (Class constructor) ### Parameters #### Path Parameters - **languages** (List) - Optional - List of language codes (e.g., 'eng', 'fra'). Defaults to ['eng']. - **pageSegMode** (PageSegMode) - Optional - The page segmentation mode. Defaults to PageSegMode.auto. - **tessDataPath** (String) - Required - Path to the tessdata directory. - **configFilePath** (String) - Optional - Path to a custom configuration file. ### Request Example ```dart import 'package:flusseract/flusseract.dart'; // Basic usage with defaults final tesseract = Tesseract( tessDataPath: TessData.tessDataPath, ); // Multi-language support final multiLangTesseract = Tesseract( languages: ['eng', 'fra', 'deu'], tessDataPath: TessData.tessDataPath, ); // Custom page segmentation final singleLineTesseract = Tesseract( languages: ['eng'], pageSegMode: PageSegMode.singleLine, tessDataPath: TessData.tessDataPath, configFilePath: '/path/to/tessconfig', ); tesseract.dispose(); ``` ### Response - **Tesseract** - An instance of the Tesseract OCR engine. ``` -------------------------------- ### Set C++ Standard and Project Name Source: https://github.com/letterassist-ai/flusseract/blob/main/src/CMakeLists.txt Configures the C++ standard to C++14 and sets the project name for the Flusseract library. ```cmake set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED True) set(LIB flusseract) project(${LIB}_library LANGUAGES C CXX) ``` -------------------------------- ### Build libpng for Android (arm64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the Android arm64 (arm64-v8a) architecture. This command downloads the source from the specified URL and builds it for the Android NDK. ```cmake ext_build_library_from_url( android arm64-v8a android ${URL} ${URL_HASH} ) ``` -------------------------------- ### Build libpng for Android (arm32) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libpng/CMakeLists.txt Builds the libpng library for the Android arm32 (armeabi-v7a) architecture. This command downloads the source from the specified URL and builds it for the Android NDK. ```cmake ext_build_library_from_url( android armeabi-v7a android ${URL} ${URL_HASH} ) ``` -------------------------------- ### Build Zstd for iOS Simulator (x86_64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libzstd/CMakeLists.txt Builds the libzstd library for iOS simulators with x86_64 architecture from a specified Git repository and tag. ```cmake # iOS simulator x86_64 architecture ext_build_library_from_git( iphonesimulator x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ``` -------------------------------- ### Platform-Specific Library Linking and Dependencies Source: https://github.com/letterassist-ai/flusseract/blob/main/src/CMakeLists.txt Handles platform-specific library linking, including finding and linking LibLZMA and ZLIB, and adding static library dependencies for various external libraries when a target type is defined. ```cmake if(DEFINED TARGET_TYPE) # Android NDK does not have liblzma. So skip # it as other libraries will be built without # it and so we do not need to link it. if(NOT DEFINED ANDROID_ABI) find_package(LibLZMA) if(NOT LIBLZMA_FOUND) message(FATAL_ERROR "liblzma not found") endif() message(STATUS "LIBLZMA_FOUND: ${LIBLZMA_FOUND} - ${LIBLZMA_LIBRARIES}") endif() find_package(ZLIB) if(NOT ZLIB_FOUND) message(FATAL_ERROR "zlib not found") endif() message(STATUS "ZLIB_FOUND: ${ZLIB_FOUND} - ${ZLIB_LIBRARIES}") # Library dependencies add_static_library_dependency(libzstd ${TARGET_TYPE}) add_static_library_dependency(libjpeg ${TARGET_TYPE}) add_static_library_dependency(libpng ${TARGET_TYPE}) add_static_library_dependency(libtiff ${TARGET_TYPE}) add_static_library_dependency(libleptonica ${TARGET_TYPE}) add_static_library_dependency(libtesseract ${TARGET_TYPE}) target_link_libraries(${LIB} ${LIBLZMA_LIBRARIES} ${ZLIB_LIBRARIES} libzstd libjpeg libpng libtiff libleptonica libtesseract ) endif() ``` -------------------------------- ### Define Application Target Source: https://github.com/letterassist-ai/flusseract/blob/main/example/windows/runner/CMakeLists.txt Defines the main executable target for the application. Source files for the application should be added here. Ensure BINARY_NAME is consistent for `flutter run` compatibility. ```cmake cmake_minimum_required(VERSION 3.14) project(runner LANGUAGES CXX) # Define the application target. To change its name, change BINARY_NAME in the # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer # work. # # Any new source files that you add to the application should be added here. add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Build Zstd for macOS (arm64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libzstd/CMakeLists.txt Builds the libzstd library for macOS with arm64 architecture from a specified Git repository and tag. ```cmake # macOSX arm64 architecture ext_build_library_from_git( macosx arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ``` -------------------------------- ### Manage Tesseract Version and Cache Source: https://context7.com/letterassist-ai/flusseract/llms.txt Provides static methods to retrieve library version info, default data paths, and clear persistent memory caches. ```dart import 'package:flusseract/flusseract.dart'; void checkTesseractInfo() { // Get Tesseract library version final version = Tesseract.version; print('Tesseract version: $version'); // e.g., "5.3.4" // Get default tessdata path final defaultPath = Tesseract.defaultTessDataPath; print('Default data path: $defaultPath'); // e.g., "/usr/local/share/tessdata/" // Clear expensive cached data structures (language dictionaries) // Useful for memory management in long-running applications Tesseract.clearPersistentCache(); } ``` -------------------------------- ### Build libtiff for macOSX (ARM 64-bit) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libtiff/CMakeLists.txt Configures the build for the macOSX ARM 64-bit architecture. Dependencies like libzstd and libjpeg are included. ```cmake # macOSX arm64 architecture ext_build_library_from_git( macosx arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) ``` -------------------------------- ### Build and Package Leptonica for macOSX Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libleptonica/CMakeLists.txt Builds the library for macOSX architectures and creates a combined multi-arch target. ```cmake # macOSX arm64 architecture ext_build_library_from_git( macosx arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # macOSX x86_64 architecture ext_build_library_from_git( macosx x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # Create multi-arch library for macOSX ext_create_target_library( macosx "macosx-arm64;macosx-x86_64" ) ``` -------------------------------- ### Build and Package Leptonica for iOS Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libleptonica/CMakeLists.txt Builds the library for iOS device and simulator architectures, then creates a multi-arch target library. ```cmake # iOS device arm64 architecture ext_build_library_from_git( iphoneos arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) ext_create_target_library( iphoneos "iphoneos-arm64" ) # iOS simulator arm64 architecture ext_build_library_from_git( iphonesimulator arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # iOS simulator x86_64 architecture ext_build_library_from_git( iphonesimulator x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # Create multi-arch library for iOS ext_create_target_library( iphonesimulator "iphonesimulator-arm64;iphonesimulator-x86_64" ) ``` -------------------------------- ### Build libtiff for macOSX (x86_64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libtiff/CMakeLists.txt Configures the build for the macOSX x86_64 architecture. Dependencies like libzstd and libjpeg are included. ```cmake # macOSX x86_64 architecture ext_build_library_from_git( macosx x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # Create multi-arch library for macOSX ext_create_target_library( macosx "macosx-arm64;macosx-x86_64" ) ``` -------------------------------- ### Build libtiff for iOS (Simulator ARM 64-bit) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libtiff/CMakeLists.txt Configures the build for the iOS simulator ARM 64-bit architecture. Dependencies like libzstd and libjpeg are included. ```cmake # iOS simulator arm64 architecture ext_build_library_from_git( iphonesimulator arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) ``` -------------------------------- ### Load Image from Memory Source: https://context7.com/letterassist-ai/flusseract/llms.txt Creates a PixImage instance from Uint8List bytes, suitable for images loaded from asset bundles or network responses. ```dart import 'dart:io'; import 'package:flutter/services.dart'; import 'package:flusseract/flusseract.dart'; // From Flutter asset bundle final imageData = await rootBundle.load('assets/document.png'); final image = PixImage.fromBytes(imageData.buffer.asUint8List()); // Or from a File final file = File('path/to/document.png'); final imageFromFile = PixImage.fromBytes(file.readAsBytesSync()); print('Loaded image: ${image.width}x${image.height}'); image.dispose(); ``` -------------------------------- ### Build Zstd for iOS Device (arm64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libzstd/CMakeLists.txt Builds the libzstd library for iOS devices with arm64 architecture from a specified Git repository and tag. A target library is then created. ```cmake # iOS device arm64 architecture ext_build_library_from_git( iphoneos arm64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ext_create_target_library( iphoneos "iphoneos-arm64" ) ``` -------------------------------- ### Build libtiff for iOS (Simulator x86_64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libtiff/CMakeLists.txt Configures the build for the iOS simulator x86_64 architecture. Dependencies like libzstd and libjpeg are included. ```cmake # iOS simulator x86_64 architecture ext_build_library_from_git( iphonesimulator x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) # Create multi-arch library for iOS ext_create_target_library( iphonesimulator "iphonesimulator-arm64;iphonesimulator-x86_64" ) ``` -------------------------------- ### Build Zstd for macOS (x86_64) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libzstd/CMakeLists.txt Builds the libzstd library for macOS with x86_64 architecture from a specified Git repository and tag. ```cmake # macOSX x86_64 architecture ext_build_library_from_git( macosx x86_64 darwin ${GIT_REPOSITORY} ${GIT_TAG} ) ``` -------------------------------- ### Implement Complete Flutter OCR App Source: https://context7.com/letterassist-ai/flusseract/llms.txt Demonstrates loading an image from assets, performing OCR, and displaying the extracted text within a Flutter widget. ```dart import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flusseract/flusseract.dart' as flusseract; void main() async { WidgetsFlutterBinding.ensureInitialized(); flusseract.LibFlusseractLogger.init(); await flusseract.TessData.init(); runApp(const OcrApp()); } class OcrApp extends StatefulWidget { const OcrApp({super.key}); @override State createState() => _OcrAppState(); } class _OcrAppState extends State { String? _ocrText; bool _isProcessing = false; Future _performOcr() async { setState(() => _isProcessing = true); flusseract.PixImage? image; flusseract.Tesseract? tesseract; try { final imageData = await rootBundle.load('assets/document.png'); image = flusseract.PixImage.fromBytes(imageData.buffer.asUint8List()); tesseract = flusseract.Tesseract( tessDataPath: flusseract.TessData.tessDataPath, ); final text = await tesseract.utf8Text(image); setState(() => _ocrText = text.trim()); } catch (e) { setState(() => _ocrText = 'Error: $e'); } finally { image?.dispose(); tesseract?.dispose(); setState(() => _isProcessing = false); } } @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('Flusseract OCR')), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Text('Tesseract: ${flusseract.Tesseract.version}'), ElevatedButton( onPressed: _isProcessing ? null : _performOcr, child: Text(_isProcessing ? 'Processing...' : 'Extract Text'), ), if (_ocrText != null) Padding( padding: const EdgeInsets.all(16), child: Text(_ocrText!), ), ], ), ), ), ); } } ``` -------------------------------- ### Define Flutter library and headers Source: https://github.com/letterassist-ai/flusseract/blob/main/example/linux/flutter/CMakeLists.txt Sets paths for the Flutter library and registers header files for the interface target. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Configure CMake for Flusseract Source: https://github.com/letterassist-ai/flusseract/blob/main/linux/CMakeLists.txt Sets the minimum CMake version and project metadata for the native build. ```cmake cmake_minimum_required(VERSION 3.10) # Project-level configuration. set(PROJECT_NAME "flusseract") project(${PROJECT_NAME} LANGUAGES CXX) # Invoke the build for native code shared with the other target platforms. # This can be changed to accommodate different builds. add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../src" "${CMAKE_CURRENT_BINARY_DIR}/shared") # List of absolute paths to libraries that should be bundled with the plugin. # This list could contain prebuilt libraries, or libraries created by an # external build triggered from this build file. set(flusseract_bundled_libraries # Defined in ../src/CMakeLists.txt. # This can be changed to accommodate different builds. $ PARENT_SCOPE ) ``` -------------------------------- ### Build libtiff for Android (x86) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libtiff/CMakeLists.txt Configures the build for the Android x86 architecture. Ensure dependencies like libzstd and libjpeg are available. ```cmake # android device x86 architecture ext_build_library_from_git( android x86 android ${GIT_REPOSITORY} ${GIT_TAG} ${DEPENDS} ) ``` -------------------------------- ### Build Zstd for Android (x86) Source: https://github.com/letterassist-ai/flusseract/blob/main/src/libzstd/CMakeLists.txt Builds the libzstd library for Android devices with x86 architecture from a specified Git repository and tag. ```cmake # android device x86 architecture ext_build_library_from_git( android x86 android ${GIT_REPOSITORY} ${GIT_TAG} ) ```