Skip to content

Commit

Permalink
Base OpenCV 3 port
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vines committed Feb 8, 2016
1 parent 090e9d7 commit 2a81f23
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 22 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ cool, I'd love to hear about it!

## Install

You'll need OpenCV 2.3.1 or newer installed before installing node-opencv.
You'll need OpenCV 2.3.1 or newer installed before installing node-opencv. Note
that OpenCV 3.x is not yet fully supported.

## Specific for Windows
1. Download and install OpenCV (Be sure to use a 2.4 version) @
Expand Down
10 changes: 5 additions & 5 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"conditions": [
[ "OS==\"linux\" or OS==\"freebsd\" or OS==\"openbsd\" or OS==\"solaris\" or OS==\"aix\"", {
"cflags": [
"<!@(pkg-config --cflags \"opencv >= 2.3.1\" )",
"<!@(node utils/find-opencv.js --cflags)",
"-Wall"
]
}],
Expand All @@ -64,7 +64,7 @@
"-mmacosx-version-min=10.7",
"-std=c++11",
"-stdlib=libc++",
"<!@(pkg-config --cflags opencv)"
"<!@(node utils/find-opencv.js --cflags)",
],
"GCC_ENABLE_CPP_RTTI": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
Expand All @@ -80,7 +80,7 @@
],

"libraries": [
"<!@(node utils/find-opencv.js --libs)"
"<!@(node utils/find-opencv.js --libs)",
],
# For windows

Expand All @@ -96,7 +96,7 @@
"conditions": [
[ "OS==\"linux\"", {
"cflags": [
"<!@(pkg-config --cflags \"opencv >= 2.3.1\" )",
"<!@(node utils/find-opencv.js --cflags)",
"-Wall"
]
}],
Expand All @@ -121,7 +121,7 @@
"-mmacosx-version-min=10.7",
"-std=c++11",
"-stdlib=libc++",
"<!@(pkg-config --cflags opencv)"
"<!@(node utils/find-opencv.js --cflags)",
],
"GCC_ENABLE_CPP_RTTI": "YES",
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
Expand Down
5 changes: 5 additions & 0 deletions examples/dissimilarity.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
var cv = require('../lib/opencv');

if (cv.ImageSimilarity === undefined) {
console.log('TODO: Please port Features2d.cc to OpenCV 3')
process.exit(0);
}

cv.readImage("./examples/files/car1.jpg", function(err, car1) {
if (err) throw err;

Expand Down
6 changes: 5 additions & 1 deletion src/BackgroundSubtractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
#include <iostream>
#include <nan.h>

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
#if CV_MAJOR_VERSION >= 3
#warning TODO: port me to OpenCV 3
#endif

#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4))

Nan::Persistent<FunctionTemplate> BackgroundSubtractorWrap::constructor;

Expand Down
2 changes: 1 addition & 1 deletion src/BackgroundSubtractor.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "OpenCV.h"

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4))

#include <opencv2/video/background_segm.hpp>

Expand Down
4 changes: 4 additions & 0 deletions src/Calib3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

#include "OpenCV.h"

#if CV_MAJOR_VERSION >= 3
#include <opencv2/calib3d.hpp>
#endif

/**
* Implementation of calib3d.hpp functions
*/
Expand Down
3 changes: 3 additions & 0 deletions src/CamShift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include "OpenCV.h"
#include "Matrix.h"

#if CV_MAJOR_VERSION >= 3
#include <opencv2/video/tracking.hpp>
#endif

#define CHANNEL_HUE 0
#define CHANNEL_SATURATION 1
Expand Down
3 changes: 3 additions & 0 deletions src/CascadeClassifierWrap.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "OpenCV.h"
#if CV_MAJOR_VERSION >= 3
#include <opencv2/objdetect.hpp>
#endif

class CascadeClassifierWrap: public Nan::ObjectWrap {
public:
Expand Down
6 changes: 5 additions & 1 deletion src/FaceRecognizer.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "FaceRecognizer.h"
#include "OpenCV.h"

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
#if CV_MAJOR_VERSION >= 3
#warning TODO: port me to OpenCV 3
#endif

#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))

#include "Matrix.h"
#include <nan.h>
Expand Down
2 changes: 1 addition & 1 deletion src/FaceRecognizer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "OpenCV.h"

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))

#include "opencv2/contrib/contrib.hpp"

Expand Down
5 changes: 3 additions & 2 deletions src/Features2d.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "OpenCV.h"

#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4))
#include "Features2d.h"
#include "Matrix.h"
#include <nan.h>
#include <stdio.h>

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))

void Features::Init(Local<Object> target) {
Nan::HandleScope scope;

Expand Down
2 changes: 1 addition & 1 deletion src/Features2d.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "OpenCV.h"

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4))

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
Expand Down
7 changes: 5 additions & 2 deletions src/LDAWrap.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include "LDAWrap.h"
#include "OpenCV.h"

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
#if CV_MAJOR_VERSION >= 3
#warning TODO: port me to OpenCV 3
#endif

#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
#include "LDAWrap.h"
#include "Matrix.h"
#include <nan.h>

Expand Down
2 changes: 1 addition & 1 deletion src/LDAWrap.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "OpenCV.h"

#if ((CV_MAJOR_VERSION >= 2) && (CV_MINOR_VERSION >=4))
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4))

#include "opencv2/contrib/contrib.hpp"

Expand Down
5 changes: 5 additions & 0 deletions src/OpenCV.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
#include <node_buffer.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
#if CV_MAJOR_VERSION >= 3
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#endif
#include <string.h>
#include <nan.h>

Expand Down
9 changes: 9 additions & 0 deletions src/Stereo.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

#include "Stereo.h"

#if CV_MAJOR_VERSION >= 3
#warning TODO: port me to OpenCV 3
#endif

#if CV_MAJOR_VERSION < 3
#include "Matrix.h"
#include <opencv2/legacy/legacy.hpp>

Expand Down Expand Up @@ -312,3 +319,5 @@ NAN_METHOD(StereoGC::Compute) {
return;
}
}

#endif
3 changes: 3 additions & 0 deletions src/Stereo.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "OpenCV.h"

#if CV_MAJOR_VERSION < 3

class StereoBM: public Nan::ObjectWrap {
public:
cv::StereoBM stereo;
Expand Down Expand Up @@ -51,3 +53,4 @@ class StereoGC: public Nan::ObjectWrap {
};

#endif
#endif // __NODE_STEREO_H
9 changes: 6 additions & 3 deletions src/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ extern "C" void init(Local<Object> target) {
Constants::Init(target);
Calib3D::Init(target);
ImgProc::Init(target);
#if CV_MAJOR_VERSION < 3
StereoBM::Init(target);
StereoSGBM::Init(target);
StereoGC::Init(target);

#if CV_MAJOR_VERSION >= 2 && CV_MINOR_VERSION >=4
#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >=4
BackgroundSubtractorWrap::Init(target);
Features::Init(target);
FaceRecognizerWrap::Init(target);
LDAWrap::Init(target);
#if CV_SUBMINOR_VERSION>=4
FaceRecognizerWrap::Init(target);
#endif
#endif
#endif
};

Expand Down
6 changes: 6 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ test("fonts", function(t) {
})

test('LDA Wrap', function(assert) {
if (cv.LDA === undefined) {
console.log('TODO: Please port LDAWrap.cc to OpenCV 3')
assert.end();
return;
}

// subspaceProject
var mat = cv.LDA.subspaceProject(new cv.Matrix(1, 2, cv.Constants.CV_64F), new cv.Matrix(), new cv.Matrix(2, 1, cv.Constants.CV_8UC1));
assert.deepEqual(mat.size(), [2,2], 'subspaceProject');
Expand Down
14 changes: 11 additions & 3 deletions utils/find-opencv.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
"use strict";

var exec = require("child_process").exec;
var fs = require("fs");
var flag = process.argv[2];
var flag = process.argv[2] || "--exists";

// Normally |pkg-config opencv ...| could report either OpenCV 2.x or OpenCV 3.y
// depending on what is installed. To enable both 2.x and 3.y to co-exist on
// the same machine, the opencv.pc for 3.y can be installed as opencv3.pc and
// then selected by |export PKG_CONFIG_OPENCV3=1| before building node-opencv.
var opencv = process.env.PKG_CONFIG_OPENCV3 === "1" ? "opencv3" : '"opencv >= 2.3.1"';

function main(){
//Try using pkg-config, but if it fails and it is on Windows, try the fallback
exec("pkg-config opencv " + flag, function(error, stdout, stderr){
exec("pkg-config " + opencv + " " + flag, function(error, stdout, stderr){
if(error){
if(process.platform === "win32"){
fallback();
}
else{
throw new Error("ERROR: pkg-config couldn't find OpenCV");
throw new Error("ERROR: failed to run: pkg-config", opencv, flag);
}
}
else{
Expand Down

0 comments on commit 2a81f23

Please sign in to comment.