@udarrr/template-matcher
Advanced tools
Comparing version 2.0.1 to 2.0.4
@@ -1,2 +0,2 @@ | ||
import { MatchResult } from '@nut-tree/nut-js'; | ||
import { MatchResult, Region } from '@nut-tree/nut-js'; | ||
import { Mat, Point2, Vec3 } from 'opencv4nodejs-prebuilt-install'; | ||
@@ -13,3 +13,3 @@ export declare enum MethodEnum { | ||
export type MatchedResults = { | ||
results: Array<MatchResult>; | ||
results: Array<MatchResult<Region>>; | ||
haystack: Mat; | ||
@@ -19,3 +19,3 @@ }; | ||
static matchImages(haystack: Mat, needle: Mat, matchedMethod: MethodNameType, debug?: boolean): Promise<{ | ||
data: MatchResult; | ||
data: MatchResult<Region>; | ||
haystack: { | ||
@@ -22,0 +22,0 @@ minVal: number; |
import { Image, ImageFinderInterface, MatchRequest, MatchResult, Region } from '@nut-tree/nut-js'; | ||
import { MethodNameType } from './match-image.function'; | ||
type CustomOptionsType = { | ||
export type CustomOptionsType = { | ||
methodType?: MethodNameType; | ||
@@ -19,7 +19,7 @@ searchMultipleScales?: boolean; | ||
private initData; | ||
findMatches<CustomOptionsType>(matchRequest: MatchRequest<Image | string, CustomOptionsType>): Promise<MatchResult[]>; | ||
findMatches<CustomOptionsType>(matchRequest: MatchRequest<Image | string, CustomOptionsType>): Promise<MatchResult<Region>[]>; | ||
private getIncreasedRectByPixelDensity; | ||
private getDecreasedRectByPixelDensity; | ||
private getValidatedMatches; | ||
findMatch<CustomOptionsType>(matchRequest: MatchRequest<Image | string, CustomOptionsType>): Promise<MatchResult>; | ||
findMatch<CustomOptionsType>(matchRequest: MatchRequest<Image | string, CustomOptionsType>): Promise<MatchResult<Region>>; | ||
private searchMultipleScales; | ||
@@ -29,3 +29,2 @@ private scaleHaystack; | ||
} | ||
export {}; | ||
//# sourceMappingURL=template-matching-finder.class.d.ts.map |
{ | ||
"name": "@udarrr/template-matcher", | ||
"version": "2.0.1", | ||
"version": "2.0.4", | ||
"main": "dist/index", | ||
@@ -54,8 +54,8 @@ "typings": "dist/index", | ||
"dependencies": { | ||
"opencv4nodejs-prebuilt-install": "^4.1.146", | ||
"@nut-tree/nut-js": "^3.1.1" | ||
"opencv4nodejs-prebuilt-install": "^4.1.148", | ||
"@nut-tree/nut-js": "^3.1.2" | ||
}, | ||
"engines": { | ||
"node": ">=12.0.0 <20.0.0" | ||
"node": ">=12.0.0 <21.0.0" | ||
} | ||
} |
113
README.md
@@ -7,11 +7,6 @@ # OpenCV 4.1.1 Template Matching Image Finder | ||
### It's plugin for [nutjs project](https://www.npmjs.com/package/@nut-tree/nut-js) or standalone with some features like | ||
## It's either standalone or plugin for [nutjs project](https://www.npmjs.com/package/@nut-tree/nut-js) | ||
- increased accuracy | ||
- increased performance | ||
- added some customOptions for arguments `providerData` in [nutjs](https://github.com/nut-tree/nut.js/blob/develop/lib/optionalsearchparameters.class.ts) implemented in nutjs > version 3, also available in standalone | ||
- added standalone | ||
### Installation for standalone | ||
#### Installation for nutjs | ||
```nodejs | ||
@@ -21,10 +16,4 @@ npm i @udarrr/template-matcher | ||
and then just use it in your project once | ||
### Installation for nutjs | ||
```javascript | ||
import "@udarrr/template-matcher"` or `require("@udarrr/template-matcher") | ||
``` | ||
#### Installation for standalone | ||
```nodejs | ||
@@ -34,23 +23,13 @@ npm i @udarrr/template-matcher | ||
and connect finder to your project | ||
### Options findMatch,findMatches | ||
```javascript | ||
import finder from "@udarrr/template-matcher"; | ||
#### Standalone | ||
//some examples | ||
const matcheImages = await finder.findMatch({haystack: pathToImage, needle: pathToTemplate}); | ||
const matcheWithScreen = await finder.findMatch({needle: pathToTemplate}); | ||
const matchesImages = await finder.findMatches({haystack: pathToImage, needle: pathToTemplate}); | ||
const matchesWithScreen = await finder.findMatches({needle: pathToTemplate}); | ||
``` | ||
#### Options | ||
```javascript | ||
//@udarrr/template-matcher@2.0.1 with nutjs 3.1.1 options | ||
```typescript | ||
{ | ||
haystack?: string | Image, | ||
needle: string | Image, | ||
confidence?: number, | ||
providerData?: { | ||
searchMultipleScales?: boolean, | ||
searchMultipleScales?: boolean, | ||
customOptions?: { | ||
methodType?: MethodNameType; | ||
@@ -65,24 +44,60 @@ scaleSteps?: Array<number>; | ||
```typescript | ||
//standalone @udarrr/template-matcher@2.0.1 | ||
import finder from "@udarrr/template-matcher"; | ||
(async () => { | ||
const matcheImages = await finder.findMatch({haystack: 'pathToImage', needle: 'pathToTemplate'}); | ||
const matcheWithScreen = await finder.findMatch({needle: pathToTemplate}); | ||
const matchesImages = await finder.findMatches({haystack: 'pathToImage', needle: 'pathToTemplate'}); | ||
const matchesWithScreen = await finder.findMatches({needle: 'pathToTemplate'}); | ||
})(); | ||
``` | ||
### Nutjs v3 | ||
```nodejs | ||
npm i @udarrr/template-matcher@2.0.4 | ||
``` | ||
```typescript | ||
{ | ||
haystack?: string | Image, | ||
needle: string | Image, | ||
confidence?: number, | ||
providerData?: { | ||
searchMultipleScales?: boolean, | ||
methodType?: MethodNameType; | ||
scaleSteps?: Array<number>; | ||
roi?: Region; | ||
debug?: boolean | ||
}, | ||
} | ||
providerData?: { | ||
searchMultipleScales?: boolean; | ||
methodType?: MethodNameType; | ||
scaleSteps?: Array<number>; | ||
roi?: Region; | ||
debug?: boolean; | ||
}; | ||
}; | ||
``` | ||
```javascript | ||
// methodType: "TM_CCOEFF" | "TM_CCOEFF_NORMED" | "TM_CCORR" | "TM_CCORR_NORMED" | "TM_SQDIFF" | "TM_SQDIFF_NORMED" by default "TM_CCOEFF_NORMED" | ||
// scaleSteps: [0.9]; by default [1, 0.9, 0.8, 0.7, 0.6, 0.5] | ||
// debug: true | false by default false | ||
```typescript | ||
import { imageResource, screen } from '@nut-tree/nut-js'; | ||
import { CustomOptionsType } from '@udarrr/template-matcher/lib/template-matching-finder.class'; | ||
import "@udarrr/template-matcher"; //once wherever | ||
// for "TM_SQDIFF" | "TM_SQDIFF_NORMED" confidence by default 0.98 | ||
// for "TM_CCOEFF" | "TM_CCOEFF_NORMED" | "TM_CCORR" | "TM_CCORR_NORMED" by default 0.8 | ||
(async () => { | ||
const img = await screen.find<CustomOptionsType>(imageResource("path"),{ providerData: {...}}); | ||
const imgs = await screen.findAll<CustomOptionsType>(imageResource("path"),{ providerData: {...}}); | ||
})(); | ||
``` | ||
#### Values by default | ||
```typescript | ||
methodType: "TM_CCOEFF" | "TM_CCOEFF_NORMED" | "TM_CCORR" | "TM_CCORR_NORMED" | "TM_SQDIFF" | "TM_SQDIFF_NORMED" by default "TM_CCOEFF_NORMED" | ||
scaleSteps: [0.9]; by default [1, 0.9, 0.8, 0.7, 0.6, 0.5] | ||
debug: true | false by default false | ||
confidence: for "TM_SQDIFF" | "TM_SQDIFF_NORMED" confidence by default 0.98 for "TM_CCOEFF" | "TM_CCOEFF_NORMED" | "TM_CCORR" | "TM_CCORR_NORMED" by default 0.8 | ||
``` | ||
#### Disclaimer for nutjs v3 | ||
In case using the package with [nutjs](https://github.com/nut-tree/nut.js/blob/develop/lib/optionalsearchparameters.class.ts) v3 or above please use precise 2.0.2 version of the package it could be prevented in package.json lile | ||
```json | ||
"@udarrr/template-matcher": "~2.0.4", | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
68751
100
528