A Robot Befriends Classic Monsters Using Watson APIs — Part 3

Integrating Watson Visual Recognition With RaspberryPi Camera

Josh Zheng
IBM watsonx Assistant
2 min readMay 22, 2017

--

In Part 1 and Part 2 of this tutorial series, we used Watson Visual Recognition’s custom classifiers to recognize a few classic monsters. Now it’s time to integrate the code with a RaspberryPi camera.

The code to this part of the tutorial can be found here.

Step-By-Step Tutorial

Step 0. What You Need

  1. NodeJS (I’m using 7.2.0)
  2. Raspberry Pi. I’m using the latest Raspberry Pi 3.
  3. Raspberry Pi Camera Module v2
  4. Dracula, Frakenstein, the Wolfman, and the Mummy plush set

Step 1. Initializing the Camera

We’re using node-raspicam to interface with the camera. Here’s the code to initialize it.

Most of these parameters are self explanatory, notice the timeout parameter is set to zero because we want to take the picture as soon as the camera turns on.

Step 2. Using the Camera

Since a photo is taken automatically the moment the camera turns on, the only event we really care about is the “read” event, which happens when a photo is saved to file.

Once the photo is saved, we remember the filename of the image and send the it to the custom classifier we created in part 1 and part 2 for classification (line 7).

Step 3. Character Recognition

Here’s the code that classifies our image against the monsters custom classifier.

Important Note: Notice the specification of the classifier_id at line 4. For this to work, you need to grab the classifier ID you got from part 1 or part 2 and put it into the config file.

The actual classification is done at line 8. The rest is just code to parse the resulting JSON.

Important Note: If you’re here to complete the whole TJBot + Classic Monsters project, make sure to do this step. I know it’s tempting to jump ahead but make sure the crux of your code works before moving on. It’ll be harder to debug and modify your code once it’s part of the larger project.

Onward to TJBot!

Alright, if you followed all the instruction correctly, you should be able to put a monster in front of the Raspberry Pi camera and see the appropriate greeting in your console.

Now it’s time to grab a TJBot and put it all together. To Part 4!

As always, if you have any questions, feel free to reach out at joshzheng@us.ibm.com, connect with me on LinkedIn, or follow me here on Medium.

--

--

Josh Zheng
IBM watsonx Assistant

Head of DevRel @ Great Expectations. Previously DevRe Lead at Shopify and IBM Watson. Hates writing.