python动作捕捉_树莓派动作捕捉抓拍存储图像脚本
本文实例为大家分享了树莓派动作捕捉抓拍存储图像的具体代码,供大家参考,具体内容如下
#!/usr/bin/python
# original script by brainflakes, improved by pageauc, peewee2 and kesthal
# www.raspberrypi.org/phpbb3/viewtopic.php?f=43&t=45235
# you need to install pil to run this script
# type "sudo apt-get install python-imaging-tk" in an terminal window to do this
import stringio
import subprocess
import os
import time
from datetime import datetime
from pil import image
# motion detection settings:
# threshold - how much a pixel has to change by to be marked as "changed"
# sensitivity - how many changed pixels before capturing an image, needs to be higher if noisy view
# forcecapture - whether to force an image to be captured every forcecapturetime seconds, values true or false
# filepath - location of folder to save photos
# filenameprefix - string that prefixes the file name for easier identification of files.
# diskspacetoreserve - delete oldest images to avoid filling disk. how much byte to keep free on disk.
# camerasettings - "" = no extra settings; "-hf" = set horizontal flip of image; "-vf" = set vertical flip; "-hf -vf" = both horizontal and vertical flip
threshold = 10
sensitivity = 20
forcecapture = true
forcecapturetime = 60 * 60 # once an hour
filepath = "/home/pi/picam"
filenameprefix = "capture"
diskspacetoreserve = 40 * 1024 * 1024 # keep 40 mb free on disk
camerasettings = ""
# settings of the photos to save
savewidth = 1296
saveheight = 972
savequality = 15 # set jpeg quality (0 to 100)
# test-image settings
testwidth = 100
testheight = 75
# this is the default setting, if the whole image should be scanned for changed pixel
testareacount = 1
testborders = [ [[1,testwidth],[1,testheight]] ] # [ [[start pixel on left side,end pixel on right side],[start pixel on top side,stop pixel on bottom side]] ]
# testborders are not zero-based, the first pixel is 1 and the last pixel is testwith or testheight
# with "testborders", you can define areas, where the script should scan for changed pixel
# for example, if your picture looks like this:
#
# ....xxxx
# ........
# ........
#
# "." is a street or a house, "x" are trees which move arround like crazy when the wind is blowing
# because of the wind in the trees, there will be taken photos all the time. to prevent this, your setting might look like this:
# testareacount = 2
# testborders = [ [[1,50],[1,75]], [[51,100],[26,75]] ] # area y=1 to 25 not scanned in x=51 to 100
# even more complex example
# testareacount = 4
# testborders = [ [[1,39],[1,75]], [[40,67],[43,75]], [[68,85],[48,75]], [[86,100],[41,75]] ]
# in debug mode, a file debug.bmp is written to disk with marked changed pixel an with marked border of scan-area
# debug mode should only be turned on while testing the parameters above
debugmode = false # false or true
# capture a small test image (for motion detection)
def capturetestimage(settings, width, height):
command = "raspistill %s -w %s -h %s -t 200 -e bmp -n -o -" % (settings, width, height)
imagedata = stringio.stringio()
imagedata.write(subprocess.check_output(command, shell=true))
imagedata.seek(0)
im = image.open(imagedata)
buffer = im.load()
imagedata.close()
return im, buffer
# save a full size image to disk
def saveimage(settings, width, height, quality, diskspacetoreserve):
keepdiskspacefree(diskspacetoreserve)
time = datetime.now()
filename = filepath + "/" + filenameprefix + "-%04d%02d%02d-%02d%02d%02d.jpg" % (time.year, time.month, time.day, time.hour, time.minute, time.second)
subprocess.call("raspistill %s -w %s -h %s -t 200 -e jpg -q %s -n -o %s" % (settings, width, height, quality, filename), shell=true)
print "captured %s" % filename
# keep free space above given level
def keepdiskspacefree(bytestoreserve):
if (getfreespace() < bytestoreserve):
for filename in sorted(os.listdir(filepath + "/")):
if filename.startswith(filenameprefix) and filename.endswith(".jpg"):
os.remove(filepath + "/" + filename)
print "deleted %s/%s to avoid filling disk" % (filepath,filename)
if (getfreespace() > bytestoreserve):
return
# get available disk space
def getfreespace():
st = os.statvfs(filepath + "/")
du = st.f_bavail * st.f_frsize
return du
# get first image
image1, buffer1 = capturetestimage(camerasettings, testwidth, testheight)
# reset last capture time
lastcapture = time.time()
while (true):
# get comparison image
image2, buffer2 = capturetestimage(camerasettings, testwidth, testheight)
# count changed pixels
changedpixels = 0
takepicture = false
if (debugmode): # in debug mode, save a bitmap-file with marked changed pixels and with visible testarea-borders
debugimage = image.new("rgb",(testwidth, testheight))
debugim = debugimage.load()
for z in xrange(0, testareacount): # = xrange(0,1) with default-values = z will only have the value of 0 = only one scan-area = whole picture
for x in xrange(testborders[z][0][0]-1, testborders[z][0][1]): # = xrange(0,100) with default-values
for y in xrange(testborders[z][1][0]-1, testborders[z][1][1]): # = xrange(0,75) with default-values; testborders are not zero-based, buffer1[x,y] are zero-based (0,0 is top left of image, testwidth-1,testheight-1 is botton right)
if (debugmode):
debugim[x,y] = buffer2[x,y]
if ((x == testborders[z][0][0]-1) or (x == testborders[z][0][1]-1) or (y == testborders[z][1][0]-1) or (y == testborders[z][1][1]-1)):
# print "border %s %s" % (x,y)
debugim[x,y] = (0, 0, 255) # in debug mode, mark all border pixel to blue
# just check green channel as it's the highest quality channel
pixdiff = abs(buffer1[x,y][1] - buffer2[x,y][1])
if pixdiff > threshold:
changedpixels += 1
if (debugmode):
debugim[x,y] = (0, 255, 0) # in debug mode, mark all changed pixel to green
# save an image if pixels changed
if (changedpixels > sensitivity):
takepicture = true # will shoot the photo later
if ((debugmode == false) and (changedpixels > sensitivity)):
break # break the y loop
if ((debugmode == false) and (changedpixels > sensitivity)):
break # break the x loop
if ((debugmode == false) and (changedpixels > sensitivity)):
break # break the z loop
if (debugmode):
debugimage.save(filepath + "/debug.bmp") # save debug image as bmp
print "debug.bmp saved, %s changed pixel" % changedpixels
# else:
# print "%s changed pixel" % changedpixels
# check force capture
if forcecapture:
if time.time() - lastcapture > forcecapturetime:
takepicture = true
if takepicture:
lastcapture = time.time()
saveimage(camerasettings, savewidth, saveheight, savequality, diskspacetoreserve)
# swap comparison buffers
image1 = image2
buffer1 = buffer2
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持萬仟网。
希望与广大网友互动??
点此进行留言吧!
python动作捕捉_树莓派动作捕捉抓拍存储图像脚本相关推荐
- python 动画人物动作_角色-动作
本文由@平凡技术人生分享,原文链接 " 别怕吃读书的苦,这是你通向世界最好的路." 01.角色-动作 今天和京京重新开始scratch编程,角色部分里面造型动作部分学习.首先第一有 ...
- python舵机控制程序_树莓派PWM控制舵机的两种方式
PWM控制舵机简介 通常情况下,伺服电机(舵机)是由一个标准的直流系统和一个内部反馈控制装置(一个减速齿轮和电位计)来组成的.伺服电机(舵机)的主要作用是将齿轮轴旋转到一个预定义的方向上.伺服电机(舵 ...
- python摄像头推流_树莓派使用python-librtmp实现rtmp推流h264的方法
目的是能使用Python进行rtmp推流,方便在h264帧里加入弹幕等操作. librtmp使用的是0.3.0,使用树莓派noir官方摄像头适配的. 通过wireshark抓ffmpeg的包一点点改动 ...
- 树莓派python开发教程_树莓派教程(基于python编程)--入门篇
原标题:树莓派教程(基于python编程)--入门篇 一:格式化SD卡 SD卡插入读卡器连接电脑,使用SDFormatter对SD卡进行格式化 (重装烧录也要进行着SD卡格式化操作) 二:下载官方镜像 ...
- python连接传感器_树莓派4B之光敏传感器模块(python3)
背景 本人最因工作原因接触到各种电路板,传感器,而自己又是一个小白,随意在其他朋友的推荐下决定从树莓派开始玩传感器:本例子为树莓派控制红外避障传感器 材料 1.树莓派4b 2.火焰传感器模块 3.导线 ...
- 树莓派python编程小车_树莓派小车教程(三)——软件代码
原标题:树莓派小车教程(三)--软件代码 树莓派小车教程(三)--软件代码 2017-07-07 琳小豆 HelloWorld少儿编程 树莓派小车教程 (三) 在上一次教程中,我们已经完成了硬件连接. ...
- 树莓派python开发教程_树莓派Raspberry开发从基础到进阶视频+设计资料超详细教程下载...
课程内容 [初级篇]重点推荐:树莓派开发实战视频教程+文档教程(含源码) 课程目录 教学视频与源代码 1.[进阶篇]Raspberry详细视频教程 树莓派基础 安装树莓派的操作系统 远程登录和使用树莓 ...
- python gps模块_树莓派连接GPS模块
一月份的时候觉得好玩买了树莓派,但是太懒没怎么研究,但最近当初买树莓派时的那个梦想又萦绕心头,决定抽空完成一下当年的计划~ GPS模块是其中很重要的一环,于是在某宝上搜索,找了一家相对便宜也很轻巧的G ...
- 用python画一条龙_树莓派打造北邮人种子下载机——下载、做种一条龙全站式教程...
树莓派是一台电脑,只不过它非常小巧,是基于 Linux 的单片机电脑,不贵-但是它的玩法很多,比如你可以在里面使用 Python 编写游戏,搭建网站,邮件收发,HTTP 服务器,Git 服务器,种子资 ...
最新文章
- phpstorm支持php7吗,PHPStorm支持PHP7类型提示等新语法
- iOS开发(1)写在前面的话
- Oracle学习:分组数据(group by)与笛卡尔积
- birt报表数据只有一条_企业构建大数据分析体系的4个层级
- Spring MVC应用程序中的Thymeleaf模板布局,无扩展
- 64位CentOS6.2安装erlang及rabbitmqServer
- 计算机操作系统(10):集群和分布式
- ehchache验证缓存过期的api_Ehcache缓存配置
- 大数据之-Hadoop3.x_Hadoop_MapReduce_介绍---大数据之hadoop3.x工作笔记0081
- 适合千万数据查询分页操作的一个通用存储过程
- 读书笔记《程序员修炼之道》
- 大魔王覃超解说 2017 Google I/O丨今晚直播!
- Bash shell编程的语法知识点(1)
- 分享6款国内、外开源PHP轻论坛CMS程序
- 魅族7.0系统最简单激活Xposed框架的经验
- 服务器文件防泄密系统,数据防泄密软件解决图纸泄密问题
- C# 实现软件授权码的功能
- 燃料电池多点恒功率工作Cruise仿真模型
- 网管服务器维修,网管员管理和维护的超级武器
- Mac M1 踩坑之Tensorflow安装 Processed finished with exit code 132
热门文章
- Aspose.Words实用教程:如何处理文档分段——Aspose.Words中的分段
- 完整版:交换机工作过程和原理
- WslRegisterDistribution failed with error: 0x80370102 Error: 0x80370102 ???????????????????
- C++:C++编程语言学习之数学运算运算符及其优先级的简介、案例应用之详细攻略
- 2020华中科技大学计算机保研夏令营经验
- 手机如何压缩照片?压缩方法分享
- 中国联通MEC边缘云架构与部署实践
- java正则基本用法
- linux下配置NAT服务
- php spry文本域_spry菜单栏(二)