0

我试图将捕获的640x480 RGB图像与NAO的前置相机保存到我的计算机。我使用Python和PIL来做到这一点。不幸的是,无论Image.save()方法的参数使用什么图像类型或路径,该图像都不会保存在我的计算机上。尽管用PIL创建的图像包含有效的RGB信息。这里是我的代码示例从choregraphe:NAO无法将捕获的图像保存到本地计算机

import Image 

def onInput_onStart(self): 
    cam_input = ALProxy("ALVideoDevice") 
    nameId = cam_input.subscribeCamera("Test_Cam", 1, 2, 13, 20) 

    image = cam_input.getImageRemote(nameId) #captures an image 
    w = image[0] #get the image width 
    h = image[1] #get the image height 
    pixel_array = image[6] #contains the image data 

    result = Image.fromstring("RGB", (w, h), pixel_array) 
    #the following line doesnt work 
    result.save("C:\Users\Claudia\Desktop\NAO\Bilder\test.png", "PNG") 

    cam_input.releaseImage(nameId) 
    cam_input.unsubscribe(nameId) 
    pass 

非常感谢你的帮助提前! - 一个沮丧的学生

+0

在choregraphe我的代码是正确缩进 - 我只是搞砸时张贴在这里。 –

回答

0

为了让您的代码正确运行,它需要正确缩进。您的代码应如下所示:

import Image 

def onInput_onStart(self): 
    cam_input = ALProxy("ALVideoDevice") 
    nameId = cam_input.subscribeCamera("Test_Cam", 1, 2, 13, 20) 

    image = cam_input.getImageRemote(nameId) #captures an image 
    w = image[0] #get the image width 
    h = image[1] #get the image height 
    pixel_array = image[6] #contains the image data 

    ... 

确保缩进def onInput_onStart(self):方法中的所有内容。

+0

谢谢你的回应!对不起,我粘贴的代码没有在这里缩进 - 这是我的第一篇文章,我有点搞砸了。但不幸的是,这不是它不起作用的原因,它正确地缩进choregraphe。 –

1

在评论中,你说代码是从choregraphe粘贴的,所以我猜你使用choregraphe启动它。 如果是这样,那么代码被注入你的机器人,然后开始。

因此,您的图像保存到NAO硬盘驱动器,我猜你的机器人没有名为“C:\ Users \ Claudia \ Desktop \ NAO \ Bilder \ test.png”的文件夹。

因此,将路径改为“/home/nao/test.png”,启动代码,然后使用putty或使用winscp浏览文件夹(因为它看起来像使用Windows)登录到NAO。

你应该看到你的图像文件。

+0

要查看您的文件,此视频的结尾将向您显示腻子部分:https://www.youtube.com/watch?v=Uz2LYU-9j34 –

相关问题