Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Follow the This tutorial will show you how to display an image from the Nao camera on your local computer.

Follow Getting started with a robot. Then, in a new python file (or use https://bitbucket.org/socialroboticshub/framework/src/master/sic_framework/tests/You should now have the following set up:

  1. Redis is running on your laptop and you have SIC installed locally

  2. SIC is running on the Nao

Approach

First, let’s create a new file called demo_nao_camera.py) copy the following code.

We first import some libraries and the CompressedImageMessage and Nao object.

Code Block
languagepy
import queue
import cv2

from sic_framework.core.message_python2 import CompressedImageMessage
from sic_framework.devices.common_naoqi.naoqi_camera import TopNaoCamera


 import Nao

Then, we make a queue and callback function to put the received images in this queue object.

Code Block
languagepy
imgs = queue.Queue()
def on_image(image_message: CompressedImageMessage):
    # we could cv2.imshow here, but that does not work on Mac OSX
    imgs.put(image_message.image)


camera

We then connect with the Nao robot and register the callback function to its top_camera sensor.

Code Block
languagepy
nao = TopNaoCameraNao(ip="192.168.0.210")
nao.top_camera.register_callback(on_image)

Now, the queue will be filled every time there is a new image available from the Nao’s top camera. So, we can write a while loop to show these images as soon as they arrive.

Code Block
languagepy
while True:
    img = imgs.get()
    cv2.imshow('', img)
    cv2.waitKey(1)

Simply run the file to show the robot’s camera output!

python demo_camera_nao.py That’s it! If you now run demo_nao_camera.py, you will receive images from the Nao, put them in a queue, and continuously show the images from this queue. The full code can be found here: https://bitbucket.org/socialroboticshub/framework/src/master/sic_framework/tests/demo_nao_camera.py.

Here is the schematic overview of how this program. The camera sends a “stream” of output messages that are received by your computer program.

...