Skip to content

Commit 3c12905

Browse files
fixed wrong paths in typescript examples
1 parent 9a4c353 commit 3c12905

12 files changed

+32
-23
lines changed

examples/dnn/loadFacenet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {
55
} = require('../utils');
66

77
module.exports = function () {
8-
const modelPath = '../../data/dnn/facenet';
8+
const modelPath = path.resolve(__dirname, '../../data/dnn/facenet');
99

1010
const prototxt = path.resolve(modelPath, 'facenet.prototxt');
1111
const modelFile = path.resolve(modelPath, 'res10_300x300_ssd_iter_140000.caffemodel');

examples/faceRecognition1.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ const lbph = new cv.LBPHFaceRecognizer();
4141
lbph.train(trainImgs, labels);
4242

4343
const twoFacesImg = cv.imread(path.resolve(basePath, 'daryl-rick.jpg'));
44-
const faces = classifier.detectMultiScale(twoFacesImg.bgrToGray()).objects;
44+
const result = classifier.detectMultiScale(twoFacesImg.bgrToGray());
4545

46-
faces.forEach((faceRect) => {
46+
const minDetections = 10;
47+
result.objects.forEach((faceRect, i) => {
48+
if (result.numDetections[i] < minDetections) {
49+
return;
50+
}
4751
const faceImg = twoFacesImg.getRegion(faceRect).bgrToGray();
4852
const who = nameMappings[lbph.predict(faceImg).label];
4953

examples/typed/dnn/loadFacenet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as path from 'path';
33
import * as cv from '../../../';
44

55
export function loadFacenet (): cv.Net {
6-
const modelPath = '../../../data/dnn/facenet';
6+
const modelPath = path.resolve(__dirname, '../../../data/dnn/facenet');
77

88
const prototxt = path.resolve(modelPath, 'facenet.prototxt');
99
const modelFile = path.resolve(modelPath, 'res10_300x300_ssd_iter_140000.caffemodel');

examples/typed/dnnSSDCoco.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (!cv.xmodules.dnn) {
1313
}
1414

1515
// replace with path where you unzipped inception model
16-
const ssdcocoModelPath = '../data/dnn/coco-SSD_300x300';
16+
const ssdcocoModelPath = '../../data/dnn/coco-SSD_300x300';
1717

1818
const prototxt = path.resolve(ssdcocoModelPath, 'deploy.prototxt');
1919
const modelFile = path.resolve(ssdcocoModelPath, 'VGG_coco_SSD_300x300_iter_400000.caffemodel');
@@ -54,7 +54,7 @@ const makeDrawClassDetections = (predictions: Prediction[]) =>
5454
};
5555

5656
const runDetectDishesExample = () => {
57-
const img = cv.imread('../data/dishes.jpg');
57+
const img = cv.imread('../../data/dishes.jpg');
5858
const minConfidence = 0.2;
5959

6060
const predictions = classifyImg(img).filter(res => res.confidence > minConfidence);
@@ -92,7 +92,7 @@ const runDetectDishesExample = () => {
9292
};
9393

9494
const runDetectPeopleExample = () => {
95-
const img = cv.imread('../data/cars.jpeg');
95+
const img = cv.imread('../../data/cars.jpeg');
9696
const minConfidence = 0.4;
9797

9898
const predictions = classifyImg(img).filter(res => res.confidence > minConfidence);

examples/typed/dnnTensorflowInception.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ const classifyImg = (img: cv.Mat) => {
6161

6262
const testData = [
6363
{
64-
image: '../data/banana.jpg',
64+
image: '../../data/banana.jpg',
6565
label: 'banana'
6666
},
6767
{
68-
image: '../data/husky.jpg',
68+
image: '../../data/husky.jpg',
6969
label: 'husky'
7070
},
7171
{
72-
image: '../data/car.jpeg',
72+
image: '../../data/car.jpeg',
7373
label: 'car'
7474
},
7575
{
76-
image: '../data/lenna.png',
76+
image: '../../data/lenna.png',
7777
label: 'lenna'
7878
}
7979
];

examples/typed/faceRecognition1.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ 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

@@ -41,9 +41,14 @@ const lbph = new cv.LBPHFaceRecognizer();
4141
lbph.train(trainImgs, labels);
4242

4343
const twoFacesImg = cv.imread(path.resolve(basePath, 'daryl-rick.jpg'));
44-
const faces = classifier.detectMultiScale(twoFacesImg.bgrToGray()).objects;
44+
const result = classifier.detectMultiScale(twoFacesImg.bgrToGray());
45+
46+
const minDetections = 10;
47+
result.objects.forEach((faceRect, i) => {
48+
if (result.numDetections[i] < minDetections) {
49+
return;
50+
}
4551

46-
faces.forEach((faceRect) => {
4752
const faceImg = twoFacesImg.getRegion(faceRect).bgrToGray();
4853
const who = nameMappings[lbph.predict(faceImg).label];
4954

examples/typed/handGestureRecognition0.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const red = new cv.Vec3(0, 0, 255);
125125

126126
// main
127127
const delay = 20;
128-
grabFrames('../data/hand-gesture.mp4', delay, (frame) => {
128+
grabFrames('../../data/hand-gesture.mp4', delay, (frame) => {
129129
const resizedImg = frame.resizeToMax(640);
130130

131131
const handMask = makeHandMask(resizedImg);

examples/typed/machineLearningOCR.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import {
77
saveConfusionMatrix
88
} from './OCRTools';
99

10-
const trainDataPath = '../data/ocr/traindata';
11-
const testDataPath = '../data/ocr/testdata';
12-
const outPath = '../data/ocr';
10+
const trainDataPath = '../../data/ocr/traindata';
11+
const testDataPath = '../../data/ocr/testdata';
12+
const outPath = '../../data/ocr';
1313
const SVMFile = 'lcletters.xml';
1414

1515
const hog = new cv.HOGDescriptor({

examples/typed/matchFeatures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const matchFeatures = (
3232
);
3333
};
3434

35-
const img1 = cv.imread('../data/s0.jpg');
36-
const img2 = cv.imread('../data/s1.jpg');
35+
const img1 = cv.imread('../../data/s0.jpg');
36+
const img2 = cv.imread('../../data/s1.jpg');
3737

3838
// check if opencv compiled with extra modules and nonfree
3939
if (cv.xmodules.xfeatures2d) {

examples/typed/plotHist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as cv from '../../';
22

3-
const img = cv.imread('../data/Lenna.png');
3+
const img = cv.imread('../../data/Lenna.png');
44

55
// single axis for 1D hist
66
const getHistAxis = (channel: number) => ([

0 commit comments

Comments
 (0)