Sample code: Identify objects in an image with the Watson Visual Recognition service
Interactive code: When you see Run at the top of a code sample, you can run the code, check the results, make changes, and run it again. When you see Deploy, you can deploy the code into the developerWorks IBM Cloud account. To deploy the code, please sign in.
About this code
This code shows you how to use the node.js API for the Watson Visual Recognition service. Given an image, Watson attempts to identify objects in that image.
The code has two basic sections:
main()method. This is the entry point to the code. It creates the
VisualRecognitionV3object and then invokes the
- A set of default parameters and the code that runs this module if it
is invoked by itself (as opposed to being invoked by a
require()statement). See the Node.js documentation for more information on the implications of the
require.main === modulestatement.
Sign in to run, change, and deploy this code.
This code takes a URL of an image file as input and looks for objects in
that image. The call to the Watson Visual Recognition service is wrapped
Promise to handle the asynchronous nature of
the service. See the overview of the Visual Recognition service or the GitHub
repo for the Watson node.js API for more information.
To see what else Watson can identify, try these other values for
- A cat: https://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Cat_November_2010-1a.jpg/449px-Cat_November_2010-1a.jpg
- A school bus: https://upload.wikimedia.org/wikipedia/commons/f/f3/Laidlaw_school_bus.jpg
- A pizza: https://upload.wikimedia.org/wikipedia/commons/thumb/d/d1/Pepperoni_pizza.jpg/800px-Pepperoni_pizza.jpg
Using this code once deployed
To use this code once you've deployed it, you must create an instance of the Watson Visual Recognition service:
To invoke the code, pass a JSON structure that matches the
defaultParameters object as shown above with the following
urlfields must be filled in with the credentials for your Visual Recognition service instance.
use_unauthenticatedfield must be
For more information, see the developerWorks tutorial Invoking actions on the IBM Cloud Functions platform.
- An overview of the Watson Visual Recognition service
- Create a free IBM Cloud account
- Use transfer learning to create your own image classifier with a Jupyter Notebook
- Node.js journeys on developer.ibm.com/code