-
Notifications
You must be signed in to change notification settings - Fork 11
/
SuccessFrameGrabberRecognizer.ts
79 lines (72 loc) · 2.29 KB
/
SuccessFrameGrabberRecognizer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Copyright (c) Microblink Ltd. All rights reserved.
*/
import
{
Recognizer,
RecognizerResult,
WasmSDK,
ImageOrientation
} from "../MicroblinkSDK/DataStructures";
/**
* The result object of the SuccessFrameGrabberRecognizer.
*/
export interface SuccessFrameGrabberRecognizerResult extends RecognizerResult
{
/**
* Camera frame on which given recognizer's result ha become valid.
* If given recognizer's result never became valid, contains null.
*/
readonly successFrame: ImageData | null;
/**
* Orientation of the success frame.
*/
readonly frameOrientation: ImageOrientation;
}
/**
* Recognizer that can wrap another recognizer and capture the frame on which
* the wrapped recognizer has succeeded to recognize.
*/
export interface SuccessFrameGrabberRecognizer< T extends Recognizer > extends Recognizer
{
/**
* Reference to recognizer that is being wrapped by this
* SuccessFrameGrabberRecognizer.
*/
readonly wrappedRecognizer: T;
/**
* Returns the current result of the recognition. Note that result will not
* contain the result of the wrapped recognizer. To obtain that result, call
* getResult on wrapped recognizer.
*/
getResult(): Promise< SuccessFrameGrabberRecognizerResult >;
/**
* Cleans up the object from the WebAssembly heap.
*/
delete(): Promise< void >;
}
/**
* Creates a new instance of `SuccessFrameGrabberRecognizer`.
* @param wasmSDK Instance of WasmSDK which will be used to communicate with the
* WebAssembly module.
* @param slaveRecognizer Instance of Recognizer that will be wrapped.
*/
export async function createSuccessFrameGrabberRecognizer< T extends Recognizer >
(
wasmSDK: WasmSDK,
slaveRecognizer: T
): Promise< SuccessFrameGrabberRecognizer < T > >
{
// taken from https://stackoverflow.com/a/53615996
const sfgr = await wasmSDK.mbWasmModule.newRecognizer
(
"SuccessFrameGrabberRecognizer",
slaveRecognizer
) as SuccessFrameGrabberRecognizer< T >;
type MutableSFGR = {
-readonly [ K in keyof SuccessFrameGrabberRecognizer< T > ]: SuccessFrameGrabberRecognizer< T >[ K ]
}
const mutableSFGR: MutableSFGR = sfgr;
mutableSFGR.wrappedRecognizer = slaveRecognizer;
return sfgr;
}