diff --git a/.gitignore b/.gitignore index ef08044..382b1ae 100755 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ out*.png examples/*.avi examples/tmp/* vagrant/.vagrant +coverage/ diff --git a/.travis.yml b/.travis.yml index db65e84..d522dab 100755 --- a/.travis.yml +++ b/.travis.yml @@ -30,6 +30,8 @@ before_install: - sudo add-apt-repository -y ppa:kubuntu-ppa/backports - sudo apt-get update - sudo apt-get install --force-yes --yes libcv-dev libcvaux-dev libhighgui-dev libopencv-dev + # for code coverage + - sudo apt-get install lcov # get commit message - COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n') # put local node-pre-gyp on PATH @@ -49,11 +51,11 @@ before_install: - platform=$(uname -s | sed "y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/") install: - # ensure source install works - - npm install --build-from-source - # test our module - - npm test - - node lib/opencv.js + # install dependencies first + - npm install + # build from source, run test and generate code coverage + - make cover + - DEBUG=true node lib/opencv.js - docker build -t peterbraden/node-opencv-ubuntu-12-04 -f test/Dockerfile-ubuntu-12-04 . - docker build -t peterbraden/node-opencv-ubuntu-14-04 -f test/Dockerfile-ubuntu-14-04 . @@ -81,3 +83,5 @@ script: after_success: # if success then query and display all published binaries - node-pre-gyp info + # Upload coverage to codecov + - bash <(curl -s https://codecov.io/bash) -s coverage -f *.info diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 4370a91..f9a995d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -68,3 +68,4 @@ Ordered by date of first contribution. [Auto-generated](https://github.com/xingr - [vyacheslav](https://github.com/vyacheslav-lonschakov) - vyacheslav - [Harold Ozouf](https://github.com/jspdown) +- [Dan Schultzer](https://github.com/danschultzer) diff --git a/Makefile b/Makefile index 9878379..57821d8 100644 --- a/Makefile +++ b/Makefile @@ -39,3 +39,63 @@ travis-build: docker build -t peterbraden/node-opencv-ubuntu-12-04 -f test/Dockerfile-ubuntu-12-04 . docker build -t peterbraden/node-opencv-ubuntu-14-04 -f test/Dockerfile-ubuntu-14-04 . .PHONY: travis-build + + +# Below build, coverage and clean tasks were partly lifted from https://github.com/geo-data/node-mapserv/blob/e99b23a44d910d444f5a45d144859758f820e1d1/Makefile +# @author danschultzer + +# The location of the `istanbul` JS code coverage framework. Try and get a +# globally installed version, falling back to a local install. +ISTANBUL := $(shell which istanbul) +ifeq ($(ISTANBUL),) + ISTANBUL = ./node_modules/.bin/istanbul/lib/cli.js +endif + +# The location of the `node-pre-gyp` module builder. Try and get a globally +# installed version, falling back to a local install. +NODE_PRE_GYP = $(shell which node-pre-gyp) +ifeq ($(NODE_GYP),) + NODE_PRE_GYP = ./node_modules/.bin/node-pre-gyp +endif + +NODE := $(shell which node) +test_deps = build \ +./test/*.js \ +./lib/*.js \ +$(NODE) + +build: build/Debug/opencv.node +build/Debug/opencv.node: + $(NODE_PRE_GYP) --verbose --debug rebuild + +# Perform the code coverage +cover: coverage/index.html +coverage/index.html: coverage/node-opencv.info + genhtml --output-directory coverage coverage/node-opencv.info + @echo "\033[0;32mPoint your browser at \`coverage/index.html\`\033[m\017" +coverage/node-opencv.info: coverage/bindings.info + lcov --test-name node-opencv \ + --add-tracefile coverage/lcov.info \ + --add-tracefile coverage/bindings.info \ + --output-file coverage/node-opencv.info +coverage/bindings.info: coverage/addon.info + lcov --extract coverage/addon.info '*opencv/src/*' --output-file coverage/bindings.info +coverage/addon.info: coverage/lcov.info + lcov --capture --base-directory build/ --directory . --output-file coverage/addon.info +# This generates the JS lcov info as well as gcov `*.gcda` files: +coverage/lcov.info: $(test_deps) $(ISTANBUL) + DEBUG=true $(NODE) --nouse_idle_notification --expose-gc \ + $(ISTANBUL) cover --report lcovonly -- test/unit.js + +$(NODE_PRE_GYP): + npm install node-pre-gyp + +$(ISTANBUL): package.json + npm install istanbul + @touch $(ISTANBUL) + +# Clean up any generated files +clean: $(NODE_PRE_GYP) + $(NODE_PRE_GYP) clean + rm -rf coverage + rm -rf build diff --git a/README.md b/README.md index 6bf0720..15944d4 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # node-opencv [![Build Status](https://secure.travis-ci.org/peterbraden/node-opencv.png)](http://travis-ci.org/peterbraden/node-opencv) - +[![Coverage](http://codecov.io/github/peterbraden/node-opencv/coverage.svg?branch=master)](https://codecov.io/gh/peterbraden/node-opencv) [OpenCV](http://opencv.org) bindings for Node.js. OpenCV is the defacto computer vision library - by interfacing with it natively in node, @@ -223,6 +223,20 @@ contours.approxPolyDP(index, epsilon, isClosed); contours.convexHull(index, clockwise); ``` +## Test + +Using [tape](https://github.com/substack/tape). Run with command: + +`npm test`. + +## Code coverage + +Using [istanbul](http://gotwarlost.github.io/istanbul/) and [lcov](http://ltp.sourceforge.net/coverage/lcov.php). Run with command: + +`make cover` + +Build version of `opencv.node` will be generated, and coverage files will be put in `coverage/` directory. These files can be remvoved automatically by running `make clean`. + ## MIT License The library is distributed under the MIT License - if for some reason that doesn't work for you please get in touch. diff --git a/binding.gyp b/binding.gyp index 1d5e1c3..69b4d12 100755 --- a/binding.gyp +++ b/binding.gyp @@ -60,17 +60,41 @@ [ # cflags on OS X are stupid and have to be defined like this "OS==\"mac\"", { "xcode_settings": { - "OTHER_CFLAGS": [ - "-mmacosx-version-min=10.7", - "-std=c++11", - "-stdlib=libc++", - "", "dependencies": { "buffers": "^0.1.1", + "istanbul": "0.4.5", "nan": "^2.0.9", "node-pre-gyp": "^0.6.30" }, diff --git a/src/Matrix.cc b/src/Matrix.cc index 39d7002..faff68d 100755 --- a/src/Matrix.cc +++ b/src/Matrix.cc @@ -198,7 +198,7 @@ double Matrix::DblGet(cv::Mat mat, int i, int j) { switch (mat.type()) { case CV_32FC3: - pix = mat.at(i, j); + pix = mat.at(i, j); pint |= (uchar) pix.val[2]; pint |= ((uchar) pix.val[1]) << 8; pint |= ((uchar) pix.val[0]) << 16; @@ -281,9 +281,9 @@ NAN_METHOD(Matrix::Set) { switch (self->mat.type()) { case CV_32FC3: vint = static_cast(val + 0.5); - self->mat.at(i, j)[0] = (uchar) (vint >> 16) & 0xff; - self->mat.at(i, j)[1] = (uchar) (vint >> 8) & 0xff; - self->mat.at(i, j)[2] = (uchar) (vint) & 0xff; + self->mat.at(i, j)[0] = (uchar) (vint >> 16) & 0xff; + self->mat.at(i, j)[1] = (uchar) (vint >> 8) & 0xff; + self->mat.at(i, j)[2] = (uchar) (vint) & 0xff; // printf("!!!i %x, %x, %x", (vint >> 16) & 0xff, (vint >> 8) & 0xff, (vint) & 0xff); break; default: diff --git a/test/unit.js b/test/unit.js index a95bbcf..412eef3 100755 --- a/test/unit.js +++ b/test/unit.js @@ -61,8 +61,8 @@ test('Matrix constructor', function(assert){ test('Matrix accessors', function(assert){ var mat = new cv.Matrix(1, 2); - mat.set(0,0,3) - mat.set(0,1,5000) + mat.set(0,0,3); + mat.set(0,1,5000); assert.deepEqual(mat.row(0), [3,5000]); mat = new cv.Matrix(1,2); @@ -335,7 +335,7 @@ test('LDA Wrap', function(assert) { test('Native Matrix', function(assert) { - var nativemat = require('../build/Release/test_nativemat.node'); + var nativemat = require('../build/' + (!!process.env.DEBUG ? 'Debug' : 'Release') + '/test_nativemat.node'); var mat = new cv.Matrix(42, 8); assert.deepEqual(mat.size(), nativemat.size(mat), 'nativemat');