最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

樹(shù)莓派動(dòng)作捕捉抓拍存儲(chǔ)圖像腳本

 更新時(shí)間:2019年06月22日 10:52:16   作者:soft2buy  
這篇文章主要為大家詳細(xì)介紹了樹(shù)莓派動(dòng)作捕捉抓拍存儲(chǔ)圖像腳本,支持Python 2.7,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了樹(shù)莓派動(dòng)作捕捉抓拍存儲(chǔ)圖像的具體代碼,供大家參考,具體內(nèi)容如下

#!/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

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 怎樣用cmd命令行運(yùn)行Python文件

    怎樣用cmd命令行運(yùn)行Python文件

    這篇文章主要介紹了怎樣用cmd命令行運(yùn)行Python文件問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Python列表和元組的定義與使用操作示例

    Python列表和元組的定義與使用操作示例

    這篇文章主要介紹了Python列表和元組的定義與使用操作,結(jié)合實(shí)例形式分析了Python中列表和元組的功能、區(qū)別、定義及使用方法,需要的朋友可以參考下
    2017-07-07
  • 跟老齊學(xué)Python之復(fù)習(xí)if語(yǔ)句

    跟老齊學(xué)Python之復(fù)習(xí)if語(yǔ)句

    是否記得,在上一部分,有一講專門(mén)介紹if語(yǔ)句的:從if開(kāi)始語(yǔ)句的征程。在學(xué)習(xí)if語(yǔ)句的時(shí)候,對(duì)python編程的基礎(chǔ)知識(shí)了解的還不是很多,或許沒(méi)有做什么太復(fù)雜的東西。本講要對(duì)它進(jìn)行一番復(fù)習(xí),通過(guò)復(fù)習(xí)提高一下。如果此前有的東西忘記了,建議首先回頭看看前面那講。
    2014-10-10
  • Python壓縮包處理模塊zipfile和py7zr操作代碼

    Python壓縮包處理模塊zipfile和py7zr操作代碼

    目前對(duì)文件的壓縮和解壓縮比較常用的格式就是zip格式和7z格式,這篇文章主要介紹了Python壓縮包處理模塊zipfile和py7zr,需要的朋友可以參考下
    2022-06-06
  • Python Pandas數(shù)據(jù)分析工具用法實(shí)例

    Python Pandas數(shù)據(jù)分析工具用法實(shí)例

    這篇文章主要介紹了Python Pandas數(shù)據(jù)分析工具用法實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • python運(yùn)行cmd命令行的3種方法總結(jié)

    python運(yùn)行cmd命令行的3種方法總結(jié)

    雖然python在調(diào)用cmd命令方面使用的比較少,不過(guò)還是要用的,下面這篇文章主要給大家介紹了關(guān)于python運(yùn)行cmd命令行的3種方法,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-09-09
  • Django model.py表單設(shè)置默認(rèn)值允許為空的操作

    Django model.py表單設(shè)置默認(rèn)值允許為空的操作

    這篇文章主要介紹了Django model.py表單設(shè)置默認(rèn)值允許為空的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-05-05
  • Python交換字典鍵值對(duì)的四種方法實(shí)例

    Python交換字典鍵值對(duì)的四種方法實(shí)例

    字典中有成對(duì)出現(xiàn)的鍵和值,但是字典中的鍵值對(duì)不是都能修改的,只有值才能修改,下面這篇文章主要給大家介紹了關(guān)于Python交換字典鍵值對(duì)的四種方法,需要的朋友可以參考下
    2022-12-12
  • Python OpenCV學(xué)習(xí)之圖像形態(tài)學(xué)

    Python OpenCV學(xué)習(xí)之圖像形態(tài)學(xué)

    形態(tài)學(xué)處理方法是基于對(duì)二進(jìn)制圖像進(jìn)行處理的,卷積核決定圖像處理后的效果。本文將為大家詳細(xì)介紹一下OpenCV中的圖像形態(tài)學(xué),感興趣的可以了解一下
    2022-01-01
  • 一文帶你深入了解Python中的GeneratorExit異常處理

    一文帶你深入了解Python中的GeneratorExit異常處理

    GeneratorExit是Python內(nèi)置的異常,當(dāng)生成器或協(xié)程被強(qiáng)制關(guān)閉時(shí),Python解釋器會(huì)向其發(fā)送這個(gè)異常,下面我們來(lái)看看如何處理這一異常吧
    2025-03-03

最新評(píng)論

玉环县| 嘉峪关市| 池州市| 海口市| 虹口区| 竹山县| 北辰区| 贵港市| 盱眙县| 资源县| 西平县| 法库县| 马公市| 三亚市| 永定县| 沾益县| 福海县| 怀仁县| 丹东市| 广灵县| 泽普县| 巫溪县| 读书| 凭祥市| 教育| 宝丰县| 错那县| 梧州市| 濉溪县| 绥棱县| 治多县| 河北省| 合作市| 三原县| 新乡县| 潼关县| 岳阳市| 沅江市| 颍上县| 乐陵市| 黄大仙区|