From 862cb7f77757a8bed17e80881282b01f7fa308cd Mon Sep 17 00:00:00 2001 From: Simon Hailes Date: Sat, 4 Nov 2017 15:01:26 +0000 Subject: [PATCH] Update examples/readimage.js for readImageAsync. --- examples/readimage.js | 55 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/examples/readimage.js b/examples/readimage.js index 6017e1e..d0d49b9 100644 --- a/examples/readimage.js +++ b/examples/readimage.js @@ -7,7 +7,6 @@ var imgdata = fs.readFileSync("./files/mona.png"); - var img = cv.readImage("./files/mona.png"); console.log('Synchronous readImage("./files/mona.png")'+img.width()+'x'+img.height()); @@ -56,3 +55,57 @@ cv.readImage(imgdata, 1, function(err, im){ + + +// try with readImageAsync +console.log('Now with readImageAsync'); + +img = cv.readImageAsync("./files/mona.png"); +console.log('Synchronous readImageAsync("./files/mona.png")'+img.width()+'x'+img.height()); + +cv.readImageAsync("./files/mona.png", function(err, im){ + console.log('Asynchronous callback readImageAsync("./files/mona.png", fn(){})'+im.width()+'x'+im.height()); +}); + +img = cv.readImageAsync( 100, 100 ); +console.log('Synchronous readImageAsync(100, 100) (create mat)'+img.width()+'x'+img.height()+' type '+img.type()); + +cv.readImageAsync(100, 100, function(err, im){ + console.log('!!Synchronous!! callback readImageAsync(100, 100, fn(){}) (create mat)'+im.width()+'x'+im.height()); +}); + +img = cv.readImageAsync(imgdata); +console.log('Synchronous readImageAsync(imgdata:Buffer)'+img.width()+'x'+img.height()); + +cv.readImageAsync(imgdata, function(err, im){ + console.log('Asynchronous callback readImageAsync(imgdata:Buffer, fn(){})'+im.width()+'x'+im.height()); +}); + + + +// try with flags now +console.log('Now Async with flags'); + +img = cv.readImageAsync("./files/mona.png", 0); +console.log('Synchronous readImageAsync("./files/mona.png", 0) (monochrome)'+img.width()+'x'+img.height()+' type '+img.type()); + +cv.readImageAsync("./files/mona.png", 1, function(err, im){ + console.log('Asynchronous callback readImageAsync("./files/mona.png", 1, fn(){}) (colour)'+im.width()+'x'+im.height()+' type '+im.type()); +}); + +img = cv.readImageAsync( 100, 100, cv.Constants.CV_8UC3 ); +console.log('Synchronous readImageAsync(100, 100, cv.Constants.CV_8UC3) (create 8 bit 3 channel mat)'+img.width()+'x'+img.height()+' type '+img.type()); + +cv.readImageAsync(100, 100, cv.Constants.CV_8UC1, function(err, im){ + console.log('!!Synchronous!! callback readImageAsync(100, 100, cv.Constants.CV_8UC1, fn(){}) (create mat)'+im.width()+'x'+im.height()+' type '+im.type()); +}); + +img = cv.readImageAsync(imgdata, 0); +console.log('Synchronous readImageAsync(imgdata:Buffer, 0) (monochrome)'+img.width()+'x'+img.height()+' type '+img.type()); + +cv.readImageAsync(imgdata, 1, function(err, im){ + console.log('Asynchronous callback readImageAsync(imgdata:Buffer, 1, fn(){}) (colour)'+im.width()+'x'+im.height()+' type '+im.type()); +}); + +console.log('\nTruely Async callbacks should be after this line\n'); +