GithubHelp home page GithubHelp logo

isabella232 / node-yolo Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mobimeo/node-yolo

0.0 0.0 0.0 3.01 MB

Node bindings for YOLO/Darknet image recognition library

Home Page: https://lab.moovel.com/blog/what-you-get-is-what-you-see-nodejs-yolo

License: MIT License

Python 7.39% C++ 67.00% JavaScript 22.42% C 3.20%

node-yolo's Introduction

Node.js Wrapper for YOLO/Darknet recognition framework

Darknet is an open source neural network framework written in C and CUDA. This project wraps this framework in a Node.js native addon.

Status

Currently, the wrapper implements a demo method to run a recognition from the webcam/video or an image file. Equivalent to

./darknet detector demo cfg/coco.data cfg/yolo.cfg yolo.weights
./darknet detect cfg/yolo.cfg yolo.weights data/dog.jpg

Prerequisites

Requires:

  • Modern Node and NPM versions (tested with latest LTS release Node v6.., npm 3.., supposed to work with the newer versions as well)

  • OpenCV (version 2, for example, 2.4.9.1) to be installed on your system.

    Installing with Brew on MacOS:

    brew install opencv@2
    sudo chown -R $(whoami):admin /usr/local
    brew link --force opencv@2
    
  • If you are on a mac: macOS 10.12 Sierra or newer, Apple LLVM version 8.0.0 (xcode 8.2, check version with clang -v). For GPU support, Nvidia CUDA Toolkit (you need to have Nvidia CUDA GPU graphic card)

First, you need to compile this fork of darknet with OpenCV support (optionally, with CUDA support):

git clone https://github.com/OrKoN/darknet
cd darknet
make OPENCV=1 # optionally GPU=1
make install # by default installed to /usr/local

After that you can process with the installation via NPM.

The fork is required because it contains a few important changes to the origin source code which allow using darknet with NodeJS:

  • Makefile is extended to build a static library (darknet.a).
  • Makefile is extended with install and uninstall commands which install the library globally so that this module can easily find and link it.
  • All darknet functions in header files are marked with extern "C" if they are included in a C++ program (such as a NodeJS module).

Installation

npm install @moovel/yolo --save

Usage

Either download your own cfg, data folders and .weight files from the darknet project or use the ones included in test folder (see also test/readme.md). You also can find there the examples from below.

Detect a video from camera or a file:

const darknet = require('@moovel/yolo');

darknet.detect({
  cfg: './cfg/yolo.cfg',
  weights: './yolo.weights',
  data: './cfg/coco.data',
  cameraIndex: 0, // optional, default: 0,
  video: './test.mp4', // optional, forces to use the video file instead of a camera
  thresh: 0.24, // optional, default: 0.24
  hierThresh: 0.5, // optional, default: 0.5
}, function(modified, original, detections, dimensions) {
  /**

  modified - raw frame with detections drawn, rgb24 format
  original - raw frame, as captured by the webcam/video, rgb24 format,
  detections - array of detections
  dimenstions - image width and height

  Example detections:

  [ { x: 0.8602103590965271,
      y: 0.20008485019207,
      w: 0.13895535469055176,
      h: 0.39782464504241943,
      prob: 0.2408987432718277,
      name: 'tvmonitor' },
    { x: 0.26072466373443604,
      y: 0.4977818727493286,
      w: 0.10842404514551163,
      h: 0.22796104848384857,
      prob: 0.3290732204914093,
      name: 'person' },
    { x: 0.2568981349468231,
      y: 0.5765896439552307,
      w: 0.12322483211755753,
      h: 0.2544059157371521,
      prob: 0.2738085687160492,
      name: 'chair' },
    { x: 0.6593853235244751,
      y: 0.8188746571540833,
      w: 0.06210440397262573,
      h: 0.100614033639431,
      prob: 0.3225017189979553,
      name: 'clock' } ]
  */
});

Detect on a single image:

const darknet = require('@moovel/yolo');

darknet.detectImage({
  cfg: './cfg/yolo.cfg',
  weights: './yolo.weights',
  data: './cfg/coco.data',
  image: './data/dog.jpg',
  thresh: 0.24, // optional, default: 0.24
  hierThresh: 0.5, // optional, default: 0.5,
}, function(modified, original, detections, dimensions) {
  /**

  modified - raw frame with detections drawn, rgb24 format
  original - raw frame, as captured by the webcam/video, rgb24 format,
  detections - array of detections
  dimenstions - image width and height

  Example detections:

  [ { x: 0.8602103590965271,
      y: 0.20008485019207,
      w: 0.13895535469055176,
      h: 0.39782464504241943,
      prob: 0.2408987432718277,
      name: 'tvmonitor' },
    { x: 0.26072466373443604,
      y: 0.4977818727493286,
      w: 0.10842404514551163,
      h: 0.22796104848384857,
      prob: 0.3290732204914093,
      name: 'person' },
    { x: 0.2568981349468231,
      y: 0.5765896439552307,
      w: 0.12322483211755753,
      h: 0.2544059157371521,
      prob: 0.2738085687160492,
      name: 'chair' },
    { x: 0.6593853235244751,
      y: 0.8188746571540833,
      w: 0.06210440397262573,
      h: 0.100614033639431,
      prob: 0.3225017189979553,
      name: 'clock' } ]
  */
});

After that you can convert the original frames with ffmpeg to an image. Play with the parameter bgr24/rgb24 if the color channels are swapped e.g. blueish image:

ffmpeg -f rawvideo -s 768x576 -pix_fmt bgr24 -i data.raw data.png

node-yolo's People

Contributors

b-g avatar joeyklee avatar orkon avatar tdurand avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.