I'm doing this CCTV Microcontroller system using Raspberry Pi 4. I want you guys to help with coding using python. For the first Raspberry Pi 4, I want a code(using pytho) for a motion Detection...

1 answer below »
I'm doing this CCTV Microcontroller system using Raspberry Pi 4. I want you guys to help with coding using python. For the first Raspberry Pi 4, I want a code(using pytho) for a motion Detection Detector and camera. Can you guys write this code
Answered 2 days AfterApr 14, 2021

Answer To: I'm doing this CCTV Microcontroller system using Raspberry Pi 4. I want you guys to help with coding...

Sandeep Kumar answered on Apr 16 2021
145 Votes
motion_cam.py
#!/usr/bin/env python3
from datetime import datetime, timedelta
import io
import numpy as np
import os
import argparse
try:
from picamera import PiCamera, PiCamer
aCircularIO
except ImportError:
exit('This script requires the picamera module\nInstall with: sudo pip install picamera')
try:
from PIL import Image, ImageFilter
except ImportError:
exit('This script requires the pillow module\nInstall with: sudo pip install pillow')
def compare(img1, img2):
im = [None, None] # to hold two arrays
for i, f in enumerate([img1, img2]):
im[i] = (np.array(f.convert('L') # convert to grayscale using PIL
.resize((256,256), resample=Image.BICUBIC) # reduce size and smooth a bit using PIL
.filter(ImageFilter.GaussianBlur(radius=2))) # blur using PIL
).astype(np.int) # convert from unsigned bytes to signed int using numpy
return np.abs(im[0] - im[1]).sum()
def user_freespace_gb():
"""
Returns the amount of free space user space in GB
"""
fd = os.open('.', os.O_RDONLY | os.O_DIRECTORY)
info = os.fstatvfs(fd)
os.close(fd)
return (info.f_bsize * info.f_bavail) / (1024 * 1024 * 1024)
class MotionDetect(object):
def __init__(self, args):
self.dryrun = args.dryrun
# Motion detection values that control starting and stoping recording
self.start_threshold = args.start
self.stop_threshold = args.stop
self.prior_image = None

# Stats for motion detection value
self.result_max = 0
self.result_min = float('inf')
self.result_avg = None
# Used to track when motion detection is on
self.motion_time = datetime.now()
self.motion_enabled = False

def run(self):
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here