Skip to content

Commit

Permalink
Merge pull request #302 from chughts/vrconfig
Browse files Browse the repository at this point in the history
Mode Setting for Visual Recognition
  • Loading branch information
chughts authored Jun 20, 2017
2 parents 994d5b5 + 4830a65 commit bb00fcd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix

<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>

### New in version 0.5.10
- Allowed detect_mode for Visual Recognition node to be set in msg.params

### New in version 0.5.9
- Text to Speech speech on msg.payload option.
- Speech to Text transcription on msg.payload option
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-watson",
"version": "0.5.9",
"version": "0.5.10",
"description": "A collection of Node-RED nodes for IBM Watson services",
"dependencies": {
"alchemy-api": "^1.3.0",
Expand Down
3 changes: 2 additions & 1 deletion services/visual_recognition/v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<p>This feature should be provided in input : </p>
<ul>
<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>
<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>
<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>
<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>
<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>
Expand Down Expand Up @@ -176,7 +177,7 @@
// which is confusing our users
var currfeature = $('#node-input-image-feature').val();
if (!currfeature) {
$("#node-input-image-feature option[value='classifyImage']").prop('selected', true);
$("#node-input-image-feature option[value='classifyImage']").prop('selected', true);
}

// update list of ruleset for the selected service when the service changes
Expand Down
36 changes: 35 additions & 1 deletion services/visual_recognition/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,35 @@ module.exports = function(RED) {
}
}

// "classify", "faces" or "text"
// <option value="detectFaces">Detect Faces</option>
// <option value="recognizeText">Recognize Text</option>
// <option selected="selected" value="classifyImage">Classify an image</option>


function verifyFeatureMode(node, msg, config) {
const theOptions = {
'classify' : 'classifyImage',
'faces' : 'detectFaces',
'text' : 'recognizeText'
};

var f = config['image-feature'];

if (msg.params && msg.params.detect_mode) {
if (msg.params.detect_mode in theOptions) {
f = theOptions[msg.params.detect_mode];
} else {
node.error('Invalid parameter setting for detect_mode, using configuration value');
}
}
if (!f) {
node.error('No configuration value for detect mode found, defaulting to classify');
f = theOptions['classify'];
}
return Promise.resolve(f);
}

function verifyInputs(feature, msg) {
switch (feature) {
case 'classifyImage':
Expand Down Expand Up @@ -477,7 +506,8 @@ module.exports = function(RED) {
function WatsonVisualRecognitionV3Node(config) {
var node = this,
b = false,
feature = config['image-feature'];
feature = '';

RED.nodes.createNode(this, config);
node.config = config;

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

verifyPayload(msg)
.then(function() {
return verifyFeatureMode(node, msg, config);
})
.then(function(f) {
feature = f;
return checkForStream(msg);
})
.then(function() {
Expand Down

0 comments on commit bb00fcd

Please sign in to comment.