【问题标题】:Pepper: display temporal imagePepper:显示时间图像
【发布时间】:2017-08-24 08:15:50
【问题描述】:

在我的 Choregraphe 项目中,机器人调用 API 来检索将在其平板电脑中显示的图像(以 base64 编码)。

因此机器人调用 API,获取数据的 JSON 并将其保存在文件中。之后,它打开文件,读取图像并对其进行解码。解码后的图像被保存为一个时间文件,最后,它使用tabletService.showImage(url)调用这个时间图像在平板电脑上显示

我遇到的问题是机器人没有显示任何图像,也没有抛出任何错误或异常。不知道怎么解决。

def onInput_onStart(self):
    # We create TabletService here in order to avoid
    # problems with connections and disconnections of the tablet during the life of the application
    import json
    import base64
    import tempfile

    tabletService = self._getTabletService()
    if tabletService:
        try:
            senaleticas = ''
            with open('senaleticas.json', 'r') as fr:
                strSenaleticas = fr.read()

            senaleticas = json.loads(strSenaleticas)

            image64 = senaleticas[0]['_mapa']
            image = base64.b64decode(image64)

            f = tempfile.NamedTemporaryFile()
            f.write(image)

            url = self._getAbsoluteUrl(f.name)

            self.logger.info("-> " + url)

            tabletService.showImage(url)
        except Exception as err:
            self.logger.error("Error during ShowImage : %s " % err)
            self.onStopped()
    else:
        self.logger.warning("No ALTabletService, can't display the image.")
        self.onStopped()

日志显示 var log 的值为 http://198.18.0.1/apps/.lastUploadedChoregrapheBehavior/tmp/tmpEhJeOS

注意:如果有其他显示图像的方式,我对此很感兴趣。

【问题讨论】:

    标签: python-2.7 pepper choregraphe


    【解决方案1】:

    尝试使用正确的图像文件扩展名,例如 png:

    f = tempfile.NamedTemporaryFile(suffix='.png')
    

    【讨论】:

    • 那行不通。目前我已经实现了一个临时解决方案,它通过 JS 在 HTML 文件中显示图像。使用图像框,平板电脑不会执行任何看起来加载图像的操作
    • 你写的是“临时的”,你的意思是“临时的”吗?
    • 我想知道“显示图像”框是否能够正常工作。请尝试以下操作:创建一个名为“html”的文件夹并将其放在项目根文件夹中(与 .pml 文件处于同一级别)。然后在“html”文件夹中插入一个图像文件。然后使用“显示图像”框。在框参数中,将字符串“ImageURL”设置为图像名称。例如'cat.jpg'。不要包含路径名。该框被硬编码为使用“html”文件夹。
    • 将图像放在 html 文件夹中还是可以在项目内的任何文件夹中?
    • 它们必须在 html 文件夹中。 nginx 服务器就是这样配置的。
    猜你喜欢
    • 2015-07-04
    • 2023-03-22
    • 2018-01-18
    • 2015-10-30
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多