在WIN7-64下使用PYTHON获得摄像头图片
2012-06-07 16:51
441 查看
环境是 Python27
需要下载库:
pygame 处理帧
http://www.lfd.uci.edu/~gohlke/pythonlibs/bpchanvi/pygame-1.9.2pre.win-amd64-py2.7.exe
VideoCature取得摄像头图像
http://www.lfd.uci.edu/~gohlke/pythonlibs/bpchanvi/VideoCapture-0.9.5.win-amd64-py2.7.exe
PIL python Image Lib 图像处理,最基础的依赖包
http://www.lfd.uci.edu/~gohlke/pythonlibs/bpchanvi/PIL-1.1.7.win-amd64-py2.7.exe
先来个摄像头截取的代码(从DEMO中抠出来的)
然后是比较复杂的连续从摄像头中取得视频流,把原有的DEMO代码加了注释调整了下顺序
自己是准备处理图像,把截屏出来的那个图片,取得边缘。
原本的想法是从摄像头中取得图像进行分析,分析眼动来替代鼠标的位置。不过取出的视频精度显然很低。看来这个要以来高精度的摄像头,高精度的摄像头带来的问题就是处理的速度降低。
同时,摄像头在本本上,来定位脑袋、眼球、笔记本、摄像头,转换为屏幕上的鼠标轨迹,显然有点困难。不过在家里面做个体感的游戏还凑合。
整体上看,
需要下载库:
pygame 处理帧
http://www.lfd.uci.edu/~gohlke/pythonlibs/bpchanvi/pygame-1.9.2pre.win-amd64-py2.7.exe
VideoCature取得摄像头图像
http://www.lfd.uci.edu/~gohlke/pythonlibs/bpchanvi/VideoCapture-0.9.5.win-amd64-py2.7.exe
PIL python Image Lib 图像处理,最基础的依赖包
http://www.lfd.uci.edu/~gohlke/pythonlibs/bpchanvi/PIL-1.1.7.win-amd64-py2.7.exe
先来个摄像头截取的代码(从DEMO中抠出来的)
import VideoCapture cam = VideoCapture.Device(devnum=0) cam.saveSnapshot('test.jpg', quality=75, timestamp=3, boldfont=1)
然后是比较复杂的连续从摄像头中取得视频流,把原有的DEMO代码加了注释调整了下顺序
#coding=utf-8 from VideoCapture import Device import ImageDraw, sys, pygame, time from pygame.locals import * from PIL import ImageEnhance # 设置窗口、摄像头分辨率 res = (640,480) # 初始化窗口 pygame.init() pygame.display.set_caption('Webcam') pygame.font.init() screen = pygame.display.set_mode((640,480)) font = pygame.font.SysFont("Courier",11) # 取得摄像头设备,设置分辨率 cam = Device() cam.setResolution(res[0],res[1]) # 显示文字信息函数 def disp(phrase,loc): s = font.render(phrase, True, (200,200,200)) sh = font.render(phrase, True, (50,50,50)) screen.blit(sh, (loc[0]+1,loc[1]+1)) screen.blit(s, loc) # 亮度,对比度 brightness = 1.0 contrast = 1.0 # 截图计数器 shots = 0 while 1: camshot = ImageEnhance.Brightness(cam.getImage()).enhance(brightness) camshot = ImageEnhance.Contrast(camshot).enhance(contrast) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() keyinput = pygame.key.get_pressed() # 快捷键处理,调节亮度对比度 if keyinput[K_1]: brightness -= .1 if keyinput[K_2]: brightness += .1 if keyinput[K_3]: contrast -= .1 if keyinput[K_4]: contrast += .1 # 呼出调试 if keyinput[K_q]: cam.displayCapturePinProperties() if keyinput[K_w]: cam.displayCaptureFilterProperties() # 截图保存,shots为计数器 if keyinput[K_s]: filename = str(time.time()) + ".jpg" cam.saveSnapshot(filename, quality=80, timestamp=0) shots += 1 # 从摄像头中取得图像 camshot = pygame.image.frombuffer(camshot.tostring(), res, "RGB") screen.blit(camshot, (0,0)) disp("S:" + str(shots), (10,4)) disp("B:" + str(brightness), (10,16)) disp("C:" + str(contrast), (10,28)) # 填充图像 pygame.display.flip()
自己是准备处理图像,把截屏出来的那个图片,取得边缘。
import Image import ImageFilter img = Image.open('test.jpg') new_img = img.filter(ImageFilter.FIND_EDGES) new_img.save('test2.jpg')
原本的想法是从摄像头中取得图像进行分析,分析眼动来替代鼠标的位置。不过取出的视频精度显然很低。看来这个要以来高精度的摄像头,高精度的摄像头带来的问题就是处理的速度降低。
同时,摄像头在本本上,来定位脑袋、眼球、笔记本、摄像头,转换为屏幕上的鼠标轨迹,显然有点困难。不过在家里面做个体感的游戏还凑合。
整体上看,
相关文章推荐
- win7 64 位 Visual studio 环境下,使用whl依赖包,搭建python3.5 机器学习开发环境
- 使用Gtreamer获得摄像头数据并显示(Webcam streaming using Python--pyGTK, wxPython and Gstreamer)
- 使用Gtreamer获得摄像头数据并显示(Webcam streaming using Python--pyGTK, wxPython and Gstreamer)
- 【网安随笔】使用python脚本解密图片
- Python3 使用PIL将图片切分为九宫格
- 使用OpenCV实现WebCam摄像头保存JPEG图片(改良3版) Ubuntu
- python tornado使用流生成图片
- Python读取图片EXIF信息类库介绍和使用实例
- 上传图片时,使用JS获得图片文件大小(旧浏览器)
- 教你使用python获得字符串的md5值
- win7使用iis并搭建 图片服务器
- 使用Python获得网页中的链接
- 使用Ipython notebook 学习《Python for Data Analysis》 在win7下搭建注意事项
- 使用Python保存网页上的图片或者保存页面为截图
- python2.7代码在win7_64环境下输出中文乱码解决方法
- 使用python利用Image模块检查图片像素是否符合要求
- 使用python来批量抓取网站图片
- Python上传磁盘和网络图片,内存图片,使用requests
- python学习 二 03 爬一个图片网站-获得所有分页网址
- 使用python脚本实现iOS图片资源压缩