Skip to content

Commit bb00fcd

Browse files
authored
Merge pull request #302 from chughts/vrconfig
Mode Setting for Visual Recognition
2 parents 994d5b5 + 4830a65 commit bb00fcd

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
### New in version 0.5.10
11+
- Allowed detect_mode for Visual Recognition node to be set in msg.params
12+
1013
### New in version 0.5.9
1114
- Text to Speech speech on msg.payload option.
1215
- Speech to Text transcription on msg.payload option

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.5.9",
3+
"version": "0.5.10",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",

services/visual_recognition/v3.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
<p>This feature should be provided in input : </p>
9191
<ul>
9292
<li><code>msg.payload</code> : the URL or the Node.js Buffer of an image. Redirects are followed, so you can use shortened URLs. (Required)</li>
93+
<li><code>msg.params["detect_mode"]</code> : A setting of "classify", "faces" or "text" indicating the visual recognition feature required. "Default" is "classify" (string) (Optional)</li>
9394
<li><code>msg.params["classifier_ids"]</code> : A comma-separated list of the classifier IDs used to classify the images. "Default" is the classifier_id of the built-in classifier. (string) (Optional)</li>
9495
<li><code>msg.params["owners"]</code> : A comma-separated list with the value(s) "IBM" and/or "me" to specify which classifiers to run. (string) (Optional)</li>
9596
<li><code>msg.params["threshold"]</code> : A floating value (in string format) that specifies the minimum score a class must have to be displayed in the response (Optional)</li>
@@ -176,7 +177,7 @@
176177
// which is confusing our users
177178
var currfeature = $('#node-input-image-feature').val();
178179
if (!currfeature) {
179-
$("#node-input-image-feature option[value='classifyImage']").prop('selected', true);
180+
$("#node-input-image-feature option[value='classifyImage']").prop('selected', true);
180181
}
181182

182183
// update list of ruleset for the selected service when the service changes

services/visual_recognition/v3.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,35 @@ module.exports = function(RED) {
7272
}
7373
}
7474

75+
// "classify", "faces" or "text"
76+
// <option value="detectFaces">Detect Faces</option>
77+
// <option value="recognizeText">Recognize Text</option>
78+
// <option selected="selected" value="classifyImage">Classify an image</option>
79+
80+
81+
function verifyFeatureMode(node, msg, config) {
82+
const theOptions = {
83+
'classify' : 'classifyImage',
84+
'faces' : 'detectFaces',
85+
'text' : 'recognizeText'
86+
};
87+
88+
var f = config['image-feature'];
89+
90+
if (msg.params && msg.params.detect_mode) {
91+
if (msg.params.detect_mode in theOptions) {
92+
f = theOptions[msg.params.detect_mode];
93+
} else {
94+
node.error('Invalid parameter setting for detect_mode, using configuration value');
95+
}
96+
}
97+
if (!f) {
98+
node.error('No configuration value for detect mode found, defaulting to classify');
99+
f = theOptions['classify'];
100+
}
101+
return Promise.resolve(f);
102+
}
103+
75104
function verifyInputs(feature, msg) {
76105
switch (feature) {
77106
case 'classifyImage':
@@ -477,7 +506,8 @@ module.exports = function(RED) {
477506
function WatsonVisualRecognitionV3Node(config) {
478507
var node = this,
479508
b = false,
480-
feature = config['image-feature'];
509+
feature = '';
510+
481511
RED.nodes.createNode(this, config);
482512
node.config = config;
483513

@@ -488,6 +518,10 @@ module.exports = function(RED) {
488518

489519
verifyPayload(msg)
490520
.then(function() {
521+
return verifyFeatureMode(node, msg, config);
522+
})
523+
.then(function(f) {
524+
feature = f;
491525
return checkForStream(msg);
492526
})
493527
.then(function() {

0 commit comments

Comments
 (0)