使用Bluemix对​​图像进行分类

经过深入研究,我决定使用Bluemix来分类和识别图像。

我有一个关于如何开始使用node.js运行时编程的初学者问题。

我试图按照这个教程。 但是,这只是代码片段。 您如何运行它们并在Bluemix环境中查看它们?

我的进展:
– 我在Bluemix中启动了node.js starter应用程序。
– 我添加了下面的代码,app.js看起来像这样:

/*eslint-env node*/ //-------------------------------------------------------------------------- // node.js starter application for Bluemix //-------------------------------------------------------------------------- // This application uses express as its web server // for more info, see: http://expressjs.com var express = require('express'); // cfenv provides access to your Cloud Foundry environment // for more info, see: https://www.npmjs.com/package/cfenv var cfenv = require('cfenv'); // create a new express server var app = express(); // serve the files out of ./public as our main files app.use(express.static(__dirname + '/public')); // get the app environment from Cloud Foundry var appEnv = cfenv.getAppEnv(); // start server on the specified port and binding host app.listen(appEnv.port, '0.0.0.0', function() { // print a message when the server starts listening console.log("server starting on " + appEnv.url); }); var watson = require('watson-developer-cloud'); var fs = require('fs'); /*var visual_recognition = watson.visual_recognition({ username: '<username>', password: '<password>', version: 'v2-beta', version_date: '2015-12-02' });*/ var visualRecognition = watson.visual_recognition({ version: 'v3', api_key: process.env.API_KEY || 'my api key', version_date: '2015-05-19' }); var params = { images_file: fs.createReadStream('./resources/car.png') }; visualRecognition.classify(params, function(err, res) { if (err) console.log(err); else console.log(JSON.stringify(res, null, 2)); }); 

我正尝试在Bluemix环境(实时编辑模式)中运行代码,而不是在本地运行。 当我点击运行代码,部署停止,我什至不能find哪一行代码是这样做的。 当我访问网页时,出现以下错误:

404未find:请求的路由('myvisualapp.mybluemix.net')不存在。

我不明白什么是错的,以及如何debugging代码。

作者等级:初学者

  1. 您需要“快速”(或至less拦截)客户端请求。 现在,请求没有处理程序。 为此目的使用app.get()调用
  2. 您的watson服务呼叫对于用户请求现在是无限的。 您需要通过用户请求汇集它。

例如:

 app.get('/', function(req, res) { // invoke watson services // get the result. // write back the result through the response object, res } 

您可以在https://github.com/watson-developer-cloud/visual-recognition-nodejs查看演示代码,并获得一个开始的好地方&#x3002;

另外,从命令行可以看到应用程序的日志部署到bluemix使用

$ cf logs YOURAPPNAME --recent

其中YOURAPPNAME是您推送到bluemix的应用程序的名称。 你可以使用这个名字

$ cf apps

如果你忘记了你使用的名字(这一直发生在我身上)。