mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
commit
0677e83235
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ out*.png
|
||||
examples/*.avi
|
||||
examples/tmp/*
|
||||
vagrant/.vagrant
|
||||
coverage/
|
||||
|
||||
14
.travis.yml
14
.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
|
||||
|
||||
@ -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)
|
||||
|
||||
60
Makefile
60
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
|
||||
|
||||
16
README.md
16
README.md
@ -1,7 +1,7 @@
|
||||
# node-opencv
|
||||
|
||||
[](http://travis-ci.org/peterbraden/node-opencv)
|
||||
|
||||
[](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.
|
||||
|
||||
50
binding.gyp
50
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++",
|
||||
"<!@(node utils/find-opencv.js --cflags)",
|
||||
"OTHER_CFLAGS": [
|
||||
"-mmacosx-version-min=10.7",
|
||||
"-std=c++11",
|
||||
"-stdlib=libc++",
|
||||
"<!@(node utils/find-opencv.js --cflags)",
|
||||
],
|
||||
"GCC_ENABLE_CPP_RTTI": "YES",
|
||||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
||||
"GCC_ENABLE_CPP_RTTI": "YES",
|
||||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
||||
}
|
||||
}
|
||||
}]
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
"configurations": {
|
||||
# This is used for generating code coverage with the `--debug` argument
|
||||
"Debug": {
|
||||
"conditions": [
|
||||
['OS=="linux"', {
|
||||
"cflags": ["-coverage"],
|
||||
"ldflags": ["-coverage"]
|
||||
}],
|
||||
['OS=="mac"', {
|
||||
"xcode_settings": {
|
||||
"OTHER_CFLAGS": [
|
||||
"-fprofile-arcs -ftest-coverage",
|
||||
],
|
||||
"OTHER_LDFLAGS": [
|
||||
"--coverage"
|
||||
]
|
||||
}
|
||||
}]
|
||||
|
||||
]
|
||||
},
|
||||
}
|
||||
},
|
||||
{
|
||||
"target_name": "test_nativemat",
|
||||
@ -119,10 +143,10 @@
|
||||
"xcode_settings": {
|
||||
"OTHER_CFLAGS": [
|
||||
"-mmacosx-version-min=10.7",
|
||||
"-std=c++11",
|
||||
"-stdlib=libc++",
|
||||
"<!@(node utils/find-opencv.js --cflags)",
|
||||
],
|
||||
"-std=c++11",
|
||||
"-stdlib=libc++",
|
||||
"<!@(node utils/find-opencv.js --cflags)",
|
||||
],
|
||||
"GCC_ENABLE_CPP_RTTI": "YES",
|
||||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
var cv = require('../lib/opencv');
|
||||
|
||||
var mat = new cv.Matrix(1, 2, cv.Constants.CV_8U, [1]);
|
||||
var mat = new cv.Matrix(1, 2, cv.Constants.CV_8UC3, [1]);
|
||||
var row = mat.pixelRow(0);
|
||||
console.log("mat: " + row[0] + row[1]);
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
var binary = require('node-pre-gyp');
|
||||
var path = require('path');
|
||||
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
|
||||
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')), { debug: !!process.env.DEBUG });
|
||||
var binding = require(binding_path);
|
||||
|
||||
//module.exports = require('../build/Release/opencv.node');
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
"author": "Peter Braden <peterbraden@peterbraden.co.uk>",
|
||||
"dependencies": {
|
||||
"buffers": "^0.1.1",
|
||||
"istanbul": "0.4.5",
|
||||
"nan": "^2.0.9",
|
||||
"node-pre-gyp": "^0.6.30"
|
||||
},
|
||||
|
||||
@ -198,7 +198,7 @@ double Matrix::DblGet(cv::Mat mat, int i, int j) {
|
||||
|
||||
switch (mat.type()) {
|
||||
case CV_32FC3:
|
||||
pix = mat.at<cv::Vec3b>(i, j);
|
||||
pix = mat.at<cv::Vec3f>(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<unsigned int>(val + 0.5);
|
||||
self->mat.at<cv::Vec3b>(i, j)[0] = (uchar) (vint >> 16) & 0xff;
|
||||
self->mat.at<cv::Vec3b>(i, j)[1] = (uchar) (vint >> 8) & 0xff;
|
||||
self->mat.at<cv::Vec3b>(i, j)[2] = (uchar) (vint) & 0xff;
|
||||
self->mat.at<cv::Vec3f>(i, j)[0] = (uchar) (vint >> 16) & 0xff;
|
||||
self->mat.at<cv::Vec3f>(i, j)[1] = (uchar) (vint >> 8) & 0xff;
|
||||
self->mat.at<cv::Vec3f>(i, j)[2] = (uchar) (vint) & 0xff;
|
||||
// printf("!!!i %x, %x, %x", (vint >> 16) & 0xff, (vint >> 8) & 0xff, (vint) & 0xff);
|
||||
break;
|
||||
default:
|
||||
|
||||
@ -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');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user