-
Notifications
You must be signed in to change notification settings - Fork 858
/
readimage.js
111 lines (71 loc) · 4.29 KB
/
readimage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var cv = require('../lib/opencv');
// read as a buffer for decode operations later
var fs = require('fs');
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());
cv.readImage("./files/mona.png", function(err, im){
console.log('callback readImage("./files/mona.png", fn(){})'+im.width()+'x'+im.height());
});
img = cv.readImage( 100, 100 );
console.log('Synchronous readImage(100, 100) (create mat)'+img.width()+'x'+img.height()+' type '+img.type());
cv.readImage(100, 100, function(err, im){
console.log('callback readImage(100, 100, fn(){}) (create mat)'+im.width()+'x'+im.height());
});
img = cv.readImage(imgdata);
console.log('Synchronous readImage(imgdata:Buffer)'+img.width()+'x'+img.height());
cv.readImage(imgdata, function(err, im){
console.log('callback readImage(imgdata:Buffer, fn(){})'+im.width()+'x'+im.height());
});
// try with flags now
console.log('Now with flags');
img = cv.readImage("./files/mona.png", 0);
console.log('Synchronous readImage("./files/mona.png", 0) (monochrome)'+img.width()+'x'+img.height()+' type '+img.type());
cv.readImage("./files/mona.png", 1, function(err, im){
console.log('callback readImage("./files/mona.png", 1, fn(){}) (colour)'+im.width()+'x'+im.height()+' type '+im.type());
});
img = cv.readImage( 100, 100, cv.Constants.CV_8UC3 );
console.log('Synchronous readImage(100, 100, cv.Constants.CV_8UC3) (create 8 bit 3 channel mat)'+img.width()+'x'+img.height()+' type '+img.type());
cv.readImage(100, 100, cv.Constants.CV_8UC1, function(err, im){
console.log('callback readImage(100, 100, cv.Constants.CV_8UC1, fn(){}) (create mat)'+im.width()+'x'+im.height()+' type '+im.type());
});
img = cv.readImage(imgdata, 0);
console.log('Synchronous readImage(imgdata:Buffer, 0) (monochrome)'+img.width()+'x'+img.height()+' type '+img.type());
cv.readImage(imgdata, 1, function(err, im){
console.log('callback readImage(imgdata:Buffer, 1, fn(){}) (colour)'+im.width()+'x'+im.height()+' type '+im.type());
});
// 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');