朋友从国外带来个3d的摄像头:
http://www.amazon.com/electronics/dp/B001NXDGFY
于是尝试着raspberry pi下利用python控制3d摄像头
主要利用opencv和PIL(Python Imaging Library)两个包
运行结果如下:
1.opencv的安装:- sudo apt-get install python-opencv
复制代码 2.PIL的安装:
从http://www.pythonware.com/products/pil/下载
Python Imaging Library 1.1.7 Source Kit (all platforms) (November 15, 2009)
按照Read文档安装
3.Camera.py- import cv2.cv as cv
- from PIL import Image
- import time
- cv.NamedWindow("camera",1)
- cap0 = cv.CaptureFromCAM(1)
- cap1 = cv.CaptureFromCAM(0)
- while True:
- frame0 = cv.QueryFrame(cap0)
- frame1 = cv.QueryFrame(cap1)
- cv.SaveImage('frame0.bmp',frame0)
- cv.SaveImage('frame1.bmp',frame1)
- im0 = Image.open('frame0.bmp')
- im1 = Image.open('frame1.bmp')
- box = (0,0,800,600)
- region = im0.crop(box)
- im0.paste(region,box)
- region = im1.crop(box)
- im1.paste(region,box)
- r0,g0,b0 = im0.split()
- r1,g1,b1 = im1.split()
- im = Image.merge('RGB',(r0,g1,b1))
- im.save('frame.bmp')
- frame = cv.LoadImage('frame.bmp')
- cv.ShowImage('camera',frame)
- if cv.WaitKey(30) == 27:
- break
- cv.DestroyWindow("camera")
复制代码 cemara.py下载地址:
camera.py
(853 Bytes, 下载次数: 2)
|