Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Max Ehrlich 2015-02-13 12:19:51 -05:00
commit 81f36f9321
28 changed files with 610 additions and 114 deletions

View File

@ -1,10 +1,73 @@
language: node_js language: node_js
node_js: node_js:
- "0.10" - '0.10'
- "0.11" - '0.11'
- '0.12'
compiler: clang
env:
global:
- secure: "kCAwXdfcMv4l4ok5lO89ANbKXXwWQpn5/3qupSbhmX2NDIGUxyXze/cs90u9gF5hcT7ebq27ZJPEtu7pRov8MadfQM9BAd4ZZrHcMHWSkA0Iz+nM+m0Urwach6jkp2Iuwx15L2NHSis7f5PUKJcEv4Gnqs8jrCJzHHS7m7dO0Xo="
- secure: "lBIk4BhdIkSmJtFUNp93UjDm445i9eF7nKA+oSiLRu+b9i/WeRLiKFI89tehexWeXBlyNhziBN16LrHmx3I86yZfEok9dBMA1JuzYBjrvpjRAflGcqaCFLV3axyyyNQRIh7Q+ziAlg0xg8HL752BpnfXO91g3jfDPjGxcvBb5xQ="
before_install: before_install:
- sudo apt-get update # Fix a problem with apt-get failing later, see http://docs.travis-ci.com/user/installing-dependencies/#Installing-Ubuntu-packages
- sudo apt-get update -qq
# - sudo add-apt-repository -y ppa:kubuntu-ppa/backports
# - sudo apt-get update
- sudo apt-get install libcv-dev - sudo apt-get install libcv-dev
- sudo apt-get install libopencv-dev - sudo apt-get install libopencv-dev
- sudo apt-get install libhighgui-dev - sudo apt-get install libhighgui-dev
# get commit message
- COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n')
# put local node-pre-gyp on PATH
- export PATH=./node_modules/.bin/:$PATH
# install node-pre-gyp so it is available for packaging and publishing
- npm install node-gyp -g
# install node-pre-gyp so it is available for packaging and publishing
- npm install node-pre-gyp
# install aws-sdk so it is available for publishing to AS3
- npm install aws-sdk
# figure out if we should publish
- PUBLISH_BINARY=false
# if we are building a tag then publish
- if [[ $TRAVIS_BRANCH == `git describe --tags --always HEAD` ]]; then PUBLISH_BINARY=true; fi;
# or if we put [publish binary] in the commit message
- if test "${COMMIT_MESSAGE#*'[publish binary]'}" != "$COMMIT_MESSAGE"; then PUBLISH_BINARY=true; fi;
- 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
before_script:
- echo "Publishing native platform Binary Package? ->" $PUBLISH_BINARY
# if publishing, do it
- if [[ $PUBLISH_BINARY == true ]]; then node-pre-gyp package publish || true ; fi;
# cleanup
- node-pre-gyp clean
- node-gyp clean
- sudo apt-get purge libcv-dev
- sudo apt-get purge libopencv-dev
- sudo apt-get purge libhighgui-dev
script:
# if publishing, test installing from remote
- INSTALL_RESULT=0
- if [[ $PUBLISH_BINARY == true ]]; then INSTALL_RESULT=$(npm install --fallback-to-build=false > /dev/null)$? || true; fi;
# if install returned non zero (errored) then we first unpublish and then call false so travis will bail at this line
- if [[ $INSTALL_RESULT != 0 ]]; then echo "returned $INSTALL_RESULT";node-pre-gyp unpublish;false; fi
# If success then we arrive here so lets clean up
- node-pre-gyp clean
# Can't compile opencv 32bit in 64 bit env.
after_success:
# if success then query and display all published binaries
- node-pre-gyp info

View File

@ -1,6 +1,29 @@
# Changelog # Changelog
### 3.0.0
You wait ages for a release, and 2 come along at once...
This one is awesome. It adds prebuilt binaries, so you don't need
to build opencv for the common platforms.
Many many thanks to @edgarsilva for awesome work here, and
http://hybridgroup.com/ for hosting the binaries
### 2.0.0
- Support for node 0.12
- Camera Calibration Functions from @queuecumber
- Fix for Nan 1.5.1 from @IMGNRY
- More build fixes from @scanlime
- Matrix crop prototype from @dbpieter
- Many fixes from @madshall
Thanks to everyone that contributed!
### 1.0.0 ### 1.0.0
Ok, let's do a proper semver release :) Ok, let's do a proper semver release :)

34
Makefile Normal file
View File

@ -0,0 +1,34 @@
VERSION := $(shell node -e "console.log(require('./package.json').version)")
.PHONY: default release smoke
test:
npm test
smoke:
npm install --build-from-source
node smoke/smoketest.js
npm test
release:
@echo "Tagging release $(VERSION)"
@git tag -m "$(VERSION)" v$(VERSION)
@echo "Pushing tags to GitHub"
@git push --tags
@echo "Switching to osx-binaries branch"
@git checkout osx-binaries
@echo "Merging master into osx-binaries"
@git merge --no-ff --commit -m "Merge master into osx-binaries [publish binary]" master
@echo "Pushing osx-binaries"
@git push
@echo "Switching to master branch"
@git checkout master
@echo "Publishing to NPM"
@npm publish

View File

@ -22,6 +22,7 @@ $ npm install opencv
``` ```
## Examples ## Examples
Run the examples from the parent directory.
### Face Detection ### Face Detection

105
appveyor.yml Normal file
View File

@ -0,0 +1,105 @@
# environment variables
environment:
node_pre_gyp_accessKeyId:
secure: 3GHZvq0y83PQ8Qi7FOc5rKoULRQvd2OohhtGqRQLZB4=
node_pre_gyp_secretAccessKey:
secure: AiX8Bx+U8LKu5JZHb5CMth5xOHuWawkQW3il0OFWfV4kodPZnC8dLYIqb4XZeF7f
# try on unstable version of the server to build node-opencv
os: unstable
# to add several platforms to build matrix:
platform:
- x64
install:
- cmd: ECHO "INSTALL OPENCV:"
- cmd: choco install OpenCV
- cmd: ECHO "APPVEYOR_REPO_COMMIT_MESSAGE ->"
- cmd: ECHO %APPVEYOR_REPO_COMMIT_MESSAGE%
- cmd: SET COMMIT_MSG="%APPVEYOR_REPO_COMMIT_MESSAGE%"
- cmd: SET PUBLISH_BINARY=false
# Check to verify the branch is the same than latest tag, if so
# then we publish the binaries if everything else is successful.
- cmd: git describe --tags --always HEAD > _git_tag.tmp
- cmd: SET /p GIT_TAG=<_git_tag.tmp
- cmd: ECHO "LATEST LOCAL TAG:"
- cmd: ECHO %GIT_TAG%
- cmd: ECHO "APPVEYOR REPO BRANCH/TAG:"
- cmd: ECHO %APPVEYOR_REPO_BRANCH%
- cmd: DEL _git_tag.tmp
- cmd: IF x%APPVEYOR_REPO_BRANCH%==x%GIT_TAG% SET PUBLISH_BINARY=true
# Or look for commit message containing `[publish binary]`
- cmd: IF not x%COMMIT_MSG:[publish binary]=%==x%COMMIT_MSG% SET PUBLISH_BINARY=true
- cmd: ECHO "Env Var PUBLISH_BINARY:"
- cmd: ECHO %PUBLISH_BINARY%
- cmd: git clone https://github.com/marcelklehr/nodist.git c:\nodist 2>&1
- cmd: SET PATH=C:\nodist\bin;%PATH%
- cmd: SET NODIST_PREFIX=C:\nodist
before_build:
- cmd: SET ARCH=x64
- cmd: SET NODIST_X64=1
- cmd: call nodist update
- cmd: call nodist stable
- cmd: npm install -g node-gyp
- cmd: SET APP_PATH=%CD%
- cmd: IF EXIST C:\OpenCV* CD C:\OpenCV*
- cmd: SET OPENCV_ROOT_PATH=%CD%\opencv
- cmd: CD %APP_PATH%
- cmd: SET OPENCV_DIR=%OPENCV_ROOT_PATH%\build\%ARCH%\vc12\bin
- cmd: SET PATH=%cd%\node_modules\.bin\;C:\MinGW\bin;C:\GTK\bin;C:\msys\1.0\bin;%OPENCV_DIR%;%PATH%
- cmd: SET PKG_CONFIG_PATH=C:\GTK\lib\pkgconfig
- cmd: DIR %OPENCV_ROOT_PATH%\build\%ARCH%\vc12\bin
- cmd: DIR %OPENCV_ROOT_PATH%\build\%ARCH%\vc12\lib
# Here we need to copy the opencv.pc file from the repo into PKG_CONFIG_PATH
# trick part is to check for the vc12 folder and use that one
- cmd: copy .\utils\opencv_x64.pc C:\GTK\lib\pkgconfig\opencv.pc
# to run your custom scripts instead of automatic MSBuild
build_script:
- cmd: ECHO "BUILDING x64 binary package:"
- cmd: npm install --build-from-source --msvs_version=2013
- cmd: npm test
- cmd: node lib/opencv.js
- cmd: ECHO "PUBLISH x64 binary package:"
- cmd: npm install aws-sdk
- cmd: IF %PUBLISH_BINARY%==true (node-pre-gyp package publish 2>&1)
- cmd: node-pre-gyp clean
- cmd: node-gyp clean
- cmd: npm uninstall -g node-gyp
- cmd: rmdir /q /s node_modules
- cmd: DEL C:\GTK\lib\pkgconfig\opencv.pc
after_build:
- cmd: SET ARCH=x86
- cmd: SET OPENCV_DIR=%OPENCV_ROOT_PATH%\build\%ARCH%\vc12\bin
- cmd: SET PATH=%OPENCV_DIR%;%PATH%
- cmd: SET NODIST_X64=0
- cmd: call nodist update
- cmd: call nodist stable
- cmd: npm install -g node-gyp
- cmd: copy .\utils\opencv_x86.pc C:\GTK\lib\pkgconfig\opencv.pc
- cmd: ECHO "BUILDING x86 binary package:"
- cmd: npm install --build-from-source --msvs_version=2013
- cmd: npm test
- cmd: node lib/opencv.js
- cmd: ECHO "PUBLISH x86 binary package:"
- cmd: npm install aws-sdk
- cmd: IF %PUBLISH_BINARY%==true (node-pre-gyp package publish 2>&1)
- cmd: node-pre-gyp clean
- cmd: node-gyp clean
- cmd: rmdir /q /s node_modules
on_success:
# test installing from binary package works
- cmd: ECHO "ON SUCCESS:"
- cmd: ECHO "Try installing from binary:"
#- cmd: IF %PUBLISH_BINARY%==true npm install --fallback-to-build=false
- cmd: npm install --fallback-to-build=false
# Print Available Binaries
- cmd: node-pre-gyp info
test: OFF
deploy: OFF

View File

@ -1,53 +1,80 @@
{ {
"targets": [{ "targets": [{
"target_name": "opencv" "target_name": "opencv",
, "sources": [ "sources": [
"src/init.cc" "src/init.cc",
, "src/Matrix.cc" "src/Matrix.cc",
, "src/OpenCV.cc" "src/OpenCV.cc",
, "src/CascadeClassifierWrap.cc" "src/CascadeClassifierWrap.cc",
, "src/Contours.cc" "src/Contours.cc",
, "src/Point.cc" "src/Point.cc",
, "src/VideoCaptureWrap.cc" "src/VideoCaptureWrap.cc",
, "src/CamShift.cc" "src/CamShift.cc",
, "src/HighGUI.cc" "src/HighGUI.cc",
, "src/FaceRecognizer.cc" "src/FaceRecognizer.cc",
, "src/BackgroundSubtractor.cc" "src/BackgroundSubtractor.cc",
, "src/Constants.cc" "src/Constants.cc",
, "src/Calib3D.cc" "src/Calib3D.cc",
, "src/ImgProc.cc" "src/ImgProc.cc"
] ],
, 'libraries': [
'<!@(pkg-config --libs opencv)' "libraries": [
] "<!@(pkg-config --libs opencv)"
],
# For windows # For windows
,'include_dirs': [
'<!@(pkg-config --cflags opencv)',
"<!(node -e \"require('nan')\")"
]
, 'cflags': [ "include_dirs": [
'<!@(pkg-config --cflags "opencv >= 2.3.1" )' "<!@(pkg-config --cflags opencv)",
, '-Wall' "<!(node -e \"require('nan')\")"
] ],
, 'cflags!' : [ '-fno-exceptions']
, 'cflags_cc!': [ '-fno-rtti', '-fno-exceptions'] "cflags!" : [ "-fno-exceptions"],
, "conditions": [ "cflags_cc!": [ "-fno-rtti", "-fno-exceptions"],
['OS=="mac"', {
# cflags on OS X are stupid and have to be defined like this "conditions": [
'xcode_settings': { [ "OS==\"linux\"", {
'OTHER_CFLAGS': [ "cflags": [
"-mmacosx-version-min=10.7", "<!@(pkg-config --cflags \"opencv >= 2.3.1\" )",
"-std=c++11", "-Wall"
"-stdlib=libc++",
'<!@(pkg-config --cflags opencv)'
] ]
, "GCC_ENABLE_CPP_RTTI": "YES" }],
, "GCC_ENABLE_CPP_EXCEPTIONS": "YES" [ "OS==\"win\"", {
"cflags": [
"<!@(pkg-config --cflags \"opencv >= 2.4.9\" )",
"-Wall"
],
"msvs_settings": {
"VCCLCompilerTool": {
"ExceptionHandling": "2",
"DisableSpecificWarnings": [ "4530", "4506", "4244" ],
},
}
}],
[ # 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++",
"<!@(pkg-config --cflags opencv)"
],
"GCC_ENABLE_CPP_RTTI": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
} }
}] }]
] ]
}] },
{
"target_name": "action_after_build",
"type": "none",
"dependencies": [ "<(module_name)" ],
"copies": [
{
"files": [ "<(PRODUCT_DIR)/<(module_name).node" ],
"destination": "<(module_path)"
}
]
}]
} }

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<opencv_storage> <opencv_storage>
<cascade> <output type_id="opencv-haar-classifier">
<stageType>BOOST</stageType> <stageType>BOOST</stageType>
<featureType>HOG</featureType> <featureType>HOG</featureType>
<height>24</height> <height>24</height>
@ -835,5 +835,7 @@
16 8 16 8 24</rect></_> 16 8 16 8 24</rect></_>
<_> <_>
<rect> <rect>
16 8 16 8 28</rect></_></features></cascade> 16 8 16 8 28</rect></_></features>
</output>
</opencv_storage> </opencv_storage>

View File

@ -1,14 +1,14 @@
var cv = require('../lib/opencv'); var cv = require('../lib/opencv');
cv.readImage("./files/mona.png", function(err, orig) { cv.readImage("./examples/files/mona.png", function(err, orig) {
if (err) throw err; if (err) throw err;
cv.readImage("./files/over_text.png", function(err, over_text) { cv.readImage("./examples/files/over_text.png", function(err, over_text) {
if (err) throw err; if (err) throw err;
var result = new cv.Matrix(orig.width(), orig.height()); var result = new cv.Matrix(orig.width(), orig.height());
result.addWeighted(orig, 0.7, over_text, 0.9); result.addWeighted(orig, 0.7, over_text, 0.9);
result.save("./tmp/weighted.png"); result.save("./examples/tmp/weighted.png");
console.log('Image saved to ./tmp/weighted.png'); console.log('Image saved to ./examples/tmp/weighted.png');
}); });
}); });

View File

@ -1,12 +1,20 @@
var cv = require('../lib/opencv'); var cv = require('../lib/opencv');
var camera = new cv.VideoCapture(0); try {
var window = new cv.NamedWindow('Video', 0) var camera = new cv.VideoCapture(0);
var window = new cv.NamedWindow('Video', 0)
setInterval(function() { /*
camera.read(function(err, im) { setInterval(function() {
if (err) throw err; camera.read(function(err, im) {
window.show(im); if (err) throw err;
window.blockingWaitKey(0, 50); console.log(im.size())
}); if (im.size()[0] > 0 && im.size()[1] > 0){
}, 20); window.show(im);
}
window.blockingWaitKey(0, 50);
});
}, 20);
*/
} catch (e){
console.log("Couldn't start camera:", e)
}

View File

@ -1,3 +1,6 @@
/* For some reason the cascade file is broken on linux :(
var cv = require('../lib/opencv'); var cv = require('../lib/opencv');
cv.readImage("./files/car1.jpg", function(err, im){ cv.readImage("./files/car1.jpg", function(err, im){
@ -16,3 +19,4 @@ cv.readImage("./files/car1.jpg", function(err, im){
console.log('Image saved to ./tmp/car-detection.jpg'); console.log('Image saved to ./tmp/car-detection.jpg');
}); });
}); });
*/

View File

@ -3,7 +3,7 @@ var http = require('http'),
request = require('request'), request = require('request'),
cv = require('../lib/opencv'); cv = require('../lib/opencv');
http.createServer(function(req, resp){ var server = http.createServer(function(req, resp){
var url = req.url.slice(1); var url = req.url.slice(1);
request({uri:url, encoding:'binary'}, function(err, r, body){ request({uri:url, encoding:'binary'}, function(err, r, body){
if (err) return resp.end(err.stack); if (err) return resp.end(err.stack);
@ -27,4 +27,7 @@ http.createServer(function(req, resp){
}); });
}); });
}).listen(3000, function(){ console.log('Listening on http://localhost:3000'); }) })
//server.listen(3000, function(){ console.log('Listening on http://localhost:3000'); })

View File

@ -1,7 +1,7 @@
var cv = require('../lib/opencv'); var cv = require('../lib/opencv');
cv.readImage("./files/mona.png", function(err, im) { cv.readImage("./files/mona.png", function(err, im) {
salt(im, 1000); salt(im, 100);
im.save("./tmp/salt.png"); im.save("./tmp/salt.png");
console.log('Image saved to ./tmp/salt.png'); console.log('Image saved to ./tmp/salt.png');
}); });

View File

@ -1,24 +1,32 @@
var cv = require('../lib/opencv'); var cv = require('../lib/opencv');
var vid = new cv.VideoCapture(0); try {
var vid = new cv.VideoCapture(0);
vid.read(function(err, im){ vid.read(function(err, im){
if (err) throw err;
im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
if (err) throw err; if (err) throw err;
if (!faces.length) return console.log("No Faces"); if (im.size()[0] > 0 && im.size()[1] > 0){
var face = faces[0]; im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
var ims = im.size(); if (err) throw err;
var im2 = im.roi(face.x, face.y, face.width, face.height) if (!faces.length) return console.log("No Faces");
/*
im.adjustROI( var face = faces[0];
-face.y var ims = im.size();
, (face.y + face.height) - ims[0] var im2 = im.roi(face.x, face.y, face.width, face.height)
, -face.x /*
, (face.x + face.width) - ims[1]) im.adjustROI(
*/ -face.y
im2.save('./tmp/take-face-pics.jpg') , (face.y + face.height) - ims[0]
console.log('Image saved to ./tmp/take-face-pics.jpg'); , -face.x
}) , (face.x + face.width) - ims[1])
}); */
im2.save('./examples/tmp/take-face-pics.jpg')
console.log('Image saved to ./tmp/take-face-pics.jpg');
})
} else {
console.log("Camera didn't return image")
}
});
} catch (e){
console.log("Couldn't start camera", e)
}

View File

@ -1,6 +1,6 @@
var cv = require('../lib/opencv'); var cv = require('../lib/opencv');
cv.readImage("./mona.png", function(err, im) { cv.readImage("./files/mona.png", function(err, im) {
if (err) throw err; if (err) throw err;
var width = im.width(); var width = im.width();
@ -11,6 +11,6 @@ cv.readImage("./mona.png", function(err, im) {
var dstArray = [0, 0, width * 0.9, height * 0.1, width, height, width * 0.2, height * 0.8]; var dstArray = [0, 0, width * 0.9, height * 0.1, width, height, width * 0.2, height * 0.8];
var xfrmMat = im.getPerspectiveTransform(srcArray, dstArray); var xfrmMat = im.getPerspectiveTransform(srcArray, dstArray);
im.warpPerspective(xfrmMat, width, height, [255, 255, 255]); im.warpPerspective(xfrmMat, width, height, [255, 255, 255]);
im.save("./warp-image.png"); im.save("./tmp/warp-image.png");
console.log('Image saved to ./tmp/warp-image.png'); console.log('Image saved to ./tmp/warp-image.png');
}); });

View File

@ -1 +1,7 @@
module.exports = require('../build/Release/opencv.node'); var binary = require('node-pre-gyp');
var path = require('path');
var binding_path = binary.find(path.resolve(path.join(__dirname,'../package.json')));
var binding = require(binding_path);
//module.exports = require('../build/Release/opencv.node');
module.exports = binding;

View File

@ -3,17 +3,23 @@
"description": "Node Bindings to OpenCV", "description": "Node Bindings to OpenCV",
"author": "Peter Braden <peterbraden@peterbraden.co.uk>", "author": "Peter Braden <peterbraden@peterbraden.co.uk>",
"dependencies": { "dependencies": {
"node-pre-gyp": "0.5.31",
"buffers": "0.1.1", "buffers": "0.1.1",
"nan": "1.4.3" "nan": "1.4.3"
}, },
"version": "1.0.0", "version": "3.0.0",
"devDependencies": { "devDependencies": {
"tape": "^3.0.0" "tape": "^3.0.0",
"aws-sdk": "~2.0.21",
"glob": "^4.0.6",
"request": "^2.45.0"
}, },
"bundledDependencies":["node-pre-gyp"],
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"build": "node-gyp build", "build": "node-gyp build",
"test": "node test/unit.js" "test": "node test/unit.js",
"install": "node-pre-gyp install --fallback-to-build"
}, },
"keywords": [ "keywords": [
"opencv", "opencv",
@ -28,5 +34,12 @@
}, },
"engines": { "engines": {
"node": ">=0.10" "node": ">=0.10"
},
"binary": {
"module_name" : "opencv",
"module_path" : "./build/{module_name}/v{version}/{configuration}/{node_abi}-{platform}-{arch}/",
"remote_path" : "./{module_name}/v{version}/{configuration}/",
"package_name": "{node_abi}-{platform}-{arch}.tar.gz",
"host" : "https://node-opencv.s3.amazonaws.com"
} }
} }

71
publish-binaries.md Normal file
View File

@ -0,0 +1,71 @@
How to publish the pre compiled binaries.
=========================================
## Setup for Linux, Windows and OSX
Every time a new tag for the latest release is pushed to github the continous integration
builds in Travis-CI and AppVeyor will generate the binaries for each platform and architecture,
package and publish to the AS3 bucket.
This can be checked in the .travis.yml file and appveyor.yml file. Within the files there are two
methods for publishing new binaries for each version, one is if a `git tag` is detected; the other
can be triggered by passing the string `[publish binary]` in the commit message itself.
We also have an automated make task, we should always use this task to avoid forgetting any steps
(like merging into the `osx-binaries` branch).
The process for generating the binaries, publishing and releasing the npm module should be as follows:
1. Merge all changes and new features into master.
2. Bump up version of npm module in `package.json`.
3. execute make task: `make release`
This task will do the following for you:
1. Generate new tags based on package.json version number
2. Push tags to Github
3. Checkout into `osx-binaries` branch
4. Merge `master` into `osx-binaries`
5. Push `osx-binaries`
6. Checkout master
7. Finally it will run `npm publish`
With this we will make sure the binaries for all platforms and architectures will be generated each time
a new version is released.
## Config Travis, AppVeyor and Github to generate all of the binaries.
Before we are able to run everything stated above some steps need to be taken.
Specifically for being able to publish the pre compiled binaries to AWS-S3. The
correct keys need to be setup in the travis and appveyor `.yml` files. This needs
to be done by the admin of the repo, in the case of Travis, and the owner of the account,
in the case of appveyor.
### Setting up secure keys in Travis.
Setting up the keys in Travis is easy if you have ruby and ruby gems installed and working then install:
`gem install travis`
After the travis gem is installed run the following command for each of the required keys:
`travis encrypt SOMEVAR=secretvalue`
And substitute the values in the `.travis.yml` file for the new ones. Detailed instructions can
be found here: http://docs.travis-ci.com/user/environment-variables/#Secure-Variables
### Setting up secure keys in AppVeyor
It is even easier than Travis, you do not need to install anything, just go to your account and
click in `encrypt tool`, there enter the values in the input field and click encrypt. Same as with
Travis we then need to substitute the newly generated values for the old ones.
Detailed instructions can be found here: http://www.appveyor.com/docs/build-configuration#secure-variables
### OSX binaries
Since Travis does not support config file for multiple OSs we need to create a new branch that contains
a slightly different version of the .travis.yml file to compile for OSX. The branch needs to be called
`osx-binaries` and be based of `master` once the pre-compiled binaries PR has been merged in.

View File

@ -1,14 +0,0 @@
#!/bin/bash
if [ ! -f smoke/smoketest.js ]; then
echo "Please run smoke test from the top-level folder of the repository." >&2
exit 1
fi
node-gyp build && echo '-- Compiled OK --
' && node smoke/smoketest.js && echo '-- Smoke Done, running tests --
' && npm test # && echo '-- Tests Run, runnning examples --
#(building example data)
#' && ./examples/make-example-files.sh && node examples/motion-track.js

View File

@ -1,6 +1,6 @@
var cv = require('../lib/opencv') var cv = require('../lib/opencv');
var trainingData = [] var trainingData = [];
/* /*
for (var i = 1; i< 41; i++){ for (var i = 1; i< 41; i++){
for (var j = 1; j<10; j++){ for (var j = 1; j<10; j++){
@ -22,5 +22,5 @@ cv.readImage("/Users/peterbraden/Downloads/orl_faces/s6/10.pgm", function(e, im)
*/ */
cv.readImage("./examples/files/mona.png", function(e, mat){ cv.readImage("./examples/files/mona.png", function(e, mat){
var th = mat.threshold(200, 200, "Threshold to Zero Inverted"); var th = mat.threshold(200, 200, "Threshold to Zero Inverted");
th.save('./examples/tmp/out.png') th.save('./examples/tmp/out.png');
}) });

View File

@ -136,3 +136,4 @@ BackgroundSubtractorWrap::BackgroundSubtractorWrap(cv::Ptr<cv::BackgroundSubtrac
}; };
#endif #endif

View File

@ -50,7 +50,7 @@ CascadeClassifierWrap::CascadeClassifierWrap(v8::Value* fileName){
class AsyncDetectMultiScale : public NanAsyncWorker { class AsyncDetectMultiScale : public NanAsyncWorker {
public: public:
AsyncDetectMultiScale(NanCallback *callback, CascadeClassifierWrap *cc, Matrix* im, double scale, int neighbors, int minw, int minh, int sleep_for) : NanAsyncWorker(callback), cc(cc), im(im), scale(scale), neighbors(neighbors), minw(minw), minh(minh), sleep_for(sleep_for) {} AsyncDetectMultiScale(NanCallback *callback, CascadeClassifierWrap *cc, Matrix* im, double scale, int neighbors, int minw, int minh) : NanAsyncWorker(callback), cc(cc), im(im), scale(scale), neighbors(neighbors), minw(minw), minh(minh) {}
~AsyncDetectMultiScale() {} ~AsyncDetectMultiScale() {}
void Execute () { void Execute () {
@ -103,7 +103,6 @@ class AsyncDetectMultiScale : public NanAsyncWorker {
int neighbors; int neighbors;
int minw; int minw;
int minh; int minh;
int sleep_for;
std::vector<cv::Rect> res; std::vector<cv::Rect> res;
}; };
@ -141,7 +140,7 @@ NAN_METHOD(CascadeClassifierWrap::DetectMultiScale){
NanCallback *callback = new NanCallback(cb.As<Function>()); NanCallback *callback = new NanCallback(cb.As<Function>());
NanAsyncQueueWorker( new AsyncDetectMultiScale(callback, self, im, scale, neighbors, minw, minh, 1) ); NanAsyncQueueWorker( new AsyncDetectMultiScale(callback, self, im, scale, neighbors, minw, minh) );
NanReturnUndefined(); NanReturnUndefined();
} }

View File

@ -53,7 +53,13 @@ NamedWindow::NamedWindow(const std::string& name, int f){
NAN_METHOD(NamedWindow::Show){ NAN_METHOD(NamedWindow::Show){
SETUP_FUNCTION(NamedWindow) SETUP_FUNCTION(NamedWindow)
Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject()); Matrix *im = ObjectWrap::Unwrap<Matrix>(args[0]->ToObject());
cv::imshow(self->winname, im->mat);
try{
cv::imshow(self->winname, im->mat);
} catch(cv::Exception& e ){
const char* err_msg = e.what();
NanThrowError(err_msg);
}
NanReturnValue(args.Holder()); NanReturnValue(args.Holder());
} }

View File

@ -69,6 +69,7 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(ctor, "drawAllContours", DrawAllContours); NODE_SET_PROTOTYPE_METHOD(ctor, "drawAllContours", DrawAllContours);
NODE_SET_PROTOTYPE_METHOD(ctor, "goodFeaturesToTrack", GoodFeaturesToTrack); NODE_SET_PROTOTYPE_METHOD(ctor, "goodFeaturesToTrack", GoodFeaturesToTrack);
NODE_SET_PROTOTYPE_METHOD(ctor, "houghLinesP", HoughLinesP); NODE_SET_PROTOTYPE_METHOD(ctor, "houghLinesP", HoughLinesP);
NODE_SET_PROTOTYPE_METHOD(ctor, "crop", Crop);
NODE_SET_PROTOTYPE_METHOD(ctor, "houghCircles", HoughCircles); NODE_SET_PROTOTYPE_METHOD(ctor, "houghCircles", HoughCircles);
NODE_SET_PROTOTYPE_METHOD(ctor, "inRange", inRange); NODE_SET_PROTOTYPE_METHOD(ctor, "inRange", inRange);
NODE_SET_PROTOTYPE_METHOD(ctor, "adjustROI", AdjustROI); NODE_SET_PROTOTYPE_METHOD(ctor, "adjustROI", AdjustROI);
@ -82,6 +83,7 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(ctor, "equalizeHist", EqualizeHist); NODE_SET_PROTOTYPE_METHOD(ctor, "equalizeHist", EqualizeHist);
NODE_SET_PROTOTYPE_METHOD(ctor, "floodFill", FloodFill); NODE_SET_PROTOTYPE_METHOD(ctor, "floodFill", FloodFill);
NODE_SET_PROTOTYPE_METHOD(ctor, "matchTemplate", MatchTemplate); NODE_SET_PROTOTYPE_METHOD(ctor, "matchTemplate", MatchTemplate);
NODE_SET_PROTOTYPE_METHOD(ctor, "templateMatches", TemplateMatches);
NODE_SET_PROTOTYPE_METHOD(ctor, "minMaxLoc", MinMaxLoc); NODE_SET_PROTOTYPE_METHOD(ctor, "minMaxLoc", MinMaxLoc);
NODE_SET_PROTOTYPE_METHOD(ctor, "pushBack", PushBack); NODE_SET_PROTOTYPE_METHOD(ctor, "pushBack", PushBack);
NODE_SET_PROTOTYPE_METHOD(ctor, "putText", PutText); NODE_SET_PROTOTYPE_METHOD(ctor, "putText", PutText);
@ -1015,7 +1017,12 @@ NAN_METHOD(Matrix::AddWeighted) {
float beta = args[3]->NumberValue(); float beta = args[3]->NumberValue();
int gamma = 0; int gamma = 0;
cv::addWeighted(src1->mat, alpha, src2->mat, beta, gamma, self->mat); try{
cv::addWeighted(src1->mat, alpha, src2->mat, beta, gamma, self->mat);
} catch(cv::Exception& e ){
const char* err_msg = e.what();
NanThrowError(err_msg);
}
NanReturnNull(); NanReturnNull();
@ -1726,6 +1733,84 @@ NAN_METHOD(Matrix::FloodFill){
NanReturnValue(NanNew<Number>( ret )); NanReturnValue(NanNew<Number>( ret ));
} }
// @author olfox
// Returns an array of the most probable positions
// Usage: output = input.templateMatches(min_probability, max_probability, limit, ascending, min_x_distance, min_y_distance);
NAN_METHOD(Matrix::TemplateMatches){
SETUP_FUNCTION(Matrix)
bool filter_min_probability = (args.Length() >= 1) ? args[0]->IsNumber() : false;
bool filter_max_probability = (args.Length() >= 2) ? args[1]->IsNumber() : false;
double min_probability = filter_min_probability ? args[0]->NumberValue() : 0;
double max_probability = filter_max_probability ? args[1]->NumberValue() : 0;
int limit = (args.Length() >= 3) ? args[2]->IntegerValue() : 0;
bool ascending = (args.Length() >= 4) ? args[3]->BooleanValue() : false;
int min_x_distance = (args.Length() >= 5) ? args[4]->IntegerValue() : 0;
int min_y_distance = (args.Length() >= 6) ? args[5]->IntegerValue() : 0;
cv::Mat_<int> indices;
if (ascending)
cv::sortIdx(self->mat.reshape(0,1), indices, CV_SORT_ASCENDING + CV_SORT_EVERY_ROW);
else
cv::sortIdx(self->mat.reshape(0,1), indices, CV_SORT_DESCENDING + CV_SORT_EVERY_ROW);
cv::Mat hit_mask = cv::Mat::zeros(self->mat.size(), CV_64F);
v8::Local<v8::Array> probabilites_array = NanNew<v8::Array>(limit);
cv::Mat_<float>::const_iterator begin = self->mat.begin<float>();
cv::Mat_<int>::const_iterator it = indices.begin();
cv::Mat_<int>::const_iterator end = indices.end();
int index = 0;
for (; (limit == 0 || index < limit) && it != end; ++it) {
cv::Point pt = (begin + *it).pos();
float probability = self->mat.at<float>(pt.y, pt.x);
if (filter_min_probability && probability < min_probability) {
if (ascending) continue;
else break;
}
if (filter_max_probability && probability > max_probability) {
if (ascending) break;
else continue;
}
if (min_x_distance != 0 || min_y_distance != 0) {
// Check hit mask color for for every corner
cv::Size maxSize = hit_mask.size();
int max_x = maxSize.width - 1;
int max_y = maxSize.height - 1;
cv::Point top_left = cv::Point(max(0, pt.x - min_x_distance), max(0, pt.y - min_y_distance));
cv::Point top_right = cv::Point(min(max_x, pt.x + min_x_distance), max(0, pt.y - min_y_distance));
cv::Point bottom_left = cv::Point(max(0, pt.x - min_x_distance), min(max_y, pt.y + min_y_distance));
cv::Point bottom_right = cv::Point(min(max_x, pt.x + min_x_distance), min(max_y, pt.y + min_y_distance));
if (hit_mask.at<double>(top_left.y, top_left.x) > 0) continue;
if (hit_mask.at<double>(top_right.y, top_right.x) > 0) continue;
if (hit_mask.at<double>(bottom_left.y, bottom_left.x) > 0) continue;
if (hit_mask.at<double>(bottom_right.y, bottom_right.x) > 0) continue;
cv::Scalar color(255.0);
cv::rectangle(hit_mask, top_left, bottom_right, color, CV_FILLED);
}
Local<Value> x_value = NanNew<Number>(pt.x);
Local<Value> y_value = NanNew<Number>(pt.y);
Local<Value> probability_value = NanNew<Number>(probability);
Local<Object> probability_object = NanNew<Object>();
probability_object->Set(NanNew<String>("x"), x_value);
probability_object->Set(NanNew<String>("y"), y_value);
probability_object->Set(NanNew<String>("probability"), probability_value);
probabilites_array->Set(index, probability_object);
index++;
}
NanReturnValue(probabilites_array);
}
// @author ytham // @author ytham
// Match Template filter // Match Template filter
// Usage: output = input.matchTemplate("templateFileString", method); // Usage: output = input.matchTemplate("templateFileString", method);

View File

@ -96,6 +96,7 @@ class Matrix: public node::ObjectWrap {
JSFUNC(FloodFill) JSFUNC(FloodFill)
JSFUNC(MatchTemplate) JSFUNC(MatchTemplate)
JSFUNC(TemplateMatches)
JSFUNC(MinMaxLoc) JSFUNC(MinMaxLoc)
JSFUNC(PushBack) JSFUNC(PushBack)

21
test/examples.js Normal file
View File

@ -0,0 +1,21 @@
var test = require('tape')
, glob = require('glob')
, exec = require('child_process').exec
, path = require('path')
module.exports = function(){
glob.sync('./examples/*.js').forEach(function(example){
test("Example: " + example, function(assert){
var fullName = path.resolve(example)
, examples = path.resolve('./examples')
exec('node ' + fullName, {cwd: examples}, function(error, stdout, stderr){
assert.error(error)
assert.end()
})
})
})
}

View File

@ -275,3 +275,7 @@ test("fonts", function(t) {
}); });
}) })
// Test the examples folder.
require('./examples')()

13
utils/opencv_x64.pc Normal file
View File

@ -0,0 +1,13 @@
# Package Information for pkg-config
opencv_prefix=C:/OpenCV249/opencv/build/x64/vc12
exec_prefix=${opencv_prefix}/bin
libdir=${opencv_prefix}/lib
includedir=C:/OpenCV249/opencv/build/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.9
Cflags: ${includedir} ${includedir}/opencv
Libs: ${libdir}/opencv_calib3d249 ${libdir}/opencv_contrib249 ${libdir}/opencv_core249 ${libdir}/opencv_features2d249 ${libdir}/opencv_flann249 ${libdir}/opencv_gpu249 ${libdir}/opencv_highgui249 ${libdir}/opencv_imgproc249 ${libdir}/opencv_legacy249 ${libdir}/opencv_ml249 ${libdir}/opencv_nonfree249 ${libdir}/opencv_objdetect249 ${libdir}/opencv_ocl249 ${libdir}/opencv_photo249 ${libdir}/opencv_stitching249 ${libdir}/opencv_superres249 ${libdir}/opencv_ts249 ${libdir}/opencv_video249 ${libdir}/opencv_videostab249

12
utils/opencv_x86.pc Normal file
View File

@ -0,0 +1,12 @@
# Package Information for pkg-config
opencv_prefix=C:/OpenCV249/opencv/build/x86/vc12
exec_prefix=${opencv_prefix}/bin
libdir=${opencv_prefix}/lib
includedir=C:/OpenCV249/opencv/build/include
Name: OpenCV
Description: Open Source Computer Vision Library
Version: 2.4.9
Cflags: ${includedir} ${includedir}/opencv
Libs: ${libdir}/opencv_calib3d249 ${libdir}/opencv_contrib249 ${libdir}/opencv_core249 ${libdir}/opencv_features2d249 ${libdir}/opencv_flann249 ${libdir}/opencv_gpu249 ${libdir}/opencv_highgui249 ${libdir}/opencv_imgproc249 ${libdir}/opencv_legacy249 ${libdir}/opencv_ml249 ${libdir}/opencv_nonfree249 ${libdir}/opencv_objdetect249 ${libdir}/opencv_ocl249 ${libdir}/opencv_photo249 ${libdir}/opencv_stitching249 ${libdir}/opencv_superres249 ${libdir}/opencv_ts249 ${libdir}/opencv_video249 ${libdir}/opencv_videostab249