Let's Make a Security Camera using your smartphone [2021]



Can I use my smartphone as a Security Camera?

Definitely possible. Today we are going to turn your smartphone into a security camera that can communicate via wifi. Eventually, Python is Improved so that people can recognize it. A third-party application creates a web app that can communicate over a Wifi network. The camera can be accessed from any device on the same wifi network.
 

Pre-preparation

  1. This requires a smartphone with Android app support.
  2. Install IP Webcam App from Play Store.
  3. Make sure the smartphone and computer are on the same Wifi network.
Now you are all ready.

Step 1

Open Ip Webcam. Then enter Start Server at the bottom of the App Menu.

IP Webcam for Android

Step 2

Get the IP address at the bottom of the dashboard you see. For example https://192.10.1.1:8080. Type this address into your computer's web browser. Then you will see the web application below. When you click on the browser under Video Renderer, you will see what the smartphone camera looks like from the computer browser.

Home Made Security Camera - IP Webcam

Now you have a wonderful Security Camera because it is wireless.

Enhancement with Python artificial intelligence

Before enabling artificial intelligence, let's take a look at how to obtain this Python program through an API. To do this, write a simple program using the Opencv Library.  If the OpenCV library is not already installed, type the following at the command prompt and enter.

pip install opencv-python

Code to retrieve video data streaming via IP Webcam into a Python program.

import cv2

api = "http://192.168.1.100:8080/video"
cap = cv2.VideoCapture(api)

while True:
ret, frame= cap.read()
cv2.imshow("Image", frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()

A cascade file is required to identify faces. To do so, download the haarcascade_frontalface_default.xml file from this Repo. Then Complete the code as follows. 

import cv2

cascPath = "haarcascade_frontalface_default.xml"
api = "http://192.168.1.100:8080/video"
cap = cv2.VideoCapture(api)

faceCascade = cv2.CascadeClassifier(cascPath)
while True:
# Read the frame
ret, frame= cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Detect face in the frame
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
)

for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow("Faces found", frame)

if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()

Github Repo

Now you have a security camera powered by artificial intelligence. We will improve this in a more interesting way in future lessons. Stay tuned with us. If you have ideas and questions, please comment below. Thank you.

Post a Comment

0 Comments