Ian Whitestone
PyCon Canada 2018
Slides: ianwhitestone.work/talks
To illustrate an example of this, consider the following background model image:
Next, we take our latest frame,
Then blur it and convert it to black and white so it can be compared to our background image.
Taking the difference between the two frames yields the following "delta" image:
Next, we threshold (or binarize) the image, by converting all pixels above/below a certain threshold to white or black.
Dilation is then performed to close any gaps. Dilation involves moving a sliding window (kernel) over an image, and updating a given pixel's value based on the surrounding pixels.
if white_blobs == big:
alert()
You can see how all this is layered together in the demo below.
entering /pycam_on
in slack sends a post request to a Flask function
@app.route('/pycam_on', methods=["POST"])
@slack_verification()
def pycam_on():
"""Turn on the pycam process.
Returns:
str: Response to slack
"""
if utils.redis_get('camera_status'):
response = 'Pycam is already running'
else:
utils.redis_set('camera_status', True)
response = "Pycam has been turned on"
return response
import requests
# Create a new requests session
session = requests.session()
# Call the login API with my credentials
response = session.post('<router_login_api_url>', LOGIN_DATA)
# Update my cookie with the new, authenticated user_id
user_str = response.headers['Set-Cookie']
user_id = user_str.split(';')[0].split('userid=')[1]
new_cookie = BASE_COOKIE.format(USERNAME, PWD, user_id)
headers['Cookie'] = new_cookie
# Call api and get connected devices
response = session.get('<get_connected_devices_api_url>', headers=headers)
devices = response.json()
connected_devices = [d['hostName'] for d in devices]
do_deep_learning()
download pre-trained image classifier model
import cv2
# Load model
net = cv2.dnn.readNetFromCaffe(proto_file, caffe_model_file)
# Get classifications
net.setInput(img)
classifications = net.forward()
you should probably buy an actual home security system
you allowed me to build a home security system with: