Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

row, col, eye

  • Loading branch information...
commit d7873e2b4e62273b00e47222158c3e3c9826dc14 1 parent 406eef4
@peterbraden peterbraden authored
Showing with 73 additions and 5 deletions.
  1. +1 −1  smoke.sh
  2. +49 −1 src/Matrix.cc
  3. +5 −2 src/Matrix.h
  4. +18 −1 test/smoke.js
View
2  smoke.sh
@@ -3,4 +3,4 @@ node-waf configure && node-waf build && echo '-- Compiled OK --
' && node smoketest.js && echo '-- Smoke Done, running tests --
-' && node test/smoke.js -v
+' && npm test
View
50 src/Matrix.cc
@@ -21,6 +21,10 @@ Matrix::Init(Handle<Object> target) {
Local<ObjectTemplate> proto = constructor->PrototypeTemplate();
+ NODE_SET_PROTOTYPE_METHOD(constructor, "row", Row);
+ NODE_SET_PROTOTYPE_METHOD(constructor, "col", Col);
+
+
NODE_SET_PROTOTYPE_METHOD(constructor, "empty", Empty);
NODE_SET_PROTOTYPE_METHOD(constructor, "get", Get);
NODE_SET_PROTOTYPE_METHOD(constructor, "set", Set);
@@ -31,6 +35,9 @@ Matrix::Init(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "ellipse", Ellipse);
NODE_SET_PROTOTYPE_METHOD(constructor, "save", Save);
+ NODE_SET_METHOD(constructor, "Eye", Eye);
+
+
target->Set(String::NewSymbol("Matrix"), m->GetFunction());
};
@@ -58,7 +65,7 @@ Matrix::Matrix(): ObjectWrap() {
}
Matrix::Matrix(int w, int h): ObjectWrap() {
- mat = cv::Mat(w, h, CV_8UC1);
+ mat = cv::Mat(w, h, CV_64FC1);
}
Handle<Value>
@@ -104,6 +111,33 @@ Matrix::Size(const Arguments& args){
return scope.Close(arr);
}
+Handle<Value>
+Matrix::Row(const Arguments& args){
+ SETUP_FUNCTION(Matrix)
+
+ int width = self->mat.size().width;
+ int j = args[0]->IntegerValue();
+ v8::Local<v8::Array> arr = v8::Array::New(width);
+
+ for (int i=0; i<width; i++){
+ arr->Set(i, Number::New(self->mat.at<double>(i, j)));
+ }
+ return scope.Close(arr);
+}
+
+Handle<Value>
+Matrix::Col(const Arguments& args){
+ SETUP_FUNCTION(Matrix)
+
+ int width = self->mat.size().width;
+ int j = args[0]->IntegerValue();
+ v8::Local<v8::Array> arr = v8::Array::New(width);
+
+ for (int i=0; i<width; i++){
+ arr->Set(i, Number::New(self->mat.at<double>(j, i)));
+ }
+ return scope.Close(arr);
+}
Handle<Value>
Matrix::Width(const Arguments& args){
@@ -171,3 +205,17 @@ Matrix::Save(const v8::Arguments& args){
return scope.Close(Number::New(res));
}
+Handle<Value>
+Matrix::Eye(const v8::Arguments& args){
+ HandleScope scope;
+
+ int w = args[0]->Uint32Value();
+ int h = args[1]->Uint32Value();
+
+ Local<Object> im_h = Matrix::constructor->GetFunction()->NewInstance();
+ Matrix *img = ObjectWrap::Unwrap<Matrix>(im_h);
+ cv::Mat mat = cv::Mat::eye(w, h, CV_64FC1);
+
+ img->mat = mat;
+ return scope.Close(im_h);
+}
View
7 src/Matrix.h
@@ -12,12 +12,15 @@ class Matrix: public node::ObjectWrap {
Matrix(int rows, int cols, int typ);
+ JSFUNC(Row)
+ JSFUNC(Col)
+ JSFUNC(Eye) // factory
+
/*
static Handle<Value> Val(const Arguments& args);
- static Handle<Value> Row(const Arguments& args);
- static Handle<Value> Col(const Arguments& args);
+
static Handle<Value> RowRange(const Arguments& args);
static Handle<Value> ColRange(const Arguments& args);
static Handle<Value> Diag(const Arguments& args);
View
19 test/smoke.js
@@ -2,7 +2,12 @@ var vows = require('vows')
, assert = require('assert')
, fs = require('fs');
-
+assertDeepSimilar = function(res, exp){
+ for (var i = 0; i < res.length; i++){
+ // res[i] = Math.round(res[i]/100)*100;
+ }
+ assert.deepEqual(res, exp)
+}
vows.describe('Smoke Tests OpenCV').addBatch({
"Importing": {
@@ -88,6 +93,18 @@ vows.describe('Smoke Tests OpenCV').addBatch({
assert.deepEqual(mat.size(), [6, 7]);
}
+ , 'row' : function(cv){
+ var mat = new cv.Matrix.Eye(4,4)
+ assertDeepSimilar(mat.row(1), [0,1,0,0])
+ assertDeepSimilar(mat.row(2), [0,0,1,0])
+ }
+
+ , 'col' : function(cv){
+ var mat = new cv.Matrix.Eye(4,4);
+ assertDeepSimilar(mat.col(1), [0,1,0,0])
+ assertDeepSimilar(mat.col(2), [0,0,1,0])
+ }
+
, "empty": function(cv){
assert.equal(new cv.Matrix().empty(), true);
}
Please sign in to comment.
Something went wrong with that request. Please try again.