node-opencv icon indicating copy to clipboard operation
node-opencv copied to clipboard

error in use toBuffer()

Open mariantonia opened this issue 8 years ago • 1 comments

when modifying example mat-put.js

var opencv = require('../lib/opencv');
var mat = new opencv.Matrix(225,225,opencv.Constants.CV_8UC3);   //
//var buf = Buffer(225*225*3).fill(0);  
var buf = mat.toBuffer();
console.log("length-", buf.length);

 for(var i=0;i<buf.length;i++){ 
    buf[i] = (i%2===1)?0:255;
  }
  mat.put(buf);
var window = new opencv.NamedWindow('Mat-Put', 0);
window.show(mat);
window.blockingWaitKey(0, 50);
setTimeout(function(){
  // keep the windows 30sec open
},4000);

Always get different value of buf.length, but if use

var buf = Buffer(2252253).fill(0)

works perfectly. dif

mariantonia avatar Jul 31 '17 14:07 mariantonia

Since I need to modify all pixels of MAT, LENGTH buffer must not be variable. Just NEED multiply two matrices...

mariantonia avatar Aug 01 '17 20:08 mariantonia