mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
Add logic for available modules
With OpenCV >3.1 and 2.4.13, OpenCV can now be installed without specific modules. This makes it so that `node-opencv` will still be able to compile.
This commit is contained in:
parent
52333d460f
commit
95b0596245
@ -11,7 +11,7 @@
|
||||
*/
|
||||
#ifndef NODE_OPENCV_MATRIX_H
|
||||
#define NODE_OPENCV_MATRIX_H
|
||||
#include <opencv/cv.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <node_object_wrap.h>
|
||||
|
||||
namespace node_opencv {
|
||||
|
||||
@ -7,15 +7,14 @@ var Stream = require('stream').Stream
|
||||
var cv = module.exports = require('./bindings');
|
||||
|
||||
var Matrix = cv.Matrix
|
||||
, VideoCapture = cv.VideoCapture
|
||||
, VideoWriter = cv.VideoWriter
|
||||
, ImageStream
|
||||
, ImageDataStream
|
||||
, ObjectDetectionStream
|
||||
, VideoStream;
|
||||
|
||||
|
||||
Matrix.prototype.detectObject = function(classifier, opts, cb){
|
||||
if (cv.CascadeClassifier) {
|
||||
Matrix.prototype.detectObject = function(classifier, opts, cb){
|
||||
var face_cascade;
|
||||
opts = opts || {};
|
||||
cv._detectObjectClassifiers = cv._detectObjectClassifiers || {};
|
||||
@ -27,10 +26,15 @@ Matrix.prototype.detectObject = function(classifier, opts, cb){
|
||||
|
||||
face_cascade.detectMultiScale(this, cb, opts.scale, opts.neighbors
|
||||
, opts.min && opts.min[0], opts.min && opts.min[1]);
|
||||
}
|
||||
} else {
|
||||
cv.Matrix.prototype.detectObject = function() {
|
||||
throw new Error("You need to install OpenCV with OBJDETECT module");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Matrix.prototype.inspect = function(){
|
||||
cv.Matrix.prototype.inspect = function(){
|
||||
var size = (this.size()||[]).join('x');
|
||||
return "[ Matrix " + size + " ]";
|
||||
}
|
||||
@ -189,17 +193,16 @@ ImageDataStream.prototype.end = function(b){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
ObjectDetectionStream = cv.ObjectDetectionStream = function(cascade, opts){
|
||||
if (cv.CascadeClassifier) {
|
||||
ObjectDetectionStream = cv.ObjectDetectionStream = function(cascade, opts){
|
||||
this.classifier = new cv.CascadeClassifier(cascade);
|
||||
this.opts = opts || {};
|
||||
this.readable = true;
|
||||
this.writable = true;
|
||||
}
|
||||
util.inherits(ObjectDetectionStream, Stream);
|
||||
}
|
||||
util.inherits(ObjectDetectionStream, Stream);
|
||||
|
||||
|
||||
ObjectDetectionStream.prototype.write = function(m){
|
||||
ObjectDetectionStream.prototype.write = function(m){
|
||||
var self = this;
|
||||
this.classifier.detectMultiScale(m, function(err, objs){
|
||||
if (err) return self.emit('error', err);
|
||||
@ -209,19 +212,23 @@ ObjectDetectionStream.prototype.write = function(m){
|
||||
, this.opts.neighbors
|
||||
, this.opts.min && this.opts.min[0]
|
||||
, this.opts.min && this.opts.min[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VideoStream = cv.VideoStream = function(src){
|
||||
if (cv.VideoCapture) {
|
||||
var VideoCapture = cv.VideoCapture
|
||||
|
||||
VideoStream = cv.VideoStream = function(src){
|
||||
if (!(src instanceof VideoCapture)) src = new VideoCapture(src);
|
||||
this.video = src;
|
||||
this.readable = true;
|
||||
this.paused = false;
|
||||
}
|
||||
util.inherits(VideoStream, Stream);
|
||||
}
|
||||
util.inherits(VideoStream, Stream);
|
||||
|
||||
|
||||
VideoStream.prototype.read = function(){
|
||||
VideoStream.prototype.read = function(){
|
||||
var self = this;
|
||||
var frame = function(){
|
||||
self.video.read(function(err, mat){
|
||||
@ -232,26 +239,24 @@ VideoStream.prototype.read = function(){
|
||||
}
|
||||
|
||||
frame();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VideoStream.prototype.pause = function(){
|
||||
VideoStream.prototype.pause = function(){
|
||||
this.paused = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VideoStream.prototype.resume = function(){
|
||||
VideoStream.prototype.resume = function(){
|
||||
this.paused = false;
|
||||
this.read();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VideoCapture.prototype.toStream = function(){
|
||||
VideoCapture.prototype.toStream = function(){
|
||||
return new VideoStream(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Provide cascade data for faces etc.
|
||||
var CASCADES = {
|
||||
FACE_CASCADE: 'haarcascade_frontalface_alt.xml'
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include <iostream>
|
||||
#include <nan.h>
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
|
||||
#if CV_MAJOR_VERSION >= 3
|
||||
#warning TODO: port me to OpenCV 3
|
||||
#endif
|
||||
@ -129,3 +131,4 @@ BackgroundSubtractorWrap::BackgroundSubtractorWrap(
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
|
||||
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
#include <opencv2/video/background_segm.hpp>
|
||||
@ -19,3 +21,5 @@ public:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include "Calib3D.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_CALIB3D
|
||||
|
||||
inline Local<Object> matrixFromMat(cv::Mat &input) {
|
||||
Local<Object> matrixWrap =
|
||||
Nan::NewInstance(Nan::GetFunction(Nan::New(Matrix::constructor)).ToLocalChecked()).ToLocalChecked();
|
||||
@ -564,3 +566,5 @@ NAN_METHOD(Calib3D::ReprojectImageTo3D) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
|
||||
#include "OpenCV.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_CALIB3D
|
||||
|
||||
#if CV_MAJOR_VERSION >= 3
|
||||
#include <opencv2/calib3d.hpp>
|
||||
#endif
|
||||
@ -25,3 +27,4 @@ public:
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
#include "OpenCV.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
|
||||
#if CV_MAJOR_VERSION >= 3
|
||||
#include <opencv2/video/tracking.hpp>
|
||||
#endif
|
||||
@ -176,3 +178,5 @@ NAN_METHOD(TrackedObject::Track) {
|
||||
|
||||
info.GetReturnValue().Set(arr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
|
||||
class TrackedObject: public Nan::ObjectWrap {
|
||||
public:
|
||||
@ -20,3 +21,5 @@ public:
|
||||
|
||||
JSFUNC(Track);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
#include "Matrix.h"
|
||||
#include <nan.h>
|
||||
|
||||
#ifdef HAVE_OPENCV_OBJDETECT
|
||||
|
||||
Nan::Persistent<FunctionTemplate> CascadeClassifierWrap::constructor;
|
||||
|
||||
void CascadeClassifierWrap::Init(Local<Object> target) {
|
||||
@ -149,3 +151,5 @@ NAN_METHOD(CascadeClassifierWrap::DetectMultiScale) {
|
||||
neighbors, minw, minh));
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_OBJDETECT
|
||||
|
||||
#if CV_MAJOR_VERSION >= 3
|
||||
#include <opencv2/objdetect.hpp>
|
||||
#include <opencv2/objdetect.hpp>
|
||||
#endif
|
||||
|
||||
class CascadeClassifierWrap: public Nan::ObjectWrap {
|
||||
@ -20,3 +23,5 @@ public:
|
||||
static void EIO_DetectMultiScale(uv_work_t *req);
|
||||
static int EIO_AfterDetectMultiScale(uv_work_t *req);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -6,6 +6,8 @@
|
||||
#include <nan.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
|
||||
void Features::Init(Local<Object> target) {
|
||||
Nan::HandleScope scope;
|
||||
|
||||
@ -112,3 +114,4 @@ NAN_METHOD(Features::Similarity) {
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4))
|
||||
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/features2d/features2d.hpp>
|
||||
|
||||
@ -14,3 +16,5 @@ public:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
#include "OpenCV.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
|
||||
Nan::Persistent<FunctionTemplate> NamedWindow::constructor;
|
||||
|
||||
void NamedWindow::Init(Local<Object> target) {
|
||||
@ -82,3 +84,5 @@ NAN_METHOD(NamedWindow::BlockingWaitKey) {
|
||||
|
||||
info.GetReturnValue().Set(Nan::New<Number>(res));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
|
||||
class NamedWindow: public Nan::ObjectWrap {
|
||||
public:
|
||||
std::string winname;
|
||||
@ -17,3 +19,5 @@ public:
|
||||
;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
#include "ImgProc.h"
|
||||
#include "Matrix.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_IMGPROC
|
||||
|
||||
void ImgProc::Init(Local<Object> target) {
|
||||
Nan::Persistent<Object> inner;
|
||||
Local<Object> obj = Nan::New<Object>();
|
||||
@ -233,3 +235,5 @@ NAN_METHOD(ImgProc::GetStructuringElement) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -3,6 +3,8 @@
|
||||
|
||||
#include "OpenCV.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_IMGPROC
|
||||
|
||||
/**
|
||||
* Implementation of imgproc.hpp functions
|
||||
*/
|
||||
@ -17,3 +19,5 @@ public:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
35
src/OpenCV.h
35
src/OpenCV.h
@ -10,22 +10,41 @@
|
||||
#endif
|
||||
|
||||
|
||||
#include <opencv2/core/version.hpp>
|
||||
#if !((((CV_MAJOR_VERSION <= 2) && (CV_MINOR_VERSION <= 4)) && (CV_MINOR_VERSION < 13)) || ((CV_MAJOR_VERSION >= 3) && (CV_MINOR_VERSION < 1)))
|
||||
#define INCLUDE_AVAILABLE_MODULES_ONLY
|
||||
#endif
|
||||
|
||||
#include <v8.h>
|
||||
#include <node.h>
|
||||
#include <node_object_wrap.h>
|
||||
#include <node_version.h>
|
||||
#include <node_buffer.h>
|
||||
#include <opencv/cv.h>
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
#if ((CV_MAJOR_VERSION <= 2) && (CV_MINOR_VERSION <= 4) && (CV_MINOR_VERSION < 10))
|
||||
#include <opencv/highgui.h>
|
||||
#if CV_MAJOR_VERSION >= 3
|
||||
#include <opencv2/highgui.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/opencv_modules.hpp>
|
||||
#else
|
||||
#include <opencv2/imgcodecs/imgcodecs_c.h>
|
||||
#endif
|
||||
#if ((CV_MAJOR_VERSION == 2) && (CV_MINOR_VERSION >=4) && (CV_SUBMINOR_VERSION>=4))
|
||||
#define HAVE_OPENCV_FACE
|
||||
|
||||
#ifndef INCLUDE_AVAILABLE_MODULES_ONLY
|
||||
#define HAVE_OPENCV_CALIB3D
|
||||
#define HAVE_OPENCV_FEATURES2D
|
||||
#define HAVE_OPENCV_FLANN
|
||||
#define HAVE_OPENCV_HIGHGUI
|
||||
// #define HAVE_OPENCV_IMGCODECS
|
||||
#define HAVE_OPENCV_IMGPROC
|
||||
#define HAVE_OPENCV_ML
|
||||
#define HAVE_OPENCV_OBJDETECT
|
||||
#define HAVE_OPENCV_PHOTO
|
||||
#define HAVE_OPENCV_SHAPE
|
||||
#define HAVE_OPENCV_STITCHING
|
||||
#define HAVE_OPENCV_SUPERRES
|
||||
#define HAVE_OPENCV_VIDEO
|
||||
#define HAVE_OPENCV_VIDEOIO
|
||||
#define HAVE_OPENCV_VIDEOSTAB
|
||||
#define HAVE_OPENCV_VIZ
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEOIO
|
||||
|
||||
Nan::Persistent<FunctionTemplate> VideoCaptureWrap::constructor;
|
||||
|
||||
struct videocapture_baton {
|
||||
@ -311,3 +313,5 @@ NAN_METHOD(VideoCaptureWrap::Retrieve) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include "OpenCV.h"
|
||||
|
||||
#ifdef HAVE_OPENCV_VIDEOIO
|
||||
|
||||
class VideoCaptureWrap: public Nan::ObjectWrap {
|
||||
public:
|
||||
cv::VideoCapture cap;
|
||||
@ -36,3 +38,5 @@ public:
|
||||
// release the stream
|
||||
static NAN_METHOD(Release);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
16
src/init.cc
16
src/init.cc
@ -24,23 +24,39 @@ extern "C" void init(Local<Object> target) {
|
||||
|
||||
Point::Init(target);
|
||||
Matrix::Init(target);
|
||||
#ifdef HAVE_OPENCV_OBJDETECT
|
||||
CascadeClassifierWrap::Init(target);
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_VIDEOIO
|
||||
VideoCaptureWrap::Init(target);
|
||||
VideoWriterWrap::Init(target);
|
||||
#endif
|
||||
Contour::Init(target);
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
TrackedObject::Init(target);
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_HIGHGUI
|
||||
NamedWindow::Init(target);
|
||||
#endif
|
||||
Constants::Init(target);
|
||||
#ifdef HAVE_OPENCV_CALIB3D
|
||||
Calib3D::Init(target);
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_IMGPROC
|
||||
ImgProc::Init(target);
|
||||
Histogram::Init(target);
|
||||
#endif
|
||||
#if CV_MAJOR_VERSION < 3
|
||||
StereoBM::Init(target);
|
||||
StereoSGBM::Init(target);
|
||||
StereoGC::Init(target);
|
||||
#if CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION >=4
|
||||
#ifdef HAVE_OPENCV_VIDEO
|
||||
BackgroundSubtractorWrap::Init(target);
|
||||
#endif
|
||||
#ifdef HAVE_OPENCV_FEATURES2D
|
||||
Features::Init(target);
|
||||
#endif
|
||||
LDAWrap::Init(target);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user