-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodecv-server-sample.js
More file actions
126 lines (110 loc) · 3.16 KB
/
Copy pathnodecv-server-sample.js
File metadata and controls
126 lines (110 loc) · 3.16 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
const fs = require('fs');
const path = require('path');
const wd = require('macaca-wd');
const request = require('request');
const remoteHost = 'http://localhost:9900';
const image1Path = path.join(__dirname, 'fixture', 'logo.png');
const image2Path = path.join(__dirname, 'fixture', 'T-Shirt.jpg');
const formData = {
custom_file1: {
value: fs.createReadStream(image1Path),
options: {
filename: 'logo.png',
contentType: 'image/png'
}
},
custom_file2: {
value: fs.createReadStream(image2Path),
options: {
filename: 'T-Shirt.jpg',
contentType: 'image/jpeg'
}
}
};
request.post({
url: `${remoteHost}/opencv/dissimilarity`,
formData: formData
}, function(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Server responded with:', body);
try {
const data = JSON.parse(body);
console.log(`Dissimilarity is: ${data.dissimilarity}`);
} catch (e) {
}
});
/////////////////////////////////////////////////////////////////
const image1Path = path.join(__dirname, 'fixture', 'T-Shirt.jpg');
const image2Path = path.join(__dirname, 'fixture', 'T-Shirt-logo.jpg');
const formData = {
custom_file1: {
value: fs.createReadStream(image1Path),
options: {
filename: 'T-Shirt-logo.jpg',
contentType: 'image/jpeg'
}
},
custom_file2: {
value: fs.createReadStream(image2Path),
options: {
filename: 'T-Shirt.jpg',
contentType: 'image/jpeg'
}
}
};
request.post({
url: `${remoteHost}/opencv/matchtemplate`,
formData: formData
}, function(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Server responded with:', body);
try {
const data = JSON.parse(body);
console.log(`match[x:${data.match[1]}, y:${data.match[2]}, width:${data.match[3]}, height:${data.match[4]}]`);
} catch (e) {
}
});
//////////////////////////////////////////////////////////////////////
wd.addPromiseChainMethod('nodecv_matchtemplate', (image1Path, image2Path) => {
return new Promise((resolve, reject) => {
const formData = {
custom_file1: {
value: fs.createReadStream(image1Path),
options: {
filename: 'T-Shirt-logo.jpg',
contentType: 'image/jpeg'
}
},
custom_file2: {
value: fs.createReadStream(image2Path),
options: {
filename: 'T-Shirt.jpg',
contentType: 'image/jpeg'
}
}
};
request.post({
url: `${remoteHost}/opencv/matchtemplate`,
formData: formData
}, function(err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Server responded with:', body);
try {
const data = JSON.parse(body);
console.log(`match[x:${data.match[1]}, y:${data.match[2]}, width:${data.match[3]}, height:${data.match[4]}]`);
resolve();
} catch (e) {
}
});
});
});
const image1Path = path.join(__dirname, 'fixture', 'T-Shirt.jpg');
const image2Path = path.join(__dirname, 'fixture', 'T-Shirt-logo.jpg');
driver.nodecv_matchtemplate(image1Path, image2Path);