Other CamerasRaspberry Pi

Octopod: Smart IoT Home/Industry Automation Project

Octopod, a uniquely shaped full industry automation system that allows you to monitor your industry and keep security with AI and smart RFID locks.There are many IoT automation projects out there, but trust me there is nothing like this! Octopod is made using NodeMCU (MAX32620FTHR or Arduino MKR 1010), Arduino Uno, and Raspberry Pi 3. Octopod allows you to make your home smart. Octopod sends you a variety of data like temperaturehumidity, and gas quality inside your home/office/ industry. Octopod sends you notification whenever it detects any sort of motion inside and tells you when you need to water your plants. You can also control your appliances through a Blynk application on your smartphone. Octopod even enables true mood lighting!

 Story

Octopod is equipped with a tiny little camera, which sends you live feed. This camera also uses artificial intelligence to detect humans in its sight and sends you their pictures. In addition, it features an RFID door locking system! Awesome, right?Octopod: Smart IoT Home/Industry Automation Project

How Everything Works?

The NodeMCU is connected to a bunch of sensors, a relay module and RGB LEDs. It is connected to Blynk app on a smartphone via WiFi, which sends all the data and allows you to control your home.

Raspberry Pi is also connected to WiFi, which lets you see the live feed via the Pi Camera. We have also installed OpenCV libraries on the Pi, and configured the Pi to detect any human beings in its sight and email you their images.

The smart door unit uses an RFID module. When the permitted RFID is brought within its range, it automatically opens the door.

STEP 1: Coding Main Octopod

I have added comments on almost every line, so you don’t only copy but you understand. Here, I will tell you what actually happens when the code is executed in a nutshell!

  • Including the Libraries:

This code uses 2 main libraries, the Blynk Library to make the code compatible to the Blynk Application and the the other library is the DHT11 Temperature Library, which converts the raw data from the sensor into Temperature and Humidity. To download these libraries, just go to the given links in the code and download them. Then head to Arduino IDE  Sketch → Include library → Add .zip library, and select your downloaded libraries.

#include<ESP8266WiFi.h>                    //Include Blynk Library
#include<BlynkSimpleEsp8266.h>        //Include Blynk Library
#include<dht.h>                                     //Include DHT sensor library
#define BLYNK_PRINT Serial

This is some Blynk code that helps you connect your nodemcu to the internet and then authenticate it to your app.

// You should get Auth Token in the Blynk App.// Go to the Project Settings (nut icon).char auth[] = "Your Auth Key";// Your WiFi credentials.// Set password to "" for open networks.char ssid[] = "Your WiFi SSID";char pass[] = "Your WiFi Pass";
  • Defining Pins and Integers:

In this segment we define the pins of our various sensors. You can change them as per your convince. We also define some Integers that we tend to use during the course of our code.

#define DHTPIN 2          // What digital pin temperature and humidity sensor is connected to#define soilPin 4         // What digital pin soil moisture sensor is connected to#define gasPin A0         // What analog  pin gas sensor is connected to#define pirPin 12         // What digital pin soil moisture sensor is connected to int pirValue;             // Place to store read PIR Valueint soilValue;            // Place to store read Soil Moisture Valueint PIRpinValue;          // Place to store the value sent by Blynk App Pin V0int SOILpinValue;         // Place to store the value sent by Blynk App Pin V1
  • BLYNK_WRITE() :

With this code we tell the Blynk app that it can use Pin V0 and Pin V1 to tell the code if Motion Detection and Soil Moisture test are turned ON.

BLYNK_WRITE(V0)             //VO pin from Blynk app tells if Motion Detection is ON{ PIRpinValue = param.asInt();    } BLYNK_WRITE(V1)             //V1 pin from Blynk app tells if Soil Moisture is ON{ SOILpinValue = param.asInt();    }
  • void sendSensor() :

This code takes the data from DHT11 make it use able, and then sends it to Pin V5 and V6 respectively.

void sendSensor(){  int h = dht.readHumidity();  int t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit  if (isnan(h) || isnan(t)) {    Serial.println("Failed to read from DHT sensor!"); // to check if sensor is not sending any false values    return;  }  // You can send any value at any time.  // Please don't send more that 10 values per second.  Blynk.virtualWrite(V5, h);  // send humidity to pin V5  Blynk.virtualWrite(V6, t);  // send temperature to pin V7}
  • void getPirValue() & void getSoilValue() :

Reads the digital value from the sensors, then it runs an if- else condition to check the state of the sensor. If the sensor is in required state, it pushes a notification from the Blynk App.

void getPirValue(void){  pirValue = digitalRead(pirPin);  if (pirValue)      //digital pin of PIR gives high value on human detection  {     Serial.println("Motion detected");    Blynk.notify("Motion detected");    }}void getSoilValue(void){  soilValue = digitalRead(soilPin);  if (soilValue == HIGH)     //digital pin of soil sensor give low value when humidity is less  {     Serial.println("Water Plants");    Blynk.notify("Water Plants");    }}
  • void setup() :

In the setup we do a couple of things that are only meant to be done once. Like: Starting the serial communication at a fixed Baud Rate, Authorize this code to the Blynk application, beginning the Dht sensor readings, then tweeting to your twitter handle that your Smart Home Project is Online, then telling the node that Pir Pin and Soil Sensor Pin is meant to take Input only.

void setup(){  // Debug console  Serial.begin(9600);  Blynk.begin(auth, ssid, pass);  // You can also specify server:  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);  dht.begin(); // Begins DHT reading    Blynk.tweet("OCTOPOD IS ONLINE!  "); // Tweating on your Twitter Handle that you project is online    pinMode(pirPin,INPUT);    // Defining that Pir Pin is meant to take Input Only  pinMode(soilPin,INPUT);   // Defining that Soil Sensor Pin is meant to take Input Only    // Setup a function to be called every second  timer.setInterval(1000L, sendSensor);}
  • void loop() :

In the loop we write things that are to be done over and over. Here, we make sure that the code that we wrote before setup runs. Then, we write 2 If- Else Statements that check the states of the Pin V0 and Pin V1 and then take the values from the sensors accordingly.

void loop(){  Blynk.run();  timer.run();    if (PIRpinValue == HIGH)   //VO pin from Blynk app tells if Motion Detection is ON      {        getPirValue();      }        if (SOILpinValue == HIGH)  //V1 pin from Blynk app tells if Soil Moisture is ON      {        getSoilValue();      }   }

STEP 2: Coding the RFID Smart Lock

To be honest this is a simple and easy Code and doesn’t need much explanation. But, I will still tell you in a nutshell what this does. There are two versions of the code, one is if you want to connect the door unit box to Bluetooth so it tells you when your door is open via the serial terminal. Other sends to serial so it can be viewed if you connect your Arduino to your computer. I prefer simple without Bluetooth version though . So here we go!

  • Go to Sketch → Include Library → Manage Library → Type in the search bar MFRC522 and install the library. Then go File → Examples → Custom Libraries → MFRC522 → dumpInfo Sketch. In the starting you can read how to connect pins (Or refer the picture). Then run the code and open serial monitor and bring one your Rfid Card in front of the MFRC522 Module and wait for 5 second. Then, note the card UID in a similar manner note the UID’s of your other cards and Key Chains.
  • Then download which ever code you like. Open the code and go to this line. Here in place of these X’s add the UID of the card that you want to use to open the door. Now you are ready, just upload the code.
if (content.substring(1) == "XX XX XX XX") {
}

In this code there are two main things that we do, that is in If- Else part of the code. In if we tell the arduino that if the the UID of the card matches to the UID mentioned make the Servo move (So that the Door Opens) and blinks some Led’s and make some sounds by using the buzzer. Else if the UID’s don’t make blink some led’s and make some sounds by using the Buzzer.human detection

STEP 3: Raspberry Pi Human Detection AI Setup

In this guided step we are going to learn how to make a Smart Security Camera. The camera will send you An Email whenever it detects the object and If you are on the same WiFi network you can access the live footage by the camera by typing the IP address of your Raspberry Pi. I will show you how to create the smart camera from scratch. Let’s go!

Requirements :

1. OpenCV (Open Source Computer Vision Library)

2. Raspberry Pi 3B

3. Raspberry Pi Camera V2

Assumptions:

1. Raspberry Pi 3 with Raspbian Stretch installed. If you don’t already have the Raspbian Stretch OS, you’ll need to upgrade your OS to take advantage of Raspbian Stretch’s new features.

To upgrade your Raspberry Pi 3 to Raspbian Stretch, you may download it here and follow these upgrade instructions (or these for the NOOBS route which is recommended for beginners).

Note: If you are upgrading your Raspberry Pi 3 from Raspbian Jessie to Raspbian Stretch, there is the potential for problems. Proceed at your own risk, and consult the Raspberry Pi forums for help. Important: It is my recommendation that you proceed with a fresh install of Raspbian Stretch! Upgrading from Raspbian Jessie is not recommended.

2. Physical access to your Raspberry Pi 3 so that you can open up a terminal and execute commandsRemote access via SSH or VNC. I’ll be doing the majority of this tutorial via SSH, but as long as you have access to a terminal, you can easily follow along.

I finished this project almost in 5 Hrs. Installation Of Open CV took almost 3 Hrs.

  • Step 1: ATTACHING CAMERA TO RASPBERRY PI 3

1. Open up your Raspberry Pi Camera module. Be aware that the camera can be damaged by static electricity. Before removing the camera from its grey anti-static bag, make sure you have discharged yourself by touching an earthed object (e.g. a radiator or PC Chassis).

2. Install the Raspberry Pi Camera module by inserting the cable into the Raspberry Pi. The cable slots into the connector situated between the Ethernet and HDMI ports, with the silver connectors facing the HDMI port.

3. Boot up your Raspberry Pi.

4. From the prompt, run “sudo raspi-config”. If the “camera” option is not listed, you will need to run a few commands to update your Raspberry Pi. Run “sudo apt-get update” and “sudo apt-get upgrade”

5. Run “sudo raspi-config” again – you should now see the “camera” option.

COMMAND-

$ sudo raspi-config

6. Navigate to the “camera” option, and enable it (lookout in interfacing option) . Select “Finish” and reboot your Raspberry Pi or just type the following :

$ sudo reboot
  • Step 2 : OPEN CV INSTALLATION

If this is your first time installing OpenCV or you are just getting started with Rasbian Stretch. This is the perfect tutorial for you.

Step #1: Expand filesystem

Are you using a brand new install of Raspbian Stretch? If so, the first thing you should do is expand your filesystem to include all available space on your micro-SD card:

COMMAND-

$ sudo raspi-config

then select the “Advanced Options” menu item and Followed by selecting “Expand filesystem”. Once prompted, you should select the first option, “A1. Expand File System”, hit Enter on your keyboard, arrow down to the “” button, and then reboot your Pi. If you are using an 8GB card you may be using close to 50% of the available space, so one simple thing to do is to delete both LibreOffice and Wolfram engine to free up some space on your PI:

COMMAND-

$ sudo apt-get purge wolfram-engine 
$ sudo apt-get purge libreoffice* 
$ sudo apt-get clean
$ sudo apt-get autoremove

After removing the Wolfram Engine and LibreOffice, you can reclaim almost 1GB!

Step #2: Install dependencies

This isn’t the first time I’ve discussed how to install OpenCV on the Raspberry Pi, so I’ll keep these instructions on the briefer side, allowing you to work through the installation process: I’ve also included the amount of time it takes to execute each command (some depend on your Internet speed) so you can plan your OpenCV + Raspberry Pi 3 install accordingly (OpenCV itself takes approximately 4 hours to compile — more on this later). The first step is to update and upgrade any existing packages:

COMMAND-

$ sudo apt-get update && sudo apt-get upgrade 

We then need to install some developer tools, including CMake, which helps us configure the OpenCV build process: Raspbian Stretch: Install OpenCV 3 + Python on your Raspberry Pi

COMMAND-

$ sudo apt-get install build-essential cmake pkg-config

Next, we need to install some image I/O packages that allow us to load various image file formats from disk. Examples of such file formats include JPEG, PNG, TIFF, etc.: Raspbian Stretch

COMMAND-

$ sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev

Just as we need image I/O packages, we also need video I/O packages. These libraries allow us to read various video file formats from disk as well as work directly with video streams

COMMAND-

$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev 
$ sudo apt-get install libxvidcore-dev libx264-dev

The OpenCV library comes with a sub-module named highgui which is used to display images to our screen and build basic GUIs. In order to compile the highgui module, we need to install the GTK development library: Raspbian Stretch: Install OpenCV 3 + Python on your Raspberry Pi

COMMAND-

$ sudo apt-get install libgtk2.0-dev libgtk-3-dev

Many operations inside of OpenCV (namely matrix operations) can be optimized further by installing a few extra dependencies:

COMMAND-

$ sudo apt-get install libatlas-base-dev gfortran

These optimization libraries are especially important for resource constrained devices such as the Raspberry Pi. Lastly, let’s install both the Python 2.7 and Python 3 header files so we can compile OpenCV with Python bindings: Raspbian Stretch

COMMAND-

$ sudo apt-get install python2.7-dev python3-dev  

If you’re working with a fresh install of the OS, it is possible that these versions of Python are already at the newest version (you’ll see a terminal message stating this). If you skip this step, you may notice an error related to the Python.h header file not being found when running make to compile OpenCV. Step #3: Download the OpenCV source code

Step #3: Download the OpenCV source code

Now that we have our dependencies installed, let’s grab the 3.3.0 archive of OpenCV from the official OpenCV repository. This version includes the dnn module which we discussed in a previous post where we did Deep Learning with OpenCV (Note: As future versions of openCV are released, you can replace 3.3.0 with the latest version number):

COMMAND-

$ cd ~  
$ wget -O opencv.zip <a href="https://github.com/Itseez/opencv/archive/3.3.0.zip">  <a href="https://github.com/Itseez/opencv/archive/3.3.0.zi..." rel="nofollow">  https://github.com/Itseez/opencv/archive/3.3.0.zi...>>p$ unzip opencv.zip<br>

We’ll want the full install of OpenCV 3 (to have access to features such as SIFT and SURF, for instance), so we also need to grab the opencv_contrib repository as well: Raspbian Stretch: Install OpenCV 3 + Python on your Raspberry Pi

COMMAND-

$ wget -O opencv_contrib.zip <a href="https://github.com/Itseez/opencv_contrib/archive/3.3.0.zip">  <a href="https://github.com/Itseez/opencv_contrib/archive/..." rel="nofollow">  https://github.com/Itseez/opencv_contrib/archive/...>>3.3.0$ unzip opencv_contrib.zip

You might need to expand the command above using the “<=>” button during your copy and paste. The .zip in the 3.3.0.zip may appear to be cutoff in some browsers. The full URL of the OpenCV 3.3.0 archive is:https://github.com/Itseez/opencv_contrib/archive/… Note: Make sure your opencv and opencv_contrib versions are the same (in this case, 3.3.0). If the versions numbers do not match up, then you’ll likely run into either compile-time or runtime errors. Step #4: Python 2.7 or Python 3? Before we can start compiling OpenCV on our Raspberry Pi 3, we first need to install pip , a Python package manager

COMMAND-

$ wget <a href="https://bootstrap.pypa.io/get-pip.py">  <a href="https://bootstrap.pypa.io/get-pip.py" rel="nofollow"> <a href="https://bootstrap.pypa.io/get-pip.py" rel="nofollow"> https://bootstrap.pypa.io/get-pip.py></a>>></a>>
$ sudo python get-pip.py 
$ sudo python3 get-pip.py

You may get a message that pip is already up to date when issuing these commands, but it is best not to skip this step. If you’re a longtime PyImageSearch reader, then you’ll know that I’m a huge fan of both virtualenv and virtualenvwrapper.

Installing these packages is not a requirement and you can absolutely get OpenCV installed without them, but that said, I highly recommend you install them as other existing PyImageSearch tutorials (as well as future tutorials) also leverage Python virtual environments.

I’ll also be assuming that you have both virtualenv and virtualenvwrapperinstalled throughout the remainder of this guide. So, given that, what’s the point of using virtualenv and virtualenvwrapper ? First, it’s important to understand that a virtual environment is a special tool used to keep the dependencies required by different projects in separate places by creating isolated, independentPython environments for each of them. In short, it solves the “Project X depends on version 1.x, but Project Y needs 4.x” dilemma.

It also keeps your global site-packages neat, tidy, and free from clutter. If you would like a full explanation on why Python virtual environments are good practice, absolutely give this excellent blog post on RealPython a read. It’s standard practice in the Python community to be using virtual environments of some sort, so I highly recommend that you do the same:

COMMAND-

$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip 

Now that both virtualenv and virtualenvwrapper have been installed, we need to update our ~/.profile file. include the following lines at the bottom of the file: Raspbian Stretch

COMMAND-

$ nano ~/.profile

Copy & paste the following lines lines at the bottom of the file:

COMMAND-

<em># </em>virtualenv and virtualenvwrapper
WORKON_HOME=$HOME/.virtualenvs 
source /usr/local/bin/virtualenvwrapper.sh 

OR

You should simply use cat and output redirection to handle updating ~/.profile :

COMMAND-

$ echo -e "\n# virtualenv and virtualenvwrapper" >> ~/.profile 
$ echo "exportWORKON_HOME=$HOME/.virtualenvs" >> ~/.profile
$ echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.profile 

Now that we have our ~/.profile updated, we need to reload it to make sure the changes take affect. You can force a reload of your ~/.profile file by: Logging out and then logging back in.

Closing a terminal instance and opening up a new one

Or my personal favourite

COMMAND-

$ source ~/.profile 

Note: I recommend running the source ~/.profile file each time you open up a new terminal to ensure your system variables have been setup correctly. Creating your Python virtual environment Next, let’s create the Python virtual environment that we’ll use for computer vision development:

COMMAND-

$ mkvirtualenv cv -p python2 

This command will create a new Python virtual environment named cv using Python 2.7.

If you instead want to use Python 3, you’ll want to use this command instead:

COMMAND-

$ mkvirtualenv cv -p python3 <br>

Again, I can’t stress this point enough: the cv Python virtual environment is entirely independent and sequestered from the default Python version included in the download of Raspbian Stretch.

Any Python packages in the global site-packages directory will not be available to the cv virtual environment. Similarly, any Python packages installed in site-packages of cv will not be available to the global install of Python.

Keep this in mind when you’re working in your Python virtual environment and it will help avoid a lot of confusion and headaches. How to check if you’re in the “cv” virtual environment If you ever reboot your Raspberry Pi; log out and log back in; or open up a new terminal, you’ll need to use the workon command to re-access the cv virtual environment.

In previous blog posts, I’ve seen readers use the mkvirtualenv command — this is entirely unneeded! Themkvirtualenv command is meant to be executed only once: to actually create the virtual environment. After that, you can use workon and you’ll be dropped down into your virtual environment:

COMMAND-

$ source ~/.profile 
$ workon cv

To validate and ensure you are in the cv virtual environment, examine your command line — if you see the text (cv) preceding your prompt, then you are in the cv virtual environment: Make sure you see the “(cv)” text on your prompt, indicating that you are in the cv virtual environment.

Otherwise, if you do not see the (cv) text, then you are not in the cv virtual environment:

If you do not see the “(cv)” text on your prompt, then you are not in the cv virtual environment and need to run “source” and “workon” to resolve this issue. To fix this, simply execute the source and workon commands mentioned above. Installing NumPy on your Raspberry Pi Assuming you’ve made it this far, you should now be in the cv virtual environment (which you should stay in for the rest of this tutorial).

Step #4 : Installing NumPy on your Raspberry Pi

Our only Python dependency is NumPy, a Python package used for numerical processing:

COMMAND-

$ pip install numpy 

the NumPy installation can take a bit of time.

Step #5: Compile and Install OpenCV

COMMAND-

$ workon cv

Once you have ensured you are in the cv virtual environment, we can setup our build using CMake:

COMMAND-

$ cd ~/opencv-3.3.0/   $ mkdir build $ cd build  $ cmake  -D CMAKE_BUILD_TYPE=RELEASE \                        -D CMAKE_INSTALL_PREFIX=/usr/local \                        -D INSTALL_PYTHON_EXAMPLES=ON \                         -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.3.0/modules \                       -D BUILD_EXAMPLES=ON ..

Now, before we move on to the actual compilation step, make sure you examine the output of CMake! Start by scrolling down the section titled Python 2 and Python 3 . If you are compiling OpenCV 3 for Python 2.7, then make sure your Python 2 section includes valid paths to the Interpreter, Libraries, numpy and packages

Checking that Python 3 will be used when compiling OpenCV 3 for Raspbian Stretch on the Raspberry Pi 3. Notice how the Interpreter points to our python2.7 binary located in the cv virtual environment. The numpy variable also points to the NumPy installation in the cv environment.

Again, the Interpreter points to our python3.5 binary located in the cv virtual environment while numpy points to our NumPy install.

In either case, if you do not see the cv virtual environment in these variables paths, it’s almost certainly because you are NOT in the cv virtual environment prior to running CMake! If this is the case, access the cv virtual environment using workon cv and re-run the cmake command outlined above.

Configure your swap space size before compiling Before you start the compile process, you should increase your swap space size. This enables OpenCV to compile with all four cores of the Raspberry PI without the compile hanging due to memory problems.

Open your /etc/dphys-swapfile and then edit the CONF_SWAPSIZE variable

COMMAND-

$ nano /etc/dphys-swapfile 

and then edit the following section of the file: #set size to absolute value, leaving empty (default) then uses computed value # you most likely don’t want this, unless you have an special disk situation

# CONF_SWAPSIZE=100
  CONF_SWAPSIZE =1024

Notice that I’ve commented out the 100MB line and added a 1024MB line. This is the secret to getting compiling with multiple cores on the Raspbian Stretch. If you skip this step, OpenCV might not compile.

To activate the new swap space, restart the swap service:

COMMAND-

$ sudo /etc/init.d/dphys-swapfile stop 
$ sudo /etc/init.d/dphys-swapfile start 

Note: It is possible to burn out the Raspberry Pi microSD card because flash memory has a limited number of writes until the card won’t work. It is highly recommended that you change this setting back to the default when you are done compiling and testing the install (see below). To read more about swap sizes corrupting memory, see this page. Finally, we are now ready to compile OpenCV:

COMMAND-

$ make -j4

The -j4 switch stands for the number of cores to use when compiling OpenCV. Since we are using a Raspberry Pi 2, we’ll leverage all four cores of the processor for a faster compilation.

However, if your make command errors out, I would suggest starting the compilation over again and only using one core

$ make clean
$ make 

Once OpenCV 3 has finished compiling.Our OpenCV 3 compile on Raspbian Stretch has completed successfully.

From there, all you need to do is install OpenCV 3 on your Raspberry Pi 3:

COMMAND-

$ sudo make install
$ sudo ldconfig 

Step #6 : Finish installing OpenCV on your Pi

We’re almost done — just a few more steps to go and you’ll be ready to use your Raspberry Pi 3 with OpenCV 3 on Raspbian Stretch.

For Python 2.7:

#5 Provided your Step without error, OpenCV should now be installed in/usr/local/lib/python2.7/site-pacakges . You can verify this using the ls command:

COMMAND-

$ ls -l /usr/local/lib/python2.7/site-packages/ 
 total 1852 
-rw-r--r-- 1 root staff 1895772 Mar 20 20:00 cv2.so 

Note: In some cases, OpenCV can be installed in /usr/local/lib/python2.7/dist-packages(note the dist-packages rather than site-packages ). If you do not find the cv2.so bindings insite-packages , we be sure to check dist-packages . Our final step is to sym-link the OpenCV bindings into our cv virtual environment for Python 2.7:

COMMAND-

$ cd ~/.virtualenvs/cv/lib/python2.7/site-packages/ 
$ ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.so 

For Python 3: After running make install , your OpenCV + Python bindings should be installed in/usr/local/lib/python3.5/site-packages . Again, you can verify this with the ls command:

COMMAND-

$ ls -l /usr/local/lib/python3.5/site-packages/
 total 1852 
-rw-r--r-- 1 root staff 1895932 Mar 20 21:51 cv2.cpython-34m.so 

I honestly don’t know why, perhaps it’s a bug in the CMake script, but when compiling OpenCV 3 bindings for Python 3+, the output .so file is named cv2.cpython-35m-arm-linux-gnueabihf.so(or some variant of) rather than simply cv2.so (like in the Python 2.7 bindings). Again, I’m not sure exactly why this happens, but it’s an easy fix. All we need to do is rename the file:

COMMAND-

$ cd /usr/local/lib/python3.5/site-packages/ 
$ sudo mv cv2.cpython-35m-arm-linux-gnueabihf.so cv2.so 

After renaming to cv2.so , we can sym-link our OpenCV bindings into the cv virtual environment

for Python 3.5:

COMMAND-

$ cd ~/.virtualenvs/cv/lib/python3.5/site-packages/ 
$ ln -s /usr/local/lib/python3.5/site-packages/cv2.so cv2.so 

Step #7: Testing your OpenCV 3 install

Congratulations, you now have OpenCV 3 installed on your Raspberry Pi 3 running Raspbian Stretch! But before we pop the champagne and get drunk on our victory, let’s first verify that your OpenCV installation is working properly.

Open up a new terminal, execute the source and workon commands, and then finally attempt to import the Python + OpenCV bindings:

COMMAND-

$ source ~/.profile$ workon cv 
$ python  >>> import cv2  >>> cv2.__version__  '3.3.0'  >>> 

OpenCV 3 has been successfully installed on my Raspberry Pi 3 + Python 3.5 environment . Once OpenCV has been installed, you can remove both the opencv-3.3.0 and opencv_contrib-3.3.0 directories to free up a bunch of space on your disk:

COMMAND-

$ rm -rf opencv-3.3.0 opencv_contrib-3.3.0 

However, be cautious with this command! Make sure OpenCV has been properly installed on your system before blowing away these directories. A mistake here could cost you hours in compile time.

Don’t forget to change your swap size back!

Open your /etc/dphys-swapfile and then edit the CONF_SWAPSIZE variable COMMAND-

# set size to absolute value, leaving empty (default) then uses computed value# you most likely don't want this, unless you have an special disk situation  
CONF_SWAPSIZE=100  
#CONF_SWAPSIZE=1024

Notice that I’ve commented out the 1024MB line and uncommented the 100MB line. As stated above, larger swap spaces may lead to memory corruption, so I recommend setting it back to 100MB. If you skip this step, your memory card won’t last as long. To revert to the smaller swap space, restart the swap service

COMMAND-

$ sudo /etc/init.d/dphys-swapfile stop<br>$ sudo /etc/init.d/dphys-swapfile start
  • STEP 4: Setting Up Python Program

You can verify that the camera works by running.

COMMAND-

$ raspistill -o image.jpg <br>

which will save a image from the camera in your current directory.

After you checked the camera is working. Now download all the python files and models from below link :

LINK:

https://drive.google.com/file/d/0B98uoD6BbkpqZU9FT…

You can open up the file inspector and view the image.

Make sure you are using the virtual environment by typing the following commands:

COMMANDS-

$ source ~/.profile 
$ workon cv 

Next, navigate to the repository directory,

COMMANDS-

$ cd Smart-Security-Camera 

and install the dependencies for the project

COMMANDS-

<strong></strong>$ pip install -r requirements.txt 

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 = 'myemail@gmail.com' 
fromEmailPassword = 'password1234' 
# Email you want to send the update to 
toEmail = 'anotheremail@gmail.com' 

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 intervalvideo_camera = VideoCamera(flip=True) # creates a camera object, flip verticallyobject_classifier = cv2.CascadeClassifier("models/fullbody_recognition_model.xml") # an opencv classifier 
facial_recognition_model.xml 
fullbody_recognition_model.xml 
upperbody_recognition_model.xml

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 :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. Receiving Emails When receiving an email for the first time, you might get the following notification from Google:

By default, Google blocks apps from using SMTP without permissions. We can solve this by clicking on the allow “less secure apps” link and toggle the feature on. The next object detected will send an email.Google blocks apps from using SMTP

STEP 4: Blynk App Interface Setup

This is one of the easiest and fun steps. So let’s get started. Shall we?

  • Downloading the Blynk App is the first obvious step. Download it from App Store or Google Play Store. Sign Up or Login in the app to get started.
  • Click on New Project to create a new project. Name it whatever you like. In devices Choose NodeMCU. In connection type choose WiFi and click on Create.
  • Now you will get a Auth key on your Email. Make sure to copy that and add that to your code.
  • Now click on the + sign to add widgets. You may need to buy some energy!
  • Now add three Gauge’s. Click on of the Gauge’s, name it Temperature. Choose a color of you choice for this gauge. In the pin choose Virtual Pin V6. Set the range from 0 to 50 °C ( not sure for °F), make the label °C/ °F and keep the reading rate to Push.
  • Repeat this for other two Gauges using data as shown in the pictures.
  • Now, add a zeRGBa and set R to digital Pin GP15, B to GP3 and B to GP1.
  • Now add 4 Buttons, change there colors accordingly. Set them as shown in the pictures.
  • Add a SuperChart, add 3 data streams Temperature, Humidity and gas, set there colors, there pins, Range and Suffix.
  • Now, add tabs. Go to the second tab and add Twitter, Notifications, Email and Eventor. In Twitter add you twitter username and password. In Notifications, Switch on Notify when hardware goes off. In Email, set your Email address. In Eventor you can set many triggers, see the picture for the triggers that I have set up.
  • You are done. now click on the play button to use the interface that you have created. You can change the interface as you like. It is really simple and fun process!

STEP 5: Making Octopod Structure

Warning – This is going to be one of most time-consuming process!

NOTE: You can skip this step and 3D print the enclosure that I have provided!

Actually, this step is optional yet the most important step! You can just take a shoe box and avoid all of this hard work. But on the contrary, this hard work makes the project unique. The idea for this unique design striked me while, I was doing my math homework. This shape is inspired from an octagon. Rather, This is a 3D octagon! So let’s get started!

Making the Structure:

  • Take your cardboard and draw a rectangle of 9 cm x 9.5 cm (You can change the dimensions as per your convince). Now, joining end to end draw 4 of theses similar rectangles (8 if your cardboard is long enough).
  • Now make partial cuts (somewhat like paper creases) in between these rectangles and cut out this whole long piece. Repeat this process until you have 4 of these long pieces.
  • Now, using a D draw a 135° and cut it out as shown in the images. Make 16 of these same angles.
  • Using Glue gun glue these angles in between the small pieces. Repeat this for all the joints.
  • Now using glue gun join 2 of these open structures to make a closed structure (somewhat octagon) .
  • Now glue the other two open structure perpendicularly, making a 3-D shape.
  • Now Cut 4 More pieces of of 9 x 9.5 cm and glue them in between all the empty spaces.
  • Now you will be left with only 8 open triangles. Using Acrylic Butter paper cut 8 triangles, which will fit on these open areas, but don’t glue them now.

Paint Job:

For this you need to head out towards an open area! Wear your Mask and Gloves and just make one coat over the structure that you have created. You can go to Youtube, to learn proper ways to make a perfect coat. Now let this dry for 4- 5 Hours and then apply 1 more coat. I think 3 coats will be good for this.

That’s it! You have arrived with a unique piece of art.

You have arrived with a unique piece of art.

STEP 6: Making Door Lock Enclosure

Really simple. Just take a Shoe Box and apply 2- 3 even coats of spray. And maybe for design make check pattern using duck tape like we did!

Making Door Lock Enclosure

 

STEP 7: Assembling the Octopod

I have tried to make this step as simple as possible, by making the schematic diagram. Refer the picture or the file, and make connections accordingly. I will briefly explain all the connections!

  • We have connected the nodeMCU to a large size Solderless Breadboard. We have also connected Breadboard power supply on the breadboard. NodeMCU, all the sensors, LED’s and other components are powered by the power supply.
  • Following are the sensor connections: DHT11 → D4/ GP2 MQ2 → A0/ adc00 Soil Moisture Sensor → D2/ GP4 PIR → D6/ GP1 RGB R → D8/ GP15, G → Rx/ GP3, B → Tx/ GP1 RelayLn1 → D0/ GP16, Ln2 → D5/ GP14 Make the following connections.
  • For powering this you can use Power Bank or a Wall Adapter, which will be connected to the breadboard Power supply.
  • Now, take your Raspberry Pi along with the Raspberry Pi Camera. Make a small hole in one of the walls of the cardboard and glue or tape your Raspberry Camera.

Now, insert all these electronics inside, through any open triangle and close the triangle by using the cut outs of acrylic butter paper that we made. It is better to leave 1 or 2 open, in case something inside needs to be fixed! Also let the prongs of the Soil Moisture Sensor sit outside.

All done! We have completed the making process of the Octopod! Now, Just switch On the power and keep your Octopod over the dining Table or maybe on the Guest’s Table and enjoy! To see the live feed from the Raspberry Pi, just open a browser and put in the IP address of the Pi. Enjoy!Octopod: Smart IoT Home/Industry Automation Project

 

STEP 8: Assembling the Door Lock

After uploading the code on your Arduino just make the connections as shown in the picture or in fritzing file! It is quite simple. Then take the handy shoe box that we made make 2 holes in it for the LED’s to pop out. and allow the servo to stand out. These days mechanical locks like servo’s are also available in the market, though servo works just as fine. This is just an experiment, so please so please don’t use this as you actual lock! Glue the Rfid to one wall of the box and also glue the small breadboard and Arduino. You can use a wall adapter or a Power bank to power this. Just power the Arduino and you will be good to go! Done!

CONCLUSION:

This was a really fun project to do!

I was really happy how it turned out. I think the lights look really well, and i think its well worth making even one of these as a side lamp. I really can’t thank creators of Blynk and OpenCV libraries enough, they are both really excellent pieces of software and made this project possible! As always, if you have any questions on any part of the process please let me know and I will be happy to try help.

Source: Octopod: Smart IoT Home/Industry Automation Project

 

 

 

 

 

 

Tags

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close