ms-types 0.9.19 → 0.9.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,715 @@
1
+ /**
2
+ * OpenCV 精简绑定(仅 JS)。Mat 以句柄字符串暴露,复杂参数优先用 Object。
3
+ * 这不是完整 cv2,只覆盖手机端高频能力。无中文方法别名,模块名仅为 `cv`。
4
+ *
5
+ * @example
6
+ * const src = cv.capture()
7
+ * const gray = cv.cvtColor(src, { code: cv.COLOR_BGR2GRAY })
8
+ * const edges = cv.Canny(gray, { threshold1: 100, threshold2: 200 })
9
+ * cv.imwrite('/tmp/e.png', edges)
10
+ * cv.release(src); cv.release(gray); cv.release(edges)
11
+ */
12
+ declare namespace cv {
13
+ /** Mat 句柄,形如 `$CV_MAT$_…` */
14
+ type Mat = string;
15
+
16
+ interface Point {
17
+ x: number;
18
+ y: number;
19
+ }
20
+
21
+ interface Size {
22
+ width: number;
23
+ height: number;
24
+ }
25
+
26
+ interface Rect {
27
+ x: number;
28
+ y: number;
29
+ width: number;
30
+ height: number;
31
+ }
32
+
33
+ interface MatInfo extends Size {
34
+ channels: number;
35
+ type: number;
36
+ rows: number;
37
+ cols: number;
38
+ }
39
+
40
+ interface MinMaxLocResult {
41
+ minVal: number;
42
+ maxVal: number;
43
+ minLoc: Point;
44
+ maxLoc: Point;
45
+ }
46
+
47
+ interface MatchLocResult {
48
+ x: number;
49
+ y: number;
50
+ minVal: number;
51
+ maxVal: number;
52
+ }
53
+
54
+ interface RotatedRect {
55
+ center: Point;
56
+ size: Size;
57
+ angle: number;
58
+ }
59
+
60
+ interface ThresholdOptions {
61
+ thresh?: number;
62
+ maxval?: number;
63
+ type?: number;
64
+ }
65
+
66
+ interface AdaptiveThresholdOptions {
67
+ maxValue?: number;
68
+ adaptiveMethod?: number;
69
+ thresholdType?: number;
70
+ blockSize?: number;
71
+ C?: number;
72
+ }
73
+
74
+ interface InRangeOptions {
75
+ lowerb: number[];
76
+ upperb: number[];
77
+ }
78
+
79
+ interface BitwiseOptions {
80
+ src2: Mat;
81
+ mask?: Mat;
82
+ }
83
+
84
+ interface BlurOptions {
85
+ ksize: number | [number, number] | Size;
86
+ sigmaX?: number;
87
+ sigmaY?: number;
88
+ }
89
+
90
+ interface CannyOptions {
91
+ threshold1?: number;
92
+ threshold2?: number;
93
+ apertureSize?: number;
94
+ L2gradient?: boolean;
95
+ }
96
+
97
+ interface ResizeOptions {
98
+ width?: number;
99
+ height?: number;
100
+ fx?: number;
101
+ fy?: number;
102
+ interpolation?: number;
103
+ }
104
+
105
+ interface CropOptions {
106
+ x?: number;
107
+ y?: number;
108
+ ex?: number;
109
+ ey?: number;
110
+ }
111
+
112
+ interface DrawColorOptions {
113
+ color?: number[] | string;
114
+ thickness?: number;
115
+ }
116
+
117
+ interface RectangleOptions extends DrawColorOptions {
118
+ pt1: Point | [number, number];
119
+ pt2: Point | [number, number];
120
+ }
121
+
122
+ interface CircleOptions extends DrawColorOptions {
123
+ center: Point | [number, number];
124
+ radius: number;
125
+ }
126
+
127
+ interface LineOptions extends DrawColorOptions {
128
+ pt1: Point | [number, number];
129
+ pt2: Point | [number, number];
130
+ }
131
+
132
+ interface PutTextOptions extends DrawColorOptions {
133
+ text: string;
134
+ org: Point | [number, number];
135
+ fontFace?: number;
136
+ fontScale?: number;
137
+ }
138
+
139
+ interface MatchTemplateOptions {
140
+ method?: number;
141
+ mask?: Mat;
142
+ }
143
+
144
+ interface FindContoursOptions {
145
+ mode?: number;
146
+ method?: number;
147
+ }
148
+
149
+ interface MorphOptions {
150
+ kernel: Mat;
151
+ iterations?: number;
152
+ }
153
+
154
+ interface MorphologyExOptions extends MorphOptions {
155
+ op: number;
156
+ }
157
+
158
+ interface StructuringElementOptions {
159
+ shape?: number;
160
+ ksize: number | [number, number] | Size;
161
+ }
162
+
163
+ // ---- constants (常用子集) ----
164
+ const COLOR_BGR2GRAY: number;
165
+ const COLOR_GRAY2BGR: number;
166
+ const COLOR_BGR2RGB: number;
167
+ const COLOR_RGB2BGR: number;
168
+ const COLOR_BGR2HSV: number;
169
+ const COLOR_HSV2BGR: number;
170
+ const COLOR_BGRA2BGR: number;
171
+ const COLOR_BGR2BGRA: number;
172
+ const COLOR_BGRA2GRAY: number;
173
+ const COLOR_BGR2Lab: number;
174
+ const COLOR_Lab2BGR: number;
175
+
176
+ const THRESH_BINARY: number;
177
+ const THRESH_BINARY_INV: number;
178
+ const THRESH_OTSU: number;
179
+ const THRESH_TRUNC: number;
180
+ const THRESH_TOZERO: number;
181
+ const THRESH_TOZERO_INV: number;
182
+
183
+ const ADAPTIVE_THRESH_MEAN_C: number;
184
+ const ADAPTIVE_THRESH_GAUSSIAN_C: number;
185
+
186
+ const TM_SQDIFF: number;
187
+ const TM_SQDIFF_NORMED: number;
188
+ const TM_CCORR: number;
189
+ const TM_CCORR_NORMED: number;
190
+ const TM_CCOEFF: number;
191
+ const TM_CCOEFF_NORMED: number;
192
+
193
+ const RETR_EXTERNAL: number;
194
+ const RETR_LIST: number;
195
+ const RETR_CCOMP: number;
196
+ const RETR_TREE: number;
197
+ const CHAIN_APPROX_NONE: number;
198
+ const CHAIN_APPROX_SIMPLE: number;
199
+
200
+ const MORPH_RECT: number;
201
+ const MORPH_CROSS: number;
202
+ const MORPH_ELLIPSE: number;
203
+ const MORPH_ERODE: number;
204
+ const MORPH_DILATE: number;
205
+ const MORPH_OPEN: number;
206
+ const MORPH_CLOSE: number;
207
+ const MORPH_GRADIENT: number;
208
+ const MORPH_TOPHAT: number;
209
+ const MORPH_BLACKHAT: number;
210
+
211
+ const INTER_NEAREST: number;
212
+ const INTER_LINEAR: number;
213
+ const INTER_CUBIC: number;
214
+ const INTER_AREA: number;
215
+ const INTER_LANCZOS4: number;
216
+
217
+ const ROTATE_90_CLOCKWISE: number;
218
+ const ROTATE_180: number;
219
+ const ROTATE_90_COUNTERCLOCKWISE: number;
220
+
221
+ const BORDER_CONSTANT: number;
222
+ const BORDER_REPLICATE: number;
223
+ const BORDER_REFLECT: number;
224
+ const BORDER_REFLECT_101: number;
225
+ const BORDER_DEFAULT: number;
226
+
227
+ const IMREAD_COLOR: number;
228
+ const IMREAD_GRAYSCALE: number;
229
+ const IMREAD_UNCHANGED: number;
230
+
231
+ const FONT_HERSHEY_SIMPLEX: number;
232
+ const FONT_HERSHEY_PLAIN: number;
233
+ const FONT_HERSHEY_DUPLEX: number;
234
+ const FONT_HERSHEY_COMPLEX: number;
235
+
236
+ const CV_8UC1: number;
237
+ const CV_8UC3: number;
238
+ const CV_8UC4: number;
239
+ const CV_32FC1: number;
240
+ const CV_32FC3: number;
241
+
242
+ // ---- IO / 生命周期 ----
243
+ /** 截屏为 Mat;参数与 `image.captureScreen` 一致,无参全屏 */
244
+ function capture(
245
+ x?: number,
246
+ y?: number,
247
+ ex?: number,
248
+ ey?: number,
249
+ ): Mat | null;
250
+ /**
251
+ * 读取图片为 Mat 句柄。`cv` 中**唯一**支持路径类输入的加载入口(与 `image.readImage` 同源):
252
+ * msbundle/res 相对路径、手机绝对路径、`$MS_IMG$_…` imageId、`screen` / `shortcut` /
253
+ * `actionScreenshot`、HTTP(S)、`media:n`、`data:image/...;base64,...` 等。
254
+ * 其它算子只接受 Mat 句柄。
255
+ */
256
+ function imread(path: string): Mat | null;
257
+ /** 仅解码 base64 / data URI;路径与 imageId 请用 `imread` */
258
+ function imdecode(data: string): Mat | null;
259
+ function imwrite(path: string, mat: Mat): boolean;
260
+ function imencode(ext: string, mat: Mat, quality?: number): string | null;
261
+ function fromImageId(imageId: string): Mat | null;
262
+ function toImageId(mat: Mat): string | null;
263
+ function Mat(options: { rows: number; cols: number; type?: number; scalar?: number[] }): Mat | null;
264
+ function zeros(options: { rows: number; cols: number; type?: number }): Mat | null;
265
+ function ones(options: { rows: number; cols: number; type?: number }): Mat | null;
266
+ function clone(mat: Mat): Mat | null;
267
+ function empty(mat: Mat): boolean;
268
+ function isRelease(mat: Mat): boolean;
269
+ function release(mat: Mat): void;
270
+ function releaseAll(): void;
271
+ function getSize(mat: Mat): MatInfo | null;
272
+ function at(mat: Mat, row: number, col: number): number[] | null;
273
+ function set(mat: Mat, options: { row: number; col: number; value: number | number[] }): boolean;
274
+ function copyTo(mat: Mat, mask?: Mat | null): Mat | null;
275
+
276
+ // ---- 颜色 / 运算 ----
277
+ function cvtColor(mat: Mat, code: number): Mat | null;
278
+ function threshold(mat: Mat, options: ThresholdOptions): Mat | null;
279
+ function adaptiveThreshold(mat: Mat, options: AdaptiveThresholdOptions): Mat | null;
280
+ function inRange(mat: Mat, options: InRangeOptions): Mat | null;
281
+ function bitwise_and(src1: Mat, options: BitwiseOptions): Mat | null;
282
+ function bitwise_or(src1: Mat, options: BitwiseOptions): Mat | null;
283
+ function bitwise_xor(src1: Mat, options: BitwiseOptions): Mat | null;
284
+ function bitwise_not(mat: Mat, options?: { mask?: Mat }): Mat | null;
285
+ function absdiff(src1: Mat, options: { src2: Mat }): Mat | null;
286
+ function addWeighted(src1: Mat, options: { src2: Mat; alpha?: number; beta?: number; gamma?: number }): Mat | null;
287
+ function convertScaleAbs(mat: Mat, options?: { alpha?: number; beta?: number }): Mat | null;
288
+ function countNonZero(mat: Mat): number;
289
+ function minMaxLoc(mat: Mat, options?: { mask?: Mat }): MinMaxLocResult | null;
290
+ function mean(mat: Mat, options?: { mask?: Mat }): number[] | null;
291
+ function split(mat: Mat): Mat[] | null;
292
+ function merge(channels: Mat[]): Mat | null;
293
+
294
+ // ---- 滤波 / 边缘 ----
295
+ function GaussianBlur(mat: Mat, options: BlurOptions): Mat | null;
296
+ function blur(mat: Mat, options: { ksize: number | [number, number] | Size }): Mat | null;
297
+ function medianBlur(mat: Mat, options: { ksize: number }): Mat | null;
298
+ function bilateralFilter(mat: Mat, options: { d?: number; sigmaColor?: number; sigmaSpace?: number }): Mat | null;
299
+ function Canny(mat: Mat, options: CannyOptions): Mat | null;
300
+ function Sobel(mat: Mat, options: { ddepth?: number; dx?: number; dy?: number; ksize?: number; scale?: number; delta?: number }): Mat | null;
301
+ function Laplacian(mat: Mat, options: { ddepth?: number; ksize?: number; scale?: number; delta?: number }): Mat | null;
302
+ function equalizeHist(mat: Mat): Mat | null;
303
+
304
+ // ---- 几何 / 绘制 ----
305
+ function resize(mat: Mat, options: ResizeOptions): Mat | null;
306
+ function crop(mat: Mat, options: CropOptions): Mat | null;
307
+ function rotate(mat: Mat, rotateCode: number): Mat | null;
308
+ function flip(mat: Mat, flipCode: number): Mat | null;
309
+ function copyMakeBorder(mat: Mat, options: { top?: number; bottom?: number; left?: number; right?: number; borderType?: number; value?: number[] }): Mat | null;
310
+ function getRotationMatrix2D(options: { center: Point | [number, number]; angle?: number; scale?: number }): Mat | null;
311
+ function warpAffine(mat: Mat, options: { M: Mat; width?: number; height?: number; flags?: number }): Mat | null;
312
+ /** 就地绘制,返回同一句柄 */
313
+ function rectangle(mat: Mat, options: RectangleOptions): Mat | null;
314
+ function circle(mat: Mat, options: CircleOptions): Mat | null;
315
+ function line(mat: Mat, options: LineOptions): Mat | null;
316
+ function putText(mat: Mat, options: PutTextOptions): Mat | null;
317
+ function fillPoly(mat: Mat, options: { pts: Point[][] | Point[]; color?: number[] | string }): Mat | null;
318
+ function polylines(mat: Mat, options: { pts: Point[][] | Point[]; isClosed?: boolean; color?: number[] | string; thickness?: number }): Mat | null;
319
+ function drawContours(mat: Mat, options: { contours: Point[][]; contourIdx?: number; color?: number[] | string; thickness?: number }): Mat | null;
320
+
321
+ // ---- 匹配 / 轮廓 / 形态学 ----
322
+ function matchTemplate(image: Mat, templ: Mat, options?: MatchTemplateOptions): Mat | null;
323
+ function matchTemplateLoc(image: Mat, templ: Mat, options?: MatchTemplateOptions): MatchLocResult | null;
324
+ function findContours(mat: Mat, options?: FindContoursOptions): { contours: Point[][]; hierarchy: number[][] } | null;
325
+ function boundingRect(matOrPoints: Mat | Point[]): Rect | null;
326
+ function minAreaRect(points: Point[]): RotatedRect | null;
327
+ function contourArea(matOrPoints: Mat | Point[], oriented?: boolean): number;
328
+ function arcLength(points: Point[], closed?: boolean): number;
329
+ function approxPolyDP(points: Point[], options: { epsilon?: number; closed?: boolean }): Point[] | null;
330
+ function erode(mat: Mat, options: MorphOptions): Mat | null;
331
+ function dilate(mat: Mat, options: MorphOptions): Mat | null;
332
+ function morphologyEx(mat: Mat, options: MorphologyExOptions): Mat | null;
333
+ function getStructuringElement(options: StructuringElementOptions): Mat | null;
334
+
335
+ // ---- 特征点 / 匹配 / 单应 ----
336
+ interface KeyPoint {
337
+ x: number;
338
+ y: number;
339
+ size: number;
340
+ angle: number;
341
+ response: number;
342
+ octave: number;
343
+ class_id: number;
344
+ }
345
+
346
+ interface DMatch {
347
+ queryIdx: number;
348
+ trainIdx: number;
349
+ distance: number;
350
+ }
351
+
352
+ interface FeatureResult {
353
+ keypoints: KeyPoint[];
354
+ /** 描述子 Mat 句柄;失败时可能为 null */
355
+ descriptors: Mat | null;
356
+ }
357
+
358
+ interface SIFTOptions {
359
+ nfeatures?: number;
360
+ nOctaveLayers?: number;
361
+ contrastThreshold?: number;
362
+ edgeThreshold?: number;
363
+ sigma?: number;
364
+ mask?: Mat;
365
+ }
366
+
367
+ interface ORBOptions {
368
+ nfeatures?: number;
369
+ scaleFactor?: number;
370
+ nlevels?: number;
371
+ mask?: Mat;
372
+ }
373
+
374
+ interface FASTOptions {
375
+ threshold?: number;
376
+ nonmaxSuppression?: boolean;
377
+ mask?: Mat;
378
+ }
379
+
380
+ interface MatcherOptions {
381
+ queryDescriptors?: Mat;
382
+ trainDescriptors?: Mat;
383
+ normType?: number;
384
+ crossCheck?: boolean;
385
+ }
386
+
387
+ interface KnnMatchOptions extends MatcherOptions {
388
+ k?: number;
389
+ /** Lowe ratio test,例如 0.75;设置后只返回通过筛选的最近邻 */
390
+ ratio?: number;
391
+ }
392
+
393
+ interface DrawKeypointsOptions {
394
+ keypoints: KeyPoint[];
395
+ color?: number[] | string;
396
+ }
397
+
398
+ interface DrawMatchesOptions {
399
+ img2: Mat;
400
+ keypoints1: KeyPoint[];
401
+ keypoints2: KeyPoint[];
402
+ matches1to2: DMatch[];
403
+ }
404
+
405
+ interface FindHomographyOptions {
406
+ srcPoints: Point[];
407
+ dstPoints: Point[];
408
+ method?: number;
409
+ ransacReprojThreshold?: number;
410
+ }
411
+
412
+ interface WarpPerspectiveOptions {
413
+ M: Mat;
414
+ width?: number;
415
+ height?: number;
416
+ flags?: number;
417
+ }
418
+
419
+ interface GoodFeaturesOptions {
420
+ maxCorners?: number;
421
+ qualityLevel?: number;
422
+ minDistance?: number;
423
+ mask?: Mat;
424
+ }
425
+
426
+ interface HoughLinesPOptions {
427
+ rho?: number;
428
+ theta?: number;
429
+ threshold?: number;
430
+ minLineLength?: number;
431
+ maxLineGap?: number;
432
+ }
433
+
434
+ interface HoughCirclesOptions {
435
+ method?: number;
436
+ dp?: number;
437
+ minDist?: number;
438
+ param1?: number;
439
+ param2?: number;
440
+ minRadius?: number;
441
+ maxRadius?: number;
442
+ }
443
+
444
+ interface CLAHEOptions {
445
+ clipLimit?: number;
446
+ tileGridSize?: number | [number, number] | Size;
447
+ }
448
+
449
+ interface FloodFillOptions {
450
+ seedPoint: Point | [number, number];
451
+ newVal: number[] | string;
452
+ loDiff?: number[] | string;
453
+ upDiff?: number[] | string;
454
+ }
455
+
456
+ interface MomentsResult {
457
+ m00: number;
458
+ m10: number;
459
+ m01: number;
460
+ m20: number;
461
+ m11: number;
462
+ m02: number;
463
+ mu20: number;
464
+ mu11: number;
465
+ mu02: number;
466
+ nu20: number;
467
+ nu11: number;
468
+ nu02: number;
469
+ }
470
+
471
+ interface ConnectedComponentsResult {
472
+ count: number;
473
+ labels: Mat | null;
474
+ stats: Mat | null;
475
+ centroids: Mat | null;
476
+ }
477
+
478
+ const NORM_L1: number;
479
+ const NORM_L2: number;
480
+ const NORM_HAMMING: number;
481
+ const NORM_HAMMING2: number;
482
+ const RANSAC: number;
483
+ const LMEDS: number;
484
+ const RHO: number;
485
+ const HOUGH_GRADIENT: number;
486
+ const HOUGH_GRADIENT_ALT: number;
487
+ const DIST_L1: number;
488
+ const DIST_L2: number;
489
+ const DIST_C: number;
490
+ const DIST_MASK_3: number;
491
+ const DIST_MASK_5: number;
492
+ const CONTOURS_MATCH_I1: number;
493
+ const CONTOURS_MATCH_I2: number;
494
+ const CONTOURS_MATCH_I3: number;
495
+ const CC_STAT_LEFT: number;
496
+ const CC_STAT_TOP: number;
497
+ const CC_STAT_WIDTH: number;
498
+ const CC_STAT_HEIGHT: number;
499
+ const CC_STAT_AREA: number;
500
+
501
+ /**
502
+ * SIFT 检测并计算描述子。
503
+ * @example
504
+ * const { keypoints, descriptors } = cv.SIFT(src, { nfeatures: 500 })
505
+ */
506
+ function SIFT(mat: Mat, options?: SIFTOptions): FeatureResult | null;
507
+ /** ORB 检测并计算描述子(二进制描述子,匹配常用 NORM_HAMMING) */
508
+ function ORB(mat: Mat, options?: ORBOptions): FeatureResult | null;
509
+ /** FAST 仅返回关键点(无描述子) */
510
+ function FAST(mat: Mat, options?: FASTOptions): { keypoints: KeyPoint[] } | null;
511
+
512
+ /** 暴力匹配描述子,返回 DMatch 数组 */
513
+ function BFMatcher(queryDescriptors: Mat, trainDescriptors: Mat, options?: MatcherOptions): DMatch[] | null;
514
+ /** K 近邻匹配;可设 ratio 做 Lowe 筛选 */
515
+ function knnMatch(queryDescriptors: Mat, trainDescriptors: Mat, options?: KnnMatchOptions): DMatch[][] | null;
516
+
517
+ /** 绘制关键点,返回新 Mat 句柄 */
518
+ function drawKeypoints(mat: Mat, options: DrawKeypointsOptions): Mat | null;
519
+ /** 绘制匹配连线 */
520
+ function drawMatches(mat: Mat, options: DrawMatchesOptions): Mat | null;
521
+
522
+ /** 计算单应矩阵,返回 3x3 Mat 句柄 */
523
+ function findHomography(options: FindHomographyOptions): Mat | null;
524
+ /** 透视变换图像 */
525
+ function warpPerspective(mat: Mat, options: WarpPerspectiveOptions): Mat | null;
526
+ /** 用单应矩阵变换点集 */
527
+ function perspectiveTransform(points: Point[], options: { M: Mat }): Point[] | null;
528
+
529
+ /** Shi-Tomasi 角点 */
530
+ function goodFeaturesToTrack(mat: Mat, options: GoodFeaturesOptions): Point[] | null;
531
+ /** 概率霍夫直线,返回 {x1,y1,x2,y2}[] */
532
+ function HoughLinesP(mat: Mat, options: HoughLinesPOptions): Array<{ x1: number; y1: number; x2: number; y2: number }> | null;
533
+ /** 霍夫圆,返回 {x,y,radius}[] */
534
+ function HoughCircles(mat: Mat, options: HoughCirclesOptions): Array<{ x: number; y: number; radius: number }> | null;
535
+
536
+ /** CLAHE 对比度受限自适应直方图均衡 */
537
+ function CLAHE(mat: Mat, options?: CLAHEOptions): Mat | null;
538
+ function pyrDown(mat: Mat): Mat | null;
539
+ function pyrUp(mat: Mat): Mat | null;
540
+ function Scharr(mat: Mat, options: { ddepth?: number; dx?: number; dy?: number; scale?: number; delta?: number }): Mat | null;
541
+ function boxFilter(mat: Mat, options: { ksize: number | [number, number] | Size; ddepth?: number }): Mat | null;
542
+ /** 就地洪水填充,返回填充像素数与外接矩形 */
543
+ function floodFill(mat: Mat, options: FloodFillOptions): { filled: number; rect: Rect } | null;
544
+ function convexHull(points: Point[], options?: { clockwise?: boolean }): Point[] | null;
545
+ function moments(matOrPoints: Mat | Point[], options?: { binaryImage?: boolean }): MomentsResult | null;
546
+ function matchShapes(contour1: Mat | Point[], contour2: Mat | Point[], options?: { method?: number; parameter?: number }): number;
547
+ function connectedComponentsWithStats(mat: Mat): ConnectedComponentsResult | null;
548
+ function distanceTransform(mat: Mat, options?: { distanceType?: number; maskSize?: number }): Mat | null;
549
+
550
+ // ---- 算术 / 归一化 / 拼接 ----
551
+ function add(src1: Mat, options: { src2: Mat; mask?: Mat }): Mat | null;
552
+ function subtract(src1: Mat, options: { src2: Mat; mask?: Mat }): Mat | null;
553
+ function multiply(src1: Mat, options: { src2: Mat; scale?: number }): Mat | null;
554
+ function divide(src1: Mat, options: { src2: Mat; scale?: number }): Mat | null;
555
+ function normalize(mat: Mat, options?: { alpha?: number; beta?: number; normType?: number }): Mat | null;
556
+ function norm(mat: Mat, options?: { normType?: number; mask?: Mat; src2?: Mat }): number;
557
+ function meanStdDev(mat: Mat, options?: { mask?: Mat }): { mean: number[]; stddev: number[] } | null;
558
+ function findNonZero(mat: Mat): Point[] | null;
559
+ function hconcat(mats: Mat[]): Mat | null;
560
+ function vconcat(mats: Mat[]): Mat | null;
561
+
562
+ // ---- 已知点变换矩阵 ----
563
+ function getPerspectiveTransform(options: { srcPoints: Point[]; dstPoints: Point[] }): Mat | null;
564
+ function getAffineTransform(options: { srcPoints: Point[]; dstPoints: Point[] }): Mat | null;
565
+
566
+ // ---- Flann(SIFT 推荐,与 image 找图同源)----
567
+ function FlannBasedMatcher(queryDescriptors: Mat, trainDescriptors: Mat): DMatch[] | null;
568
+ function flannKnnMatch(queryDescriptors: Mat, trainDescriptors: Mat, options?: { k?: number; ratio?: number }): DMatch[][] | null;
569
+
570
+ // ---- 直方图 ----
571
+ function calcHist(mat: Mat, options?: {
572
+ channels?: number[];
573
+ histSize?: number[];
574
+ ranges?: number[];
575
+ mask?: Mat;
576
+ accumulate?: boolean;
577
+ }): Mat | null;
578
+ function compareHist(H1: Mat, H2: Mat, options?: { method?: number }): number;
579
+
580
+ // ---- 轮廓几何配套 ----
581
+ function boxPoints(options: { center: Point; size: Size | [number, number]; angle?: number }): Point[] | null;
582
+ function pointPolygonTest(contour: Point[], ptOrOptions: Point | { pt: Point; measureDist?: boolean }): number;
583
+ function minEnclosingCircle(points: Point[]): { center: Point; radius: number } | null;
584
+ /** 椭圆拟合,至少 5 个点;可用于圆形/椭圆控件轮廓 */
585
+ function fitEllipse(points: Point[]): RotatedRect | null;
586
+ function filter2D(mat: Mat, options: { kernel: Mat; ddepth?: number; delta?: number }): Mat | null;
587
+ function ellipse(mat: Mat, options: {
588
+ center: Point;
589
+ axes: Size | [number, number];
590
+ angle?: number;
591
+ startAngle?: number;
592
+ endAngle?: number;
593
+ color?: number[] | string;
594
+ thickness?: number;
595
+ }): Mat | null;
596
+ function getTextSize(options: {
597
+ text: string;
598
+ fontFace?: number;
599
+ fontScale?: number;
600
+ thickness?: number;
601
+ }): { width: number; height: number; baseLine: number } | null;
602
+
603
+ // ---- QR / 条码 ----
604
+ /** 编码二维码为可显示/可识别的 BGR Mat(已放大并加静区,可直接 detectQRCode) */
605
+ function encodeQRCode(text: string): Mat | null;
606
+ function detectQRCode(mat: Mat): { decoded: string; points: Point[] } | null;
607
+ function detectBarcode(mat: Mat): { decoded: string[]; types: string[]; points: Point[] } | null;
608
+
609
+ // ---- Photo ----
610
+ function inpaint(mat: Mat, options: { mask: Mat; inpaintRadius?: number; flags?: number }): Mat | null;
611
+ function fastNlMeansDenoising(mat: Mat, options?: {
612
+ h?: number; templateWindowSize?: number; searchWindowSize?: number;
613
+ }): Mat | null;
614
+ function fastNlMeansDenoisingColored(mat: Mat, options?: {
615
+ h?: number; hColor?: number; templateWindowSize?: number; searchWindowSize?: number;
616
+ }): Mat | null;
617
+
618
+ // ---- Core 扩展 ----
619
+ function LUT(mat: Mat, options: { lut: Mat }): Mat | null;
620
+ function compare(src1: Mat, options: { src2: Mat; cmpop: number }): Mat | null;
621
+ function min(src1: Mat, options: { src2: Mat }): Mat | null;
622
+ function max(src1: Mat, options: { src2: Mat }): Mat | null;
623
+ function extractChannel(mat: Mat, options: { coi: number }): Mat | null;
624
+ function sum(mat: Mat): number[] | null;
625
+
626
+ // ---- Imgproc 几何 / 滤波扩展 ----
627
+ function invertAffineTransform(M: Mat): Mat | null;
628
+ function getRectSubPix(mat: Mat, options: {
629
+ patchSize: Size | [number, number]; center: Point;
630
+ }): Mat | null;
631
+ /** 相位相关估计两图位移(如滚动/拖拽前后帧) */
632
+ function phaseCorrelate(src1: Mat, options: { src2: Mat; window?: Mat }): {
633
+ x: number; y: number; response?: number;
634
+ } | null;
635
+ function cornerHarris(mat: Mat, options?: { blockSize?: number; ksize?: number; k?: number }): Mat | null;
636
+ function cornerSubPix(mat: Mat, options: {
637
+ corners: Point[];
638
+ winSize?: Size | [number, number];
639
+ zeroZone?: Size | [number, number];
640
+ criteria?: { type?: number; maxCount?: number; epsilon?: number };
641
+ }): Point[] | null;
642
+ function calcBackProject(mat: Mat, options: {
643
+ hist: Mat; channels?: number[]; ranges?: number[]; scale?: number;
644
+ }): Mat | null;
645
+ function HuMoments(contourOrMoments: Point[] | MomentsResult): number[] | null;
646
+ function connectedComponents(mat: Mat, options?: { connectivity?: number }): {
647
+ count: number; labels: Mat;
648
+ } | null;
649
+ function convexityDefects(contour: Point[], options: {
650
+ hull: number[] | Point[];
651
+ }): Array<{ start: number; end: number; farthest: number; depth: number }> | null;
652
+ function isContourConvex(contour: Point[]): boolean;
653
+ function fitLine(points: Point[], options?: {
654
+ distType?: number; param?: number; reps?: number; aeps?: number;
655
+ }): [number, number, number, number] | null;
656
+
657
+ /** 就地绘制标记点,返回原句柄 */
658
+ function drawMarker(mat: Mat, options: {
659
+ position: Point; color?: number[] | string;
660
+ markerType?: number; markerSize?: number; thickness?: number;
661
+ }): Mat | null;
662
+ /** 就地画箭头线,返回原句柄 */
663
+ function arrowedLine(mat: Mat, options: {
664
+ pt1: Point; pt2: Point; color?: number[] | string; thickness?: number; tipLength?: number;
665
+ }): Mat | null;
666
+ /** 就地填充凸多边形,返回原句柄 */
667
+ function fillConvexPoly(mat: Mat, options: {
668
+ pts: Point[]; color?: number[] | string;
669
+ }): Mat | null;
670
+
671
+ // ---- Calib3d ----
672
+ function estimateAffine2D(options: {
673
+ srcPoints: Point[]; dstPoints: Point[]; method?: number; ransacReprojThreshold?: number;
674
+ }): Mat | null;
675
+ /** 相似变换(平移+旋转+等比缩放,无剪切),点对齐/跨分辨率匹配常用 */
676
+ function estimateAffinePartial2D(options: {
677
+ srcPoints: Point[]; dstPoints: Point[]; method?: number; ransacReprojThreshold?: number;
678
+ }): Mat | null;
679
+
680
+ // ---- Features 扩展 ----
681
+
682
+ // ---- Objdetect ----
683
+
684
+ const COLOR_RGB2GRAY: number;
685
+ const COLOR_RGBA2GRAY: number;
686
+ const LINE_4: number;
687
+ const LINE_8: number;
688
+ const LINE_AA: number;
689
+ const FILLED: number;
690
+ const HISTCMP_CORREL: number;
691
+ const HISTCMP_CHISQR: number;
692
+ const HISTCMP_INTERSECT: number;
693
+ const HISTCMP_BHATTACHARYYA: number;
694
+ const HISTCMP_CHISQR_ALT: number;
695
+ const HISTCMP_KL_DIV: number;
696
+ const NORM_INF: number;
697
+ const NORM_MINMAX: number;
698
+
699
+ const INPAINT_NS: number;
700
+ const INPAINT_TELEA: number;
701
+ const CMP_EQ: number;
702
+ const CMP_GT: number;
703
+ const CMP_GE: number;
704
+ const CMP_LT: number;
705
+ const CMP_LE: number;
706
+ const CMP_NE: number;
707
+ const MORPH_HITMISS: number;
708
+ const MARKER_CROSS: number;
709
+ const MARKER_TILTED_CROSS: number;
710
+ const MARKER_STAR: number;
711
+ const MARKER_DIAMOND: number;
712
+ const MARKER_SQUARE: number;
713
+ const MARKER_TRIANGLE_UP: number;
714
+ const MARKER_TRIANGLE_DOWN: number;
715
+ }