Smart Spy
The Smart Spy is a device which is going to use the camera, the Intel Edison and the gsm module to recognize wanted or blacklisted people and alert administrators and police.
You will need;
1. Intel Edison Board
2. GSM/GPRS shield
3. PC USB Camera
import numpy as np
import cv2
cap = cv2.VideoCapture('vtest.avi')
fgbg = cv2.createBackgroundSubtractorMOG()
while(1): ret, frame = cap.read()
fgmask = fgbg.apply(frame)
cv2.imshow('frame',fgmask) k = cv2.waitKey(30) & 0xff if k == 27: break
cap.release() cv2.destroyAllWindows()
Face detection In python With a webcam
Pre-requisites:
OpenCV installed (see the previous blog post for details)A working webcam
Let’s get into the code taken from this https://github.com/mugiluri/Face-Detection-with-camera
import cv2
import sys
cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)
video_capture = cv2.VideoCapture(0)
while True:
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30),
flags=cv2.cv.CV_HAAR_SCALE_IMAGE )
# Draw a rectangle around the faces
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
Explanation:
import cv2
import sys
cascPath = sys.argv[1] faceCascade = cv2.CascadeClassifier(cascPath)
Creating a face cascade
video_capture = cv2.VideoCapture(0)
Setting the video source to the default webcam
NOTE: You can also provide a filename here, and Python will read in the video file. However, you need to have ffmpeg https://www.ffmpeg.org/ installed for that since OpenCV itself cannot decode compressed video. Ffmpeg acts as the front end for OpenCV, and, ideally, it should be compiled directly into OpenCV. This is not easy to do, especially on Windows.
while True:
# Capture frame-by-frame ret, frame = video_capture.read()
We capture the video. The read() function reads one frame from the video source, which in this example is the webcam. Then returns:
The actual video frame read (one frame on each loop)A return codeThe return code tells us if we have run out of frames, which will happen if we are reading from a file. This doesn’t matter when reading from the webcam, since we can record forever, so we will ignore it.
# Capture frame-by-frame
ret, frame = video_capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale( gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30), flags=cv2.cv.CV_HAAR_SCALE_IMAGE )
# Draw a rectangle around the faces for (x, y, w, h) in faces: cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Display the resulting frame cv2.imshow('Video', frame)
Searching for the face in our captured frame.
if cv2.waitKey(1) & 0xFF == ord('q'):
break
Wait for the ‘q’ key to be pressed then we exit the script.
# When everything is done, release the capture
video_capture.release() cv2.destroyAllWindows()
Cleaning up
Image Processing and identification
Sending SMS and alert to administrators GSM/GPRS module