element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Vision Thing
  • Challenges & Projects
  • Project14
  • Vision Thing
  • More
  • Cancel
Vision Thing
Blog Smart Security Camera (with Attendance on Google Sheets)
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Vision Thing requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: aabhas
  • Date Created: 17 Nov 2019 1:34 PM Date Created
  • Views 1616 views
  • Likes 11 likes
  • Comments 5 comments
  • visionthingch
  • makevember 2019
  • makevember
  • raspberri pi
  • project14
Related
Recommended

Smart Security Camera (with Attendance on Google Sheets)

aabhas
aabhas
17 Nov 2019
image

Vision Thing

Enter Your Project for a chance to win an Oscilloscope Grand Prize Package for the Most Creative Vision Thing Project!

Back to The Project14 homepage image

Project14 Home
Monthly Themes
Monthly Theme Poll

 

Smart Security Camera

(with attendance on Google Sheets)

 

Summary

image

The AIM of the project is to make a smart camera that can monitor your house, office, etc and

give you valuable data like keeping track of who is on the door, at when did any person arrive, click photographs on unknown people and only open the smart lock (electromagnetic based) when a known person is at the door.

 

Hardware Requirements

-Raspberry Pi (any version will do for best results 4B(2GB) was used)

-Raspberry Pi CSI Camera

-Power Bank

-SD card(flashed with latest raspbian)

-Relay (for controlling door lock)

 

Software Requirements

-PIP (install it along with python)

-GIT

-Clone my Github repository - http://github.com/aabhassenapati/smart_security_camera

and unzip the file on the raspberry pi.

 

Bringing the Project into Real Life

There are two main parts of this project one is Face Recognition using OpenCV and the other is sending the onto Google Sheets and the most difficult task is to integrate these two together.

 

So to start building this project first we need to set up the requirements for OpenCV face recognition

so hook up to the terminal and run following commands one by one

$ sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-100
$ sudo apt-get install libqtgui4 libqtwebkit4 libqt4-test python3-pyqt5
$ sudo apt-get install libatlas-base-dev
$ sudo apt-get install libjasper-dev
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
$ pip install virtualenv virtualenvwrapper
$ mkvirtualenv cv -p python3
$ workon cv
$ pip install opencv-contrib-python
$ pip install dlib      
$ pip install face_recognition
$ pip install imutils

image

after then we need to unzip the repository and  root to its directory

$ workon cv
$ cd smart_security_camera
$ tree

image

you need to then replace the dataset with your desired dataset 5 images per person is sufficient, then you need to run the encode_faces.py

$ python encode_faces.py --dataset dataset --encodings encodings.pickle \
 --detection-method hog

 

 

image

the next step is to get the client_secret.json file from google sheets API to use it to upload data onto google sheets by following the steps below, then place the client_secret.json file in the smart_security_camera directory.

image

The next step is to get the Spreadsheet ID and Sheet ID of your google sheet worksheet where you want the data and replace it in the code in face_reconition.py and sheet.py files.

image

image

the next step is to connect the relay 5v and GND pin with  VCC and GND of raspberry pi and signal pin of the relay with GPIO pin 18 and connect it with your electromagnetic lock as a switch connection

image

 

NOW you are ready with all required installations and then you need to run both python files to get the smart security camera working. In a new terminal type following commands

$ workon cv
$ cd smart_security_camera
$ python pi_face_recognition.py --cascade haarcascade_frontalface_default.xml \
 --encodings encodings.pickle

 

$ workon cv
$ cd smart_security_camera
$ python sheet.py

Working VIDEO Demonstration

(please bear with bad quality of the video as I had to record with the phone as don't have a camera soo)

                                               

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

Code and Its basic concept of Working

(the code below has an error with tabs  when I paste the code , so if you want  code take it from GitHub it has proper tabs )

USAGEimage

good frame rate about 8.5 frames per second was achievedimage

the python script uploading data to google sheets

image

the relay turns on when a known person is detected

image

data on google sheets

 

The two essential part of the entire project is the pi_face_recognition.py and sheet.py python file. In the broader aspect, the pi_face_recognition.py file does the face recognition and stores it locally while the sheet.py takes this data and uploads it to Google Sheets.

 

Working of pi_face_recognition.py:-

The first tas is to use the encodings of the faces and determine that is there any face in the frame, then the next task is that it does is that it checks with each and every face to identify whose face it is or is it an unknown face then it draws a bounding box around the face and if an unknown face is detected it stores that frame with numbering the unknown face serially, then the last task is that it stores this data locally to an excel file.

 

Working of sheet.py:-

The task of this script is to take the data from the locally saved file and upload it onto Google Sheets with data who was at the door and at what time and date.

 

Problems and errors faced during coding

-The first problem I was facing was with the installation of libraries which I had to do many times and was successful when I installed libraries on a virtual environment creation method.

 

-Then the next problem I faced was that after I was successful in using face recognition with python was that when I tried to use the Google sheets API to upload the data, there was an error which said that it was due to improper authentication but I found that the sheet id name was to be changed and client_secret.json was to be obtained.

 

 

-Then I was successful in sending the data into google sheets but what I observed was that the frame was very very low because it depended on the internet connection as it only went to the next frame after the data uploading of the previous frame was complete. Thus I thought that I should store the data locally and then run another script to upload it onto Google Sheets

 

-The next error I faced was that while doing the storage of data locally onto an excel file it actually was not possible to edit a saved file so I had to learn and used the method in which two files with same data is created and then data is stored by copying the data of one file and adding new data to it and this process continues.

 

-The final error I was facing was that the code terminated after some time as the no person was detected and it reached the end of file while parsing so then I had to get the number of rows from face recognition script and use that as a condition to wait until more rows are added .(earlier I thought that the problem of termination of code can be solved by running the periodically with crontab but was not good approach as it caused repetition of data being uploaded ).

 

I learned a lot about face recognition with open cv, using Google API's and also using excel files in python while making this project overall it was a very great learning experience making and troubleshooting with this project.

 

Some references which were used to make the project are:-

-https://www.pyimagesearch.com/2018/06/25/raspberry-pi-face-recognition/

-http://www.whatimade.today/log-sensor-data-straight-to-google-sheets-from- a-raspberry-pi-zero-all-the-python-code/

   

ANY COMMENTS, IMPROVEMENTS, AND QUERIES ARE WELCOMED IN THE COMMENTS BELOW

I would also like to thank danzima for the Raspberry Pi 4 and tariq.ahmad for the Beaglebone AI

Project14Vision ThingArtificial Intelligence

  • Sign in to reply

Top Comments

  • aabhas
    aabhas over 3 years ago +2
    Actually my internet connection is quite slow as soon as the video uploads on YouTube I will add the video into the blog. Thanks Aabhas Senapati
  • shabaz
    shabaz over 3 years ago +1
    Hi Aabhas, Great project, and well-documented!
  • clem57
    clem57 over 3 years ago +1
    Nice and very interesting... Great use of Google for data capture and analysis. Thanks aabhas
  • aabhas
    aabhas over 3 years ago in reply to shabaz

    Thanks shabaz and clem57

    Thanks for your compliments , yet if any other suggestions are welcomed.

    Thanks

    Aabhas Senapati

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • clem57
    clem57 over 3 years ago

    Nice and very interesting... Great use of Google for data capture and analysis.

    Thanks aabhas

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 3 years ago

    Hi Aabhas,

     

    Great project, and well-documented!

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • aabhas
    aabhas over 3 years ago

    One thing wanted to share is that usually I always gave the ideas for what I would make earlier and then when submission deadline was near I would start making some project that too in a hurry and so earlier was never able to get time to add proper documentation with tutorial for making it .

    But this time I did the project with more dedication started early , debugged all errors and made improvements and had proper time to blog it up along with description of every part of it , It took me around 2-4 full days only doing this project entire day and two more days to blog it up properly . And of course as I spent ample amount of time in making the project and made it gradually this learnt a lot many new things and enjoyed exploring.

     

    Anyhow myself very satisfied and  with my submission this time , and tried to make in such a way that even noob could follow and make it.      , So that someone like me enterting into a completely new topic can easily make things by following documented tutorials.

     

    Thanks

    Aabhas Senapati

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • aabhas
    aabhas over 3 years ago

    Actually my internet connection is quite slow as soon as the video uploads on YouTube I will add the video into the blog.

    Thanks

    Aabhas Senapati

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube