python-2.7pepper

Having trouble displaying images on Pepper


In the code below, I've tried to display a photo on Pepper's tablet that was just taken by their camera, but I've been having issues.

import time

from naoqi import ALProxy
from src.common.ip_port import IP, PORT

photoCapture = ALProxy("ALPhotoCapture", IP, PORT)
tablet = ALProxy("ALTabletService", IP, PORT)
tts = ALProxy("ALTextToSpeech", IP, PORT)


def main():
    photoCapture.setResolution(2)
    photoCapture.setPictureFormat("jpg")
    photoCapture.takePictures(1, "/home/nao/lachlan/photo/", "capture")
    print("Image taken")

    # If this doesn't work try these:
    # tablet.showImage("http://198.18.0.1/lachlan/photo/capture.jpg")
    # tablet.showImage("http://{}/lachlan/photo/capture.jpg".format(IP))
    tablet.showImage("/home/nao/lachlan/photo/capture.jpg")
    print("Image displayed")
    print(tablet.robotIp())
    # tts.say("Do you like this photo I took?")

    time.sleep(5)

    tablet.hideImage()


if __name__ == '__main__':
    main()

When the photo is displayed, the idle gif(?) on the tablet disappears and is replaced by a black screen for the 5 seconds before tablet.hideImage() is run. I've tried all of the showImages commented out, and I've also tried preloading the image and also trying with showImageNoCache() (I think I might have done it incorrectly though). I believe it's not an issue with loading the file, because it can play audio files just fine. If anyone has any ideas on how to solve, things to test, or just a problem with my code, that would be great.

Thanks!


Solution

  • http://198.18.0.1/ points to the root web server directory on the robot, which is not /home/nao. You thus have probably two options:

    1. either download the image to some remote location with its own remote URL, or
    2. save in on the robot in an application directory and refer to it via http://198.18.0.1/apps/<app name>/.... This directory is located in /home/nao/.local/share/PackageManager/apps/<app name>/html/ and the directory structure is created when installing the application package (i.e. the html subdirectory should appear in the package).