forked from echamudi/opencv-wasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
37 lines (32 loc) · 1.24 KB
/
mod.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
import * as OpenCV from 'https://unpkg.com/[email protected]/types/opencv.ts';
import {cv as _cv} from 'https://unpkg.com/[email protected]/opencv-deno.js';
export const cv: typeof OpenCV = _cv;
/**
* Translate error number from OpenCV into a meaningful message
* @param cvObject OpenCV object
* @param err OpenCV error number
*/
export function cvTranslateError (cv: typeof OpenCV, err: any): string | Error | undefined {
// Code modified from OpenCV TryIt playground
// https://docs.opencv.org/3.4/d0/d84/tutorial_js_usage.html
let errorStatement: string | Error | undefined = undefined;
if (typeof err === 'undefined') {
errorStatement = '';
} else if (typeof err === 'number') {
if (!isNaN(err)) {
if (typeof cv !== 'undefined') {
errorStatement = 'Exception: ' + cv.exceptionFromPtr(err).msg;
}
}
} else if (typeof err === 'string') {
let ptr = Number(err.split(' ')[0]);
if (!isNaN(ptr)) {
if (typeof cv !== 'undefined') {
errorStatement = 'Exception: ' + cv.exceptionFromPtr(ptr).msg;
}
}
} else if (err instanceof Error) {
errorStatement = err;
}
return errorStatement;
}