mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
added mask parameter
This commit is contained in:
parent
569a1143cd
commit
2704d607fe
26
examples/mat-normalize.js
Normal file
26
examples/mat-normalize.js
Normal file
@ -0,0 +1,26 @@
|
||||
var cv = require('../lib/opencv');
|
||||
|
||||
|
||||
|
||||
|
||||
cv.readImage("./examples/files/mona.png", function(err, orig) {
|
||||
if (err) throw err;
|
||||
orig.convertGrayscale();
|
||||
|
||||
var mask = new cv.Matrix(orig.height(),orig.width(),cv.Constants.CV_8UC1);
|
||||
var buf = Buffer(orig.height()*orig.width());
|
||||
buf.fill(0);
|
||||
for(var i=0;i<buf.length;i++){
|
||||
buf[i] = (i%2===1)?0:255;
|
||||
}
|
||||
mask.put(buf);
|
||||
orig.normalize(10,250,cv.Constants.NORM_TYPE_MASK,-1,mask);
|
||||
/*
|
||||
var window = new cv.NamedWindow('Mat-Normalize', 0);
|
||||
window.show(orig);
|
||||
window.blockingWaitKey(0, 50);
|
||||
setTimeout(function(){
|
||||
// keep the windows 30sec open
|
||||
},30000);
|
||||
*/
|
||||
});
|
||||
@ -321,12 +321,43 @@ NAN_METHOD(Matrix::Normalize) {
|
||||
if (!args[1]->IsNumber())
|
||||
NanThrowTypeError("max is required (argument 2)");
|
||||
|
||||
int min = args[0]->Uint32Value();
|
||||
int max = args[1]->Uint32Value();
|
||||
int type = cv::NORM_MINMAX;
|
||||
if (args[2]->IsNumber()){
|
||||
type = args[2]->Uint32Value();
|
||||
if (
|
||||
(type!=cv::NORM_MINMAX) ||
|
||||
(type!=cv::NORM_INF) ||
|
||||
(type!=cv::NORM_L1) ||
|
||||
(type!=cv::NORM_L2) ||
|
||||
(type!=cv::NORM_L2SQR) ||
|
||||
(type!=cv::NORM_HAMMING) ||
|
||||
(type!=cv::NORM_HAMMING2) ||
|
||||
(type!=cv::NORM_RELATIVE) ||
|
||||
(type!=cv::NORM_TYPE_MASK)
|
||||
){
|
||||
NanThrowTypeError("type value must be NORM_INF=1, NORM_L1=2, NORM_L2=4, NORM_L2SQR=5, NORM_HAMMING=6, NORM_HAMMING2=7, NORM_TYPE_MASK=7, NORM_RELATIVE=8, NORM_MINMAX=32 ");
|
||||
}
|
||||
}
|
||||
int dtype = -1;
|
||||
if (args[3]->IsNumber()){
|
||||
dtype = args[3]->IntegerValue();
|
||||
}
|
||||
|
||||
double min = args[0]->NumberValue();
|
||||
double max = args[1]->NumberValue();
|
||||
|
||||
|
||||
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||
cv::Mat norm;
|
||||
cv::normalize(self->mat, norm,min,max, cv::NORM_MINMAX);
|
||||
|
||||
cv::Mat mask;
|
||||
if (args[4]->IsObject()){
|
||||
Matrix *mmask = ObjectWrap::Unwrap<Matrix>( args[4]->ToObject() );
|
||||
mask = mmask->mat;
|
||||
}
|
||||
|
||||
|
||||
cv::normalize(self->mat, norm,min,max, type, dtype, mask);
|
||||
|
||||
norm.copyTo(self->mat);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user