• Stars
    star
    560
  • Rank 79,541 (Top 2 %)
  • Language
    Python
  • Created about 7 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

IoT security camera running open-cv for object detection 📹

Smart-Security-Camera

IoT Raspberry Pi security camera running open-cv for object detection. The camera will send an email with an image of any objects it detects. It also runs a server that provides a live video stream over the internet.

Watch the original video here

Setup

This project uses a Raspberry Pi Camera to stream video. Before running the code, make sure to configure the raspberry pi camera on your device.

Open the terminal and run

sudo raspi-config

Select Interface Options, then Pi Camera and toggle on. Press Finish and exit.

You can verify that the camera works by running

raspistill -o image.jpg

which will save a image from the camera in your current directory. You can open up the file inspector and view the image.

Installing Dependencies

This project uses openCV to detect objects in the video feed. You can install openCV by using the following tutorial. I used the Python 2.7 version of the tutorial.

The installation took almost 8 hours (!!) on my Raspberry Pi Zero, but it would be considerably faster on a more powerful board like the Raspberry Pi 3.

The tutorial will prompt you to create a virtual environment. Make sure you are using the virtual environment by typing the following commands

source ~/.profile
workon cv

Next, navigate to the repository directory

cd Smart-Security-Camera

and install the dependencies for the project

pip install -r requirements.txt

Note: If you're running python3, you'll have to change the import statements at the top of the mail.py file

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage

and change your print statements from quotes to parenthesis

print "" => print()

Customization

To get emails when objects are detected, you'll need to make a couple modifications to the mail.py file.

Open mail.py with vim vim mail.py, then press i to edit. Scroll down to the following section

# Email you want to send the update from (only works with gmail)
fromEmail = '[email protected]'
fromEmailPassword = 'password1234'

# Email you want to send the update to
toEmail = '[email protected]'

and replace with your own email/credentials. The mail.py file logs into a gmail SMTP server and sends an email with an image of the object detected by the security camera.

Press esc then ZZ to save and exit.

You can also modify the main.py file to change some other properties.

email_update_interval = 600 # sends an email only once in this time interval
video_camera = VideoCamera(flip=True) # creates a camera object, flip vertically
object_classifier = cv2.CascadeClassifier("models/fullbody_recognition_model.xml") # an opencv classifier

Notably, you can use a different object detector by changing the path "models/fullbody_recognition_model.xml" in object_classifier = cv2.CascadeClassifier("models/fullbody_recognition_model.xml").

to a new model in the models directory.

facial_recognition_model.xml
fullbody_recognition_model.xml
upperbody_recognition_model.xml

Running the Program

Run the program

python main.py

You can view a live stream by visiting the ip address of your pi in a browser on the same network. You can find the ip address of your Raspberry Pi by typing ifconfig in the terminal and looking for the inet address.

Visit <raspberrypi_ip>:5000 in your browser to view the stream.

Note: To view the live stream on a different network than your Raspberry Pi, you can use ngrok to expose a local tunnel. Once downloaded, run ngrok with ./ngrok http 5000 and visit one of the generated links in your browser.

Note: The video stream will not start automatically on startup. To start the video stream automatically, you will need to run the program from your /etc/rc.local file see this video for more information about how to configure that.

More Repositories

1

Smart-Mirror

Raspberry powered mirror which can display news, weather, calendar events
Python
907
star
2

AI-Smart-Mirror

Smart Mirror with a smart AI 🤖
Python
536
star
3

Tracking-Turret

A motion tracking turret.
Python
179
star
4

Smart-Bartender

🍻
Python
148
star
5

OpenAI-NEAT

NEAT Solver for OpenAI
Python
146
star
6

Autonomous-Follow-Me-Cooler

Cooler that follows you by navigating via GPS 🍹🌊⛱
C++
89
star
7

Smart-Doorbell

A wifi-connected raspberry pi doorbell with video chat
Python
87
star
8

Raspberry-Pi-VNC-Mac

How to Setup Raspberry Pi VNC Screensharing on a Mac
62
star
9

Smartphone-Doorlock

Doorlock that can be locked or unlocked through your smartphone
JavaScript
58
star
10

Automated-Gardener

Simple scheduler for a Raspberry Pi powered indoor gardener
Python
51
star
11

Holographic-Audio-Visualizer

JavaScript
28
star
12

Facebook-Newsbot

Raspberry Pi Powered Chatbot
JavaScript
21
star
13

Portable-Arcade

C
18
star
14

realtime-subscriber-counter

An LED Matrix that counts subscribers (and cryptocurrency prices) in realtime.
Python
15
star
15

midi-footswitch

MIDI footswitch for software instruments
C++
14
star
16

multi-stream-chatbot

Chatbot framework that listens and sends messages to multiple live-streaming platforms simultaneously
JavaScript
14
star
17

Animatable-LED-Hat

Battery operated, LED matrix hat that can be programmed to display interesting designs.
Arduino
9
star
18

Light-Rover

Light painting robot
Python
7
star
19

hackershack-livestream-chatbot

Code for the Hacker Shack livestream chatbot
JavaScript
6
star
20

Robotic-Bartender

Project files for our Arduino/Raspberry Pi powered robotic bartender
Arduino
6
star
21

HackerShackOfficial.github.io

Github pages site for Hacker Shack
HTML
2
star