mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
putText with font and color support
This commit is contained in:
parent
857e88fa21
commit
ee25c1f2ee
@ -14,6 +14,7 @@
|
|||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"build": "node-gyp build",
|
||||||
"preinstall": "node-gyp clean rebuild",
|
"preinstall": "node-gyp clean rebuild",
|
||||||
"test": "vows test/unit.js"
|
"test": "vows test/unit.js"
|
||||||
},
|
},
|
||||||
|
|||||||
@ -97,6 +97,8 @@ Matrix::Init(Handle<Object> target) {
|
|||||||
|
|
||||||
NODE_SET_PROTOTYPE_METHOD(constructor, "pushBack", PushBack);
|
NODE_SET_PROTOTYPE_METHOD(constructor, "pushBack", PushBack);
|
||||||
|
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(constructor, "putText", PutText);
|
||||||
|
|
||||||
NODE_SET_METHOD(constructor, "Eye", Eye);
|
NODE_SET_METHOD(constructor, "Eye", Eye);
|
||||||
|
|
||||||
|
|
||||||
@ -1650,3 +1652,43 @@ Matrix::PushBack(const v8::Arguments& args) {
|
|||||||
|
|
||||||
return scope.Close(args.This());
|
return scope.Close(args.This());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle<Value>
|
||||||
|
Matrix::PutText(const v8::Arguments& args) {
|
||||||
|
HandleScope scope;
|
||||||
|
|
||||||
|
Matrix *self = ObjectWrap::Unwrap<Matrix>(args.This());
|
||||||
|
|
||||||
|
v8::String::AsciiValue textString(args[0]);
|
||||||
|
char *text = (char *) malloc(textString.length() + 1);
|
||||||
|
strcpy(text, *textString);
|
||||||
|
|
||||||
|
int x = args[1]->IntegerValue();
|
||||||
|
int y = args[2]->IntegerValue();
|
||||||
|
|
||||||
|
v8::String::AsciiValue fontString(args[3]);
|
||||||
|
char *font = (char *) malloc(fontString.length() + 1);
|
||||||
|
strcpy(font, *fontString);
|
||||||
|
int constFont = cv::FONT_HERSHEY_SIMPLEX;
|
||||||
|
|
||||||
|
if (!strcmp(font, "HERSEY_SIMPLEX")) { constFont = cv::FONT_HERSHEY_SIMPLEX; }
|
||||||
|
else if (!strcmp(font, "HERSEY_PLAIN")) { constFont = cv::FONT_HERSHEY_PLAIN; }
|
||||||
|
else if (!strcmp(font, "HERSEY_DUPLEX")) { constFont = cv::FONT_HERSHEY_DUPLEX; }
|
||||||
|
else if (!strcmp(font, "HERSEY_COMPLEX")) { constFont = cv::FONT_HERSHEY_COMPLEX; }
|
||||||
|
else if (!strcmp(font, "HERSEY_TRIPLEX")) { constFont = cv::FONT_HERSHEY_TRIPLEX; }
|
||||||
|
else if (!strcmp(font, "HERSEY_COMPLEX_SMALL")) { constFont = cv::FONT_HERSHEY_COMPLEX_SMALL; }
|
||||||
|
else if (!strcmp(font, "HERSEY_SCRIPT_SIMPLEX")) { constFont = cv::FONT_HERSHEY_SCRIPT_SIMPLEX; }
|
||||||
|
else if (!strcmp(font, "HERSEY_SCRIPT_COMPLEX")) { constFont = cv::FONT_HERSHEY_SCRIPT_COMPLEX; }
|
||||||
|
else if (!strcmp(font, "HERSEY_SCRIPT_SIMPLEX")) { constFont = cv::FONT_HERSHEY_SCRIPT_SIMPLEX; }
|
||||||
|
|
||||||
|
cv::Scalar color(0, 0, 255);
|
||||||
|
|
||||||
|
if(args[4]->IsArray()) {
|
||||||
|
Local<Object> objColor = args[4]->ToObject();
|
||||||
|
color = setColor(objColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
cv::putText(self->mat, text, cv::Point(x, y), constFont, 1, color, 2);
|
||||||
|
|
||||||
|
return scope.Close(Undefined());
|
||||||
|
}
|
||||||
|
|||||||
@ -90,6 +90,8 @@ class Matrix: public node::ObjectWrap {
|
|||||||
JSFUNC(MinMaxLoc)
|
JSFUNC(MinMaxLoc)
|
||||||
|
|
||||||
JSFUNC(PushBack)
|
JSFUNC(PushBack)
|
||||||
|
|
||||||
|
JSFUNC(PutText)
|
||||||
/*
|
/*
|
||||||
static Handle<Value> Val(const Arguments& args);
|
static Handle<Value> Val(const Arguments& args);
|
||||||
static Handle<Value> RowRange(const Arguments& args);
|
static Handle<Value> RowRange(const Arguments& args);
|
||||||
|
|||||||
33
test/unit.js
33
test/unit.js
@ -351,6 +351,39 @@ vows.describe('Smoke Tests OpenCV').addBatch({
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
, "putText": {
|
||||||
|
topic: function() {
|
||||||
|
var cv = require('../lib/opencv')
|
||||||
|
, self = this
|
||||||
|
|
||||||
|
cv.readImage('./examples/coin1.jpg', function(e, im){
|
||||||
|
self.callback(null, im);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
"fonts": function(im) {
|
||||||
|
function rnd() {
|
||||||
|
return Math.round(Math.random() * 255);
|
||||||
|
};
|
||||||
|
|
||||||
|
var y = 0;
|
||||||
|
|
||||||
|
([
|
||||||
|
"HERSEY_SIMPLEX",
|
||||||
|
"HERSEY_PLAIN",
|
||||||
|
"HERSEY_DUPLEX",
|
||||||
|
"HERSEY_COMPLEX",
|
||||||
|
"HERSEY_TRIPLEX",
|
||||||
|
"HERSEY_COMPLEX_SMALL",
|
||||||
|
"HERSEY_SCRIPT_SIMPLEX",
|
||||||
|
"HERSEY_SCRIPT_COMPLEX",
|
||||||
|
"HERSEY_SCRIPT_SIMPLEX"
|
||||||
|
]).forEach(function(font) {
|
||||||
|
im.putText("Some text", 0, y += 20, font, [rnd(), rnd(), rnd()]);
|
||||||
|
});
|
||||||
|
|
||||||
|
im.save("./examples/coin1-with-text.jpg");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}).export(module);
|
}).export(module);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user