mirror of
https://github.com/peterbraden/node-opencv.git
synced 2025-12-08 19:45:55 +00:00
commit
794e1add4d
6
examples/test.js
Normal file
6
examples/test.js
Normal file
@ -0,0 +1,6 @@
|
||||
var cv = require('../lib/opencv');
|
||||
|
||||
var mat = new cv.Matrix(1, 2, cv.Constants.CV_8U, [1]);
|
||||
var row = mat.pixelRow(0);
|
||||
console.log("mat: " + row[0] + row[1]);
|
||||
|
||||
@ -1893,7 +1893,7 @@ NAN_METHOD(Matrix::ConvertTo) {
|
||||
// param 3 - beta
|
||||
double beta = 0;
|
||||
if (info.Length() >= 4) {
|
||||
DOUBLE_FROM_ARGS(alpha, 3);
|
||||
DOUBLE_FROM_ARGS(beta, 3);
|
||||
}
|
||||
|
||||
self->mat.convertTo(dest->mat, rtype, alpha, beta);
|
||||
@ -2435,11 +2435,13 @@ NAN_METHOD(Matrix::Reshape) {
|
||||
JSTHROW("Invalid number of arguments");
|
||||
}
|
||||
|
||||
cv::Mat res = self->mat.reshape(cn, rows);
|
||||
~self->mat;
|
||||
self->mat = res;
|
||||
Local<Object> img_to_return =
|
||||
Nan::New(Matrix::constructor)->GetFunction()->NewInstance();
|
||||
Matrix *img = Nan::ObjectWrap::Unwrap<Matrix>(img_to_return);
|
||||
|
||||
return;
|
||||
img->mat = self->mat.reshape(cn, rows);
|
||||
|
||||
info.GetReturnValue().Set(img_to_return);
|
||||
}
|
||||
|
||||
NAN_METHOD(Matrix::Release) {
|
||||
|
||||
BIN
test/.unit.js.swp
Normal file
BIN
test/.unit.js.swp
Normal file
Binary file not shown.
40
test/unit.js
40
test/unit.js
@ -53,7 +53,9 @@ test('Point', function(t){
|
||||
test('Matrix constructor', function(assert){
|
||||
assert.ok(cv.Matrix);
|
||||
assert.ok(new cv.Matrix);
|
||||
assert.ok(new cv.Matrix(1,2));
|
||||
assert.ok(new cv.Matrix(1, 2));
|
||||
assert.ok(new cv.Matrix(1, 2, cv.Constants.CV_8U));
|
||||
assert.ok(new cv.Matrix(1, 2, cv.Constants.CV_8U, [1]));
|
||||
assert.end()
|
||||
})
|
||||
|
||||
@ -91,9 +93,43 @@ test('Matrix accessors', function(assert){
|
||||
|
||||
assert.equal(new cv.Matrix().empty(), true);
|
||||
|
||||
mat = new cv.Matrix(1, 2, cv.Constants.CV_8UC3, [1, 2, 3]);
|
||||
assert.deepEqual(mat.pixelRow(0), [1, 2, 3, 1, 2, 3]);
|
||||
|
||||
assert.end()
|
||||
})
|
||||
|
||||
test('Matrix functions', function(assert) {
|
||||
// convertTo
|
||||
var mat = new cv.Matrix(75, 75, cv.Constants.CV_32F, [2.0]);
|
||||
var matNew = new cv.Matrix(75, 75, cv.Constants.CV_8U);
|
||||
mat.convertTo(matNew, cv.Constants.CV_8U, 2, 1);
|
||||
assert.equal(matNew.pixel(0, 0), 5);
|
||||
|
||||
// reshape
|
||||
mat = new cv.Matrix(75, 75, cv.Constants.CV_8UC1);
|
||||
matNew = mat.reshape(1, 1);
|
||||
assert.equal(matNew.height(), 1);
|
||||
assert.equal(matNew.width(), 5625);
|
||||
|
||||
assert.end();
|
||||
})
|
||||
|
||||
test(".norm", function(assert){
|
||||
cv.readImage("./examples/files/coin1.jpg", function(err, im) {
|
||||
cv.readImage("./examples/files/coin2.jpg", function(err, im2){
|
||||
assert.ok(im);
|
||||
assert.ok(im2);
|
||||
|
||||
var errorL2 = im.norm(im2, cv.Constants.NORM_L2);
|
||||
assert.equal(errorL2, 7295.591339980605);
|
||||
|
||||
errorL2 = im.norm(im, cv.Constants.NORM_L2);
|
||||
assert.equal(errorL2, 0);
|
||||
assert.end();
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
test("Matrix toBuffer", function(assert){
|
||||
var buf = fs.readFileSync('./examples/files/mona.png')
|
||||
@ -105,8 +141,6 @@ test("Matrix toBuffer", function(assert){
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
|
||||
test("Matrix toBuffer Async", function(assert){
|
||||
var buf = fs.readFileSync('./examples/files/mona.png')
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user