Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imagewordfinder

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imagewordfinder

Wrapper library for Google vision OCR to find position of a word/line/para in a image.

  • 1.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-70%
Maintainers
1
Weekly downloads
 
Created
Source

image-word-finder

Wrapper library for Google vision OCR to find position of a word/line/para in a image.

Start from here: https://cloud.google.com/vision/docs/quickstart

Methods to find word from image

Installation

npm install imagewordfinder

Include the module

const wordFinder = require('imagewordfinder');

To find a word in a image

let vertices = await wordFinder.findWord('imagepath.png', "birth");

To find multiple words in a image

let vertices = await wordFinder.findWord('imagepath.png', [
  "Name",
  "Current Address",
  "Contact Information",
]);

To find words in a image with case insensitivity (By default, it is case sensitive)

let options = {
  caseSensitive: false,
}

let vertices = await wordFinder.findWord('imagepath.png', [
  "Name",
  "Current Address",
  "Contact Information",
], options);

vertices = await wordFinder.findWord('imagepath.png', "birth", options);

The output of the word finder is as follows,

let vertices = await wordFinder.findWord('imagepath.png', "birth");

console.log(vertices);

==================================================================

{
	"para_text": "Alternate Names - List any names by which you are known or any names Date of Birth",
	"vertices": {
		"width": 17,
		"height": 9,
		"origin": {
			"x": 374,
			"y": 201
		}
	},
	"index": {
		"page_index": 0,
		"block_index": 5
	},
	"para_vertices": {
		"origin": {
			"x": 39,
			"y": 188
		},
		"height": 23,
		"width": 471
	},
	"word": "birth"
}

The above vertices can be used in various ways:

  1. To find exact position of word,
let vertices = await wordFinder.findWord('imagepath.png', "birth");

let x = vertices.vertices.origin.x;
let y = vertices.vertices.origin.y;

let xEnd = vertices.vertices.origin.x + vertices.vertices.width;
let yEnd = vertices.vertices.origin.y + vertices.vertices.height;

  1. To draw the boundary of word in css,
let element = document.createElement('div');

element.style.position = "absolute";
element.style.left = vertices.vertices.origin.x;
element.style.top = vertices.vertices.origin.y;
element.style.width = vertices.vertices.origin.x + vertices.vertices.width;
element.style.height = vertices.vertices.origin.y + vertices.vertices.height;

let body = document.getElementsByTagName('body')
body[0].appendChild(element);

To find distance between two words in a image

let distance = await wordFinder.findWord('imagepath.png', "Name", "Date of Birth");

The object format of distance object is as below,

{
	"distanceX": 306,
	"distanceY": 25,
	"word1": {
		"para_text": "Personal Information Name ( First , Middle , Last , Suffix )",
		"vertices": {
			"width": 24,
			"height": 11,
			"origin": {
				"x": 38,
				"y": 176
			}
		},
		"index": {
			"page_index": 0,
			"block_index": 5
		},
		"para_vertices": {
			"origin": {
				"x": 38,
				"y": 160
			},
			"height": 27,
			"width": 119
		},
		"word": "Name"
	},
	"word2": {
		"para_text": "Alternate Names - List any names by which you are known or any names Date of Birth",
		"vertices": {
			"width": 17,
			"height": 9,
			"origin": {
				"x": 344,
				"y": 201
			}
		},
		"index": {
			"page_index": 0,
			"block_index": 5
		},
		"para_vertices": {
			"origin": {
				"x": 39,
				"y": 188
			},
			"height": 23,
			"width": 471
		},
		"word": "Date of Birth"
	}
}

Keywords

FAQs

Package last updated on 10 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc