nao机器人拍照,并且展示 Visualize an image using PIL Get one image from NAO, then display it using PIL. Python实现:
import sys
import time
import PIL.Image as Image
from naoqi import ALProxy
def showNaoImage(IP, PORT):
"""
First get an image from Nao, then show it on the screen with PIL.
"""
camProxy = ALProxy("ALVideoDevice", IP, PORT)
resolution = 2
colorSpace = 11
videoClient = camProxy.subscribe("python_client", resolution, colorSpace, 5)
t0 = time.time()
naoImage = camProxy.getImageRemote(videoClient)
t1 = time.time()
print "acquisition delay ", t1 - t0
camProxy.unsubscribe(videoClient)
imageWidth = naoImage[0]
imageHeight = naoImage[1]
array = naoImage[6]
im = Image.frombytes("RGB", (imageWidth, imageHeight), array)
im.save("camImage.png", "PNG")
im.show()
if __name__ == '__main__':
IP = "169.254.165.22"
PORT = 9559
if len(sys.argv) > 1:
IP = sys.argv[1]
naoImage = showNaoImage(IP, PORT)
|