Skip to content

Commit b620169

Browse files
added typings for non class functions + declare constants
1 parent b31de15 commit b620169

File tree

9 files changed

+683
-58
lines changed

9 files changed

+683
-58
lines changed

examples/typed/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# opencv4nodejs TypeScript examples
2+
3+
### Install
4+
``` bash
5+
npm install
6+
```
7+
8+
### Run
9+
``` bash
10+
npm run ts-node <example>.ts
11+
```

examples/typed/faceRecognition0.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ if (!cv.xmodules.face) {
66
throw new Error('exiting: opencv4nodejs compiled without face module');
77
}
88

9-
const basePath = '../data/face-recognition';
9+
const basePath = '../../data/face-recognition';
1010
const imgsPath = path.resolve(basePath, 'imgs');
1111
const nameMappings = ['daryl', 'rick', 'negan'];
1212

1313
const imgFiles = fs.readdirSync(imgsPath);
1414

1515
const classifier = new cv.CascadeClassifier(cv.HAAR_FRONTALFACE_ALT2);
16-
const getFaceImage = (grayImg) => {
16+
const getFaceImage = (grayImg: cv.Mat) => {
1717
const faceRects = classifier.detectMultiScale(grayImg).objects;
1818
if (!faceRects.length) {
1919
throw new Error('failed to detect faces');
@@ -33,8 +33,8 @@ const images = imgFiles
3333
// face images must be equally sized
3434
.map(faceImg => faceImg.resize(80, 80));
3535

36-
const isImageFour = (_, i) => imgFiles[i].includes('4');
37-
const isNotImageFour = (_, i) => !isImageFour(_, i);
36+
const isImageFour = (_: any, i: number) => imgFiles[i].includes('4');
37+
const isNotImageFour = (_: any, i: number) => !isImageFour(_, i);
3838
// use images 1 - 3 for training
3939
const trainImages = images.filter(isNotImageFour);
4040
// use images 4 for testing
@@ -44,7 +44,7 @@ const labels = imgFiles
4444
.filter(isNotImageFour)
4545
.map(file => nameMappings.findIndex(name => file.includes(name)));
4646

47-
const runPrediction = (recognizer) => {
47+
const runPrediction = (recognizer: cv.FaceRecognizer) => {
4848
testImages.forEach((img) => {
4949
const result = recognizer.predict(img);
5050
console.log('predicted: %s, confidence: %s', nameMappings[result.label], result.confidence);

examples/typed/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"version": "0.0.0",
44
"author": "justadudewhohacks",
55
"license": "MIT",
6+
"scripts": {
7+
"ts-node": "./node_modules/.bin/ts-node"
8+
},
69
"devDependencies": {
710
"@types/node": "^9.4.0",
811
"ts-lint": "^4.5.1",

lib/index.d.ts

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,56 @@
1-
export * from './typings/Mat.d'
2-
export * from './typings/Vec.d'
3-
export * from './typings/Point.d'
4-
export * from './typings/Size.d'
5-
export * from './typings/Net.d'
6-
export * from './typings/Rect.d'
7-
export * from './typings/RotatedRect.d'
8-
export * from './typings/TermCriteria.d'
9-
export * from './typings/Contour.d'
10-
export * from './typings/Moments.d'
11-
export * from './typings/EigenFaceRecognizer.d'
12-
export * from './typings/LBPHFaceRecognizer.d'
13-
export * from './typings/FisherFaceRecognizer.d'
14-
export * from './typings/AGASTDetector.d'
15-
export * from './typings/AKAZEDetector.d'
16-
export * from './typings/BRISKDetector.d'
17-
export * from './typings/DescriptorMatch.d'
18-
export * from './typings/FASTDetector.d'
19-
export * from './typings/GFTTDetector.d'
20-
export * from './typings/KAZEDetector.d'
21-
export * from './typings/KeyPoint.d'
22-
export * from './typings/MSERDetector.d'
23-
export * from './typings/ORBDetector.d'
24-
export * from './typings/SimpleBlobDetector.d'
25-
export * from './typings/SimpleBlobDetectorParams.d'
26-
export * from './typings/VideoCapture.d'
27-
export * from './typings/VideoWriter.d'
28-
export * from './typings/ParamGrid.d'
29-
export * from './typings/TrainData.d'
30-
export * from './typings/CascadeClassifier.d'
31-
export * from './typings/DetectionROI.d'
32-
export * from './typings/HOGDescriptor.d'
33-
export * from './typings/OCRHMMClassifier.d'
34-
export * from './typings/MultiTracker.d'
35-
export * from './typings/SVM.d'
36-
export * from './typings/OCRHMMDecoder.d'
37-
export * from './typings/TrackerBoostingParams.d'
38-
export * from './typings/TrackerGOTURN.d'
39-
export * from './typings/TrackerKCFParams.d'
40-
export * from './typings/TrackerMedianFlow.d'
41-
export * from './typings/TrackerMILParams.d'
42-
export * from './typings/TrackerTLD.d'
43-
export * from './typings/TrackerMIL.d'
44-
export * from './typings/TrackerKCF.d'
45-
export * from './typings/TrackerBoosting.d'
46-
export * from './typings/BackgroundSubtractorKNN.d'
47-
export * from './typings/BackgroundSubtractorMOG2.d'
48-
export * from './typings/SIFTDetector.d'
49-
export * from './typings/SURFDetector.d'
50-
export * from './typings/SuperpixelLSC.d'
51-
export * from './typings/SuperpixelSLIC.d'
52-
export * from './typings/SuperpixelSEEDS.d'
1+
export * from './typings/cv.d';
2+
export * from './typings/constants.d';
3+
export * from './typings/xmodules.d';
4+
export * from './typings/Mat.d';
5+
export * from './typings/Vec.d';
6+
export * from './typings/Point.d';
7+
export * from './typings/Size.d';
8+
export * from './typings/Net.d';
9+
export * from './typings/Rect.d';
10+
export * from './typings/RotatedRect.d';
11+
export * from './typings/TermCriteria.d';
12+
export * from './typings/Contour.d';
13+
export * from './typings/Moments.d';
14+
export * from './typings/EigenFaceRecognizer.d';
15+
export * from './typings/LBPHFaceRecognizer.d';
16+
export * from './typings/FisherFaceRecognizer.d';
17+
export * from './typings/FaceRecognizer.d';
18+
export * from './typings/AGASTDetector.d';
19+
export * from './typings/AKAZEDetector.d';
20+
export * from './typings/BRISKDetector.d';
21+
export * from './typings/DescriptorMatch.d';
22+
export * from './typings/FASTDetector.d';
23+
export * from './typings/GFTTDetector.d';
24+
export * from './typings/KAZEDetector.d';
25+
export * from './typings/KeyPoint.d';
26+
export * from './typings/MSERDetector.d';
27+
export * from './typings/ORBDetector.d';
28+
export * from './typings/SimpleBlobDetector.d';
29+
export * from './typings/SimpleBlobDetectorParams.d';
30+
export * from './typings/VideoCapture.d';
31+
export * from './typings/VideoWriter.d';
32+
export * from './typings/ParamGrid.d';
33+
export * from './typings/TrainData.d';
34+
export * from './typings/CascadeClassifier.d';
35+
export * from './typings/DetectionROI.d';
36+
export * from './typings/HOGDescriptor.d';
37+
export * from './typings/OCRHMMClassifier.d';
38+
export * from './typings/MultiTracker.d';
39+
export * from './typings/SVM.d';
40+
export * from './typings/OCRHMMDecoder.d';
41+
export * from './typings/TrackerBoostingParams.d';
42+
export * from './typings/TrackerGOTURN.d';
43+
export * from './typings/TrackerKCFParams.d';
44+
export * from './typings/TrackerMedianFlow.d';
45+
export * from './typings/TrackerMILParams.d';
46+
export * from './typings/TrackerTLD.d';
47+
export * from './typings/TrackerMIL.d';
48+
export * from './typings/TrackerKCF.d';
49+
export * from './typings/TrackerBoosting.d';
50+
export * from './typings/BackgroundSubtractorKNN.d';
51+
export * from './typings/BackgroundSubtractorMOG2.d';
52+
export * from './typings/SIFTDetector.d';
53+
export * from './typings/SURFDetector.d';
54+
export * from './typings/SuperpixelLSC.d';
55+
export * from './typings/SuperpixelSLIC.d';
56+
export * from './typings/SuperpixelSEEDS.d';

lib/typings/FaceRecognizer.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { EigenFaceRecognizer } from './EigenFaceRecognizer.d';
2+
import { FisherFaceRecognizer } from './FisherFaceRecognizer.d';
3+
import { LBPHFaceRecognizer } from './LBPHFaceRecognizer.d';
4+
5+
export type FaceRecognizer = LBPHFaceRecognizer | FisherFaceRecognizer | LBPHFaceRecognizer;

lib/typings/Point2.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Point } from './../generated/Point.d';
1+
import { Point } from './Point.d';
22

33
export class Point2 extends Point {
44
readonly x: number;

0 commit comments

Comments
 (0)