目的:把iPhone4s当成网络摄像头,通过wifi连接到树莓派上,做为树莓派的摄像头。
1. iPhone4s上安装mini WebCam应用。
很旧的一个app, 没有密码,简单,无广告,免费。
启动WebCam服务, ip地址为192.168.1.222。2. 树莓派上运行代码
代码:
# url-cam.py
from SimpleCV import JpegStreamCamera, Image,Displaydisplay = Display()# 连接iPhone4s网络摄像头cam = JpegStreamCamera('http://192.168.1.222/video.mjpg')while True: # 取网络摄像头图像 img = cam.getImage() # 显示 img.save(display)
运行:
:~$ pyhton url-cam.py错误:
ERROR: 24 Traceback (most recent call last): 25 File "mobile-cam.py", line 7, in26 img = cam.getImage() 27 File "/home/pi/Code/SimpleCV/SimpleCV/Camera.py", line 1193, in getImage 28 return Image(pil.open(StringIO(self.camthread.currentframe)), self) 29 File "/home/pi/Code/SimpleCV/SimpleCV/ImageClass.py", line 1102, in __init __ 30 cv.SetData(self._bitmap, self._pil.tostring()) 31 File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 697, in tostrin g 32 "Please call tobytes() instead.") 33 NotImplementedError: tostring() has been removed. Please call tobytes() instead.
3. 解决
按错误要求修改ImageClass.py文件中1102行修改为1103行内容:
1102 #cv.SetData(self._bitmap, self._pil.tostring())1103 cv.SetData(self._bitmap, self._pil.tobytes()) # changed tobytes() by hyper99
截屏如下: