npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@capacitor-community/image-to-text

v6.0.1

Published

Image to Text (OCR) Plugin for Capacitor

Downloads

2,535

Readme

Credits

This project was forked from the Cap ML plugin written by Vennela Kodali. It was refactored and converted to Capacitor 4.

  • For Capacitor 4 projects use v4.x
  • For Capacitor 5 projects use v5.x
  • For Capacitor 6 projects use v6.x

Installation

npm install @capacitor-community/image-to-text

Usage

There is one method detectText that takes a filename of an image and will return the text associated with it.

Add the following to your application:

import { Ocr, TextDetections } from '@capacitor-community/image-to-text';

...

const data: TextDetections = await Ocr.detectText({ filename: '[get-filename-of-image-jpg]' });
for (let detection of data.textDetections) {
    console.log(detection.text);
}

The above code will convert the image file and console.log the text found in it.

Example with Camera

You can use the @capacitor/camera plugin to take a photo and convert it to text:

import { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
import { Ocr, TextDetections } from '@capacitor-community/image-to-text';

...

const photo = await Camera.getPhoto({
  quality: 90,
  allowEditing: true,
  resultType: CameraResultType.Uri,
  source: CameraSource.Camera,
});

const data: TextDetections = await Ocr.detectText({ filename: photo.path });

for (let detection of data.textDetections) {
  console.log(detection.text);
}

A full sample application can be found here.

video of scanning a card and it being converted to text

iOS Usage

No additional setup is required to use this plugin in a iOS Capacitor project.

Android Usage

Your project must include a google-services.json file stored in the Android project folder (usually android/app).

Create Firebase Project and App

  • Sign in to console.firebase.google.com
  • Click on Add Project and follow through the steps.
  • Click the Android icon to create an android app.
  • Enter the Package Name which must match your apps package name (You can find it in android/app/AndroidManifest.xml).
  • Click Register App
  • Download google-services.json and save into your project's android/app directory.

Add Firebase SDK

The sample project has this in place in its build.gradle (see here as a reference).

Note: Most starter Capacitor projects are preconfigured to load google-services.json.

API Reference

detectText(...)

detectText(options: DetectTextFileOptions | DetectTextBase64Options) => Promise<TextDetections>

Detect text in an image

| Param | Type | Description | | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------- | -------------------------- | | options | DetectTextFileOptions | DetectTextBase64Options | Options for text detection |

Returns: Promise<TextDetections>


Interfaces

TextDetections

| Prop | Type | | -------------------- | ---------------------------- | | textDetections | TextDetection[] |

TextDetection

| Prop | Type | | ----------------- | ----------------------------- | | bottomLeft | [number, number] | | bottomRight | [number, number] | | topLeft | [number, number] | | topRight | [number, number] | | text | string |

DetectTextFileOptions

| Prop | Type | | ----------------- | ------------------------------------------------------------- | | filename | string | | orientation | ImageOrientation |

DetectTextBase64Options

| Prop | Type | | ----------------- | ------------------------------------------------------------- | | base64 | string | | orientation | ImageOrientation |

Enums

ImageOrientation

| Members | Value | | ----------- | -------------------- | | Up | 'UP' | | Down | 'DOWN' | | Left | 'LEFT' | | Right | 'RIGHT' |

Compatibility

Images are expected to be in portrait mode only, i.e. with text facing up. It will try to process even otherwise, but note that it might result in gibberish.

iOS and Android are supported. Web is not.

| Feature | ios | android | | -------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------- | | ML Framework | CoreML Vision | Firebase MLKit | | Text Detection with Still Images | Yes | Yes | | Detects lines of text | Yes | Yes | | Bounding Coordinates for Text | Yes | Yes | | Image Orientation | Yes (Up, Left, Right, Down) | Yes (Up, Left, Right, Down) | | Skewed Text | Yes | Unreliable | | Rotated Text (<~ 45deg) | Yes | Yes (but with noise) | | On-Device | Yes | Yes | | SDK/ios Version | ios 13.0 or newer | Targets API level >= 16Uses Gradle >= 4.1com.android.tools.build:gradle >= v3.2.1compileSdkVersion >= 28 | | | | |

License

Hippocratic License Version 2.0.

For more information, refer to LICENSE file