I wanted to get a text when someone comes to my front door. I know you can buy a commercial camera that does this, but I wanted more control over the images. My garage has a window that faces the front door of my house, so I didn't have to build a weatherproof enclosure.
Overview
The system has a smart cam that detects people and notifies the Raspberry Pi when one is the the frame. A python program on the Raspberry Pi writes the Jpeg to a file and uploads it to Google Drive. The program then uses Twilio to send a text with a link to the photo to my cell phone.
Hardware
I am using a Jevois smart camera and a Raspberry Pi. The Jevois camera is an open source smart cam that runs Linux and has a number of built in modules and costs about $50. I've previously tried to do image recognition using just a webcam on a Raspberry Pi, but the performance wasn't good.
The Jevois comes in a small 3D printed case with a mini-USB connector on the back. I used a piece of scrap MDF to make a base. I initially wanted to use the Jevois on a tripod so I cut a hole and glued a 1/4-20 nut in the MDF. I screwed the Jevois to the MDF with the suggested screws. The holes in the case aren't tapped so it's a little tricky.
To make a stable base, I took the small cardboard box that the Jevois was shipped in, cut a small hole in the top and glued a 1/4-20 bolt in the top. When the glue was dry, I filled the box with sand and screwed the Jevois on to the box.
For the computer, I used a Raspberry Pi 3B that I had from a previous project and I connected the Jevois via USB. One thing to note, The Raspberry Pi doesn't provide enough power to reliably power the Jevois via the USB port. Jevois sells a pigtail USB that has two standard USB connections - one for data, and one for power - connected to a mini-USB. I used one of these with the data connection going to the PI and the power going to a USB power adapter/wall charger.
Software
The Jevois cam has YOLO as one of the bundled machine vision modules. I've had success with it previously, so I just used the stock version.
On the Raspberry Pi, the following code controls the camera, saves the image when a person is detected, copies it to Google Drive and texts me.
#!/usr/bin/python3
TWaccount_sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
TWauth_token = 'lotsarandomchars'
import os,sys
import time
import shutil
import cv2
import numpy
import serial
import logging
from datetime import datetime
from twilio.rest import Client
import uploader
def SendParm(cmd):
ser.write (cmd)
time.sleep(1)
line = ser.readline()
if Headless:
logging.info(cmd.decode('utf8'))
logging.info(line.decode('utf8'))
else:
print (cmd.decode('utf8'))
print (line.decode('utf8'))
#main -------
Headless=True
#default to not headless when debugging in Idle
if 'idlelib.run' in sys.modules:
#idle
Headless=False
thresh=50 # default detection threshold
if len(sys.argv)>1:
if sys.argv[1]=='-show':
Headless=False
elif 'thresh' in sys.argv[1]:
thresh_arg=sys.argv[1].split("=")
thresh=int(thresh_arg[1])
if len(sys.argv)>2:
if 'thresh' in sys.argv[2]:
thresh_arg=sys.argv[2].split("=")
thresh=int(thresh_arg[1])
if os.name == 'nt':
folder = 'C:\\users\\peter/jevois_capture'
logfile = 'c:\\users\\peter/jevois.log'
cfg_path = 'c:/Users/peter/frontdoorcam/uploader.cfg'
port = 'COM7'
camno = 0
else: #linux
folder = '/home/pi/jevois_capture'
logfile = '/home/pi/jevois.log'
cfg_path = '/home/pi/frontdoorcam/uploader.cfg'
port = '/dev/ttyACM0'
camno = 0
logging.basicConfig(filename=logfile,level=logging.DEBUG)
logging.info('------- Jevois Cam Startup --------')
ser = serial.Serial(port,115200,timeout=0.01)
# No windows in headless
if not Headless:
cv2.namedWindow("jevois", cv2.WINDOW_NORMAL)
cv2.resizeWindow("jevois",1280,480)
camera = cv2.VideoCapture(camno)
...
Read more »
More tipz
https://github.com/PINTO0309/OpenVINO-YoloV3
http://www.lindeni.org/lindenis-v5.html