Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
images/
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

node_modules
package-lock.json
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ubuntu:16.04
USER root
COPY . .
RUN apt-get update
RUN apt-get -y install curl gnupg git cmake build-essential
RUN curl -sL https://deb.nodesource.com/setup_11.x | bash -
RUN apt-get -y install nodejs
RUN npm install
CMD "npm start"
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
# object-detection-node
# object-detection-node
This is an example on how we can use ***@cloud-annotations*** in Nodejs.

You can find an in depth walkthrough for training a TensorFlow.js model [here](https://github.com/cloud-annotations/training/).

## Setup
`git clone` the repo and `cd` into it by running the following command:

```bash
git clone https://github.com/cloud-annotations/object-detection-node.git
cd object-detection-node
```

### `npm install`

> **Note: You’ll need to have Node 8.10.0 or later on your local development machine.** You can use [nvm](https://github.com/creationix/nvm#installation) (macOS/Linux) or [nvm-windows](https://github.com/coreybutler/nvm-windows#node-version-manager-nvm-for-windows) to easily switch Node versions between different projects.

## Add TensorFlow.js Model to the App
Copy the `model_web` directory generated from the object detection walkthrough and paste it into the root directory of this repo.

## Run the App
### `npm start`

It will open a window and show live stream of processed images through @cloud-annotations/models-node
![alt text](images/1.png)
Binary file added images/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var cv = require("opencv4nodejs");
const models = require('@cloud-annotations/models-node');
const vCap = new cv.VideoCapture(0);
const delay = 50;
let done = false;
const blue = new cv.Vec(255, 0, 0);
const thickness = 1;
async function load() {
try {
const model = await models.load('model_web');
console.log("model is loaded");
while (!done) {
let frame = vCap.read();
var buffer = cv.imencode('.jpg', frame)
const results = await model.detect(buffer);
console.log(results);
results.forEach(element => {
frame.drawRectangle(
new cv.Point(element.bbox[0], element.bbox[1]),
new cv.Point(element.bbox[0]+ element.bbox[2], element.bbox[1] + element.bbox[3]),
blue,
cv.LINE_8,
thickness
);
frame.putText(element.label, new cv.Point2(element.bbox[0], element.bbox[1]+element.bbox[3]), cv.FONT_HERSHEY_SIMPLEX, 2, new cv.Vec3(0, 255, 0), 2)
});
if (frame.empty) {
vCap.reset();
frame = vCap.read();
}
cv.waitKey(delay);
// cv.imshow("frame", frame)
}

} catch(err) {
console.log(err)

}
}
load()
Binary file added model_web/group1-shard1of6.bin
Binary file not shown.
Binary file added model_web/group1-shard2of6.bin
Binary file not shown.
Binary file added model_web/group1-shard3of6.bin
Binary file not shown.
Binary file added model_web/group1-shard4of6.bin
Binary file not shown.
Binary file added model_web/group1-shard5of6.bin
Binary file not shown.
Binary file added model_web/group1-shard6of6.bin
Binary file not shown.
1 change: 1 addition & 0 deletions model_web/labels.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["mask", "nomask"]
1 change: 1 addition & 0 deletions model_web/model.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "object-detection-node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/SaifRehman/object-detection-node.git"
},
"dependencies": {
"@cloud-annotations/models-node": "0.0.3",
"@tensorflow/tfjs": "^1.4.0",
"@tensorflow/tfjs-node": "^1.7.4",
"opencv4nodejs": "^5.6.0"
},
"opencv4nodejs": {
"autoBuildFlags": "-DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_PC_FILE_NAME=opencv.pc",
"autoBuildOpencvVersion": "4.1.0"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/SaifRehman/object-detection-node/issues"
},
"homepage": "https://github.com/SaifRehman/object-detection-node#readme"
}
Loading