Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 34afadd

Browse files
Add drawing boxes example
1 parent d750f14 commit 34afadd

File tree

4 files changed

+213
-15
lines changed

4 files changed

+213
-15
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ build/
88
*.d.ts
99

1010
examples/dog.jpg
11+
examples/dog-with-boxes.png
1112
examples/eagle.jpg
1213
examples/giraffe.jpg
1314
examples/yolov3-tiny.cfg

README.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# Darknet.JS
2+
23
A Node wrapper of pjreddie's open source neural network framework Darknet, using the Foreign Function Interface Library. Read: YOLOv3 in JavaScript.
34

45
## Prerequisites
6+
57
- Linux, Mac, Windows (Linux sub-system),
68
- Node
79
- Build tools (make, gcc, etc.)
810

911
## Examples
12+
1013
To run the examples, run the following commands:
14+
1115
```sh
1216
# Clone the repositorys
1317
git clone https://github.com/bennetthardwick/darknet.js.git darknet && cd darknet
@@ -18,14 +22,19 @@ npx tsc
1822
# Run examples
1923
./examples/example
2024
```
25+
2126
Note: The example weights are quite large, the download might take some time
2227

2328
## Installation
29+
2430
You can install darknet with npm using the following command:
31+
2532
```
2633
npm install darknet
2734
```
35+
2836
If you'd like to enable CUDA and/or CUDANN, export the flags `DARKNET_BUILD_WITH_GPU=1` for CUDA, and `DARKNET_BUILD_WITH_CUDNN=1` for CUDANN, and rebuild:
37+
2938
```
3039
export DARKNET_BUILD_WITH_GPU=1
3140
export DARKNET_BUILD_WITH_CUDNN=1
@@ -35,50 +44,56 @@ npm rebuild darknet
3544
You can enable OpenMP by also exporting the flag `DARKNET_BUILD_WITH_OPENMP=1`;
3645

3746
## Usage
47+
3848
To create an instance of darknet.js, you need a three things. The trained weights, the configuration file they were trained with and a list of the names of all the classes.
49+
3950
```typescript
40-
import { Darknet } from 'darknet';
51+
import { Darknet } from "darknet";
4152

4253
// Init
4354
let darknet = new Darknet({
44-
weights: './cats.weights',
45-
config: './cats.cfg',
46-
names: [ 'dog', 'cat' ]
55+
weights: "./cats.weights",
56+
config: "./cats.cfg",
57+
names: ["dog", "cat"],
4758
});
4859

4960
// Detect
50-
console.log(darknet.detect('/image/of/a/dog.jpg'));
61+
console.log(darknet.detect("/image/of/a/dog.jpg"));
5162
```
5263

5364
In conjuction with [opencv4nodejs](https://github.com/justadudewhohacks/opencv4nodejs), Darknet.js can also be used to detect objects inside videos.
65+
5466
```javascript
55-
const fs = require('fs');
56-
const cv = require('opencv4nodejs');
57-
const { Darknet } = require('darknet');
67+
const fs = require("fs");
68+
const cv = require("opencv4nodejs");
69+
const { Darknet } = require("darknet");
5870

5971
const darknet = new Darknet({
60-
weights: 'yolov3.weights',
61-
config: 'cfg/yolov3.cfg',
62-
namefile: 'data/coco.names'
72+
weights: "yolov3.weights",
73+
config: "cfg/yolov3.cfg",
74+
namefile: "data/coco.names",
6375
});
6476

65-
const cap = new cv.VideoCapture('video.mp4');
77+
const cap = new cv.VideoCapture("video.mp4");
6678

6779
let frame;
6880
let index = 0;
6981
do {
7082
frame = cap.read().cvtColor(cv.COLOR_BGR2RGB);
7183
console.log(darknet.detect(frame));
72-
} while(!frame.empty);
84+
} while (!frame.empty);
7385
```
7486

7587
### Example Configuration
76-
You can download pre-trained weights and configuration from pjreddie's website. The latest version (yolov3-tiny) is linked below:
88+
89+
You can download pre-trained weights and configuration from pjreddie's website. The latest version (yolov3-tiny) is linked below:
90+
7791
- [weights](https://pjreddie.com/media/files/yolov3-tiny.weights)
7892
- [config](https://github.com/pjreddie/darknet/blob/master/cfg/yolov3-tiny.cfg)
7993
- [names](https://raw.githubusercontent.com/pjreddie/darknet/master/data/coco.names)
8094

8195
If you don't want to download that stuff manually, navigate to the `examples` directory and issue the `./example` command. This will download the necessary files and run some detections.
8296

8397
## Built-With
98+
8499
- [Darknet](https://github.com/pjreddie/darknet)

0 commit comments

Comments
 (0)