I am assuming you now how to get Raspbian onto the Raspberry Pi so I will not be covering it in the tutorial. # if you have have a differnt number of Pictues change the xrange # Ghost = list() CLOCK = () # This is to setup the Gui-less display # driver = 'fbcon' os.putenv('SDL_VIDEODRIVER', driver) # initialize pygame # () size = (().current_w, ().current_h) # display the size of the screen # print("Framebuffer size: %d x %d" % (size, size)) # Turn off the Mouse # _visible(0) # set the Dsiplay to Fullscreen # DS = _mode(size, pygame.FULLSCREEN) # Initially fill the sceen Black # DS.fill((0,0,0)) () #main while loop while cv2.waitKey(1) != 27: # Capture the stream from the camera # for f in camera.capture_continuous(stream, format='bgr', use_video_port=True): # Check for ESC # event_handler() # Capture the image and compare it to the previous image # imgOriginal = f.array uncate(0) imgOriginal = imutils.resize(imgOriginal, width=500) imgGray = cv2.cvtColor(imgOriginal, cv2.COLOR_BGR2GRAY) imgGray = cv2.GaussianBlur(imgGray, (21, 21), 0) if avg is None: avg = py().astype("float") uncate(0) continue cv2.accumulateWeighted(imgGray, avg, 0.5) frameDelta = cv2.absdiff(imgGray, cv2.convertScaleAbs(avg)) thresh = cv2.threshold(frameDelta, 5, 255, cv2.THRESH_BINARY) thresh = cv2.dilate(thresh, None, iterations=2) # Motion Tracking # (_, cnts, _) = cv2.findContours(py(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) for c in cnts: if cv2.contourArea(c) 0: # Take the x cordinate add half of the Width # This gets the center of the motion on the x-axis # Divde by 18 and add 1 to get the Picture number # Int() make it a whole number Round() rounds down # z = int(round((x + (w/2))/18)) + 1 # Rather than allow the Ghost to jump from center # we have it cycle through till we hit new center # while imgNum z: # If it is new motion just diplay the fist # if imgNum = 0: imgNum = z # Debug #print("Picture Start = Ghost_" + str(imgNum) + ".jpg") DS.blit(Ghost, (336, 0)) # If its to the right go up 1 image # elif z > imgNum: imgNum += 1 # Debug #print("Picture + Ghost_" + str(imgNum)+ ".jpg") DS.blit(Ghost, (336, 0)) # if its to the left go down 1 image # else: imgNum -= 1 # Debug #print("Picture - Ghost_" + str(imgNum) + ".jpg") DS.blit(Ghost, (336, 0)) () # Debug #print("Picture = " + str(z) + ", x = " + str(x) + ", w = " + str(w)) cntSleep = 0 continue # Make the Ghost Disapear after 10 rounds with no Movement# if cntSleep > 10: # Debug #print("Black Screen") DS.fill((0,0,0)) () # Set the next movement to the First movement # imgNum = 0 # Debug #print("Sleep = " + str(cntSleep)) cntSleep += 1 # Debug #timerCnt += 1 #print("Timer = " + str(timerCnt)) #if timerCnt >= 100: # quit() return if _name_ = "_main_": main() import picamera.array import picamera import cv2 import numpy as np import os from imutils.object_detection import non_max_suppression from imutils import paths import imutils import time import pygame from pygame.locals import * import sys import random # ESC key to Exit Program # def event_handler(): for event in (): if event.type = QUIT or (event.type = KEYDOWN and event.key = K_ESCAPE): pygame.quit() sys.exit() # The Main Loop # def main(): # setup for Camera and OpenCV # Start the Camera # camera = picamera.PiCamera() stream = (camera, size=(640, 480)) # set the resolution I used 640x480 so I could use 36 Pictures # camera.resolution = (640, 480) # Set frame rate at 16 to reduce the stress on the Raspberry Pi # amerate = 16 # set the inital values of the tracking variables # motionCounter = 0 avg = None cntSleep = 0 imgNum = 1 # setup for Pygame # import the Ghost images. Note that python is a very specific TAB syntax you will need to use the included file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |