Merge branch 'get_CV_32F'

This commit is contained in:
Pierre Colle 2016-11-08 14:44:17 +01:00
commit 0cb3f01196
3 changed files with 37 additions and 2 deletions

30
examples/mat-get.js Normal file
View File

@ -0,0 +1,30 @@
var cv = require('../lib/opencv');
cv.readImage("./files/mona.png", function(err, orig) {
if (err) throw err;
var chan1 = orig.split()[0];
var floatMatrix = new cv.Matrix();
var chan1Back = new cv.Matrix();
chan1.convertTo(floatMatrix, cv.Constants.CV_32F);
floatMatrix.convertTo(chan1Back, cv.Constants.CV_8U);
var rowId = 0;
var colId = 0;
console.log(orig.get(rowId,colId), orig.pixel(rowId, colId));
// ACTUAL : => -8.425768939900947e-273 [25, 51, 57]
// EXPECTED : => [25, 51, 57] (this is R : 57 G : 51 and B : 25)
console.log(chan1.get(rowId,colId), chan1.pixel(rowId, colId));
// ACTUAL => 1.76244473776441e-105 36
// EXPECTED => 154
console.log(floatMatrix.get(rowId,colId), floatMatrix.pixel(rowId, colId));
// ACTUAL => 481036405168
// EXPECTED => 154.0
console.log(chan1Back.get(rowId,colId), chan1Back.pixel(rowId, colId));
// ACTUAL => 1.76244473776441e-105
// EXPECTED => 154
});

View File

@ -208,6 +208,9 @@ double Matrix::DblGet(cv::Mat mat, int i, int j) {
case CV_64FC1:
val = mat.at<double>(i, j);
break;
case CV_32FC1:
val = mat.at<float>(i, j);
break;
default:
val = mat.at<double>(i, j);
break;

View File

@ -103,8 +103,10 @@ 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);
var alpha = 2;
var beta = 1;
mat.convertTo(matNew, cv.Constants.CV_8U, alpha, beta);
assert.equal(matNew.pixel(0, 0), mat.get(0, 0)*alpha + beta);
// reshape
mat = new cv.Matrix(75, 75, cv.Constants.CV_8UC1);