alicedingZhang UranusXubin Nisheng
Published © Apache-2.0

Home Automation

design a smart lock for your house

AdvancedWork in progress24 hours1,426
Home Automation

Things used in this project

Hardware components

Android device
Android device
×1
Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
Camera Module
Raspberry Pi Camera Module
×1
Bluetooth to USB Dongle
mbientLab Bluetooth to USB Dongle
×1
Intel RealSense Camera
Intel RealSense Camera
×1
Microphone Amplifier Breakout
Adafruit Microphone Amplifier Breakout
×1
Sonos speakers
Sonos speakers
×1
AWS CloudWatch
Amazon Web Services AWS CloudWatch
×1

Software apps and online services

Android Things
Google Android Things

Story

Read more

Schematics

Bluetooth module

Code

get face from camera

Python
import cv2
import os
import sys
import random

out_dir = './my_faces'
if not os.path.exists(out_dir):
    os.makedirs(out_dir)



def relight(img, alpha=1, bias=0):
    w = img.shape[1]
    h = img.shape[0]
    #image = []
    for i in range(0,w):
        for j in range(0,h):
            for c in range(3):
                tmp = int(img[j,i,c]*alpha + bias)
                if tmp > 255:
                    tmp = 255
                elif tmp < 0:
                    tmp = 0
                img[j,i,c] = tmp
    return img


cv2.CascadeClassifier('haarcascade_frontalface_default.xml')


camera = cv2.VideoCapture(0)

n = 1
while 1:
    if (n <= 10000):
        print('It`s processing %s image.' % n)
        success, img = camera.read()

        gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        faces = haar.detectMultiScale(gray_img, 1.3, 5)
        for f_x, f_y, f_w, f_h in faces:
            face = img[f_y:f_y+f_h, f_x:f_x+f_w]
            face = cv2.resize(face, (64,64))
            '''
            if n % 3 == 1:
                face = relight(face, 1, 50)
            elif n % 3 == 2:
                face = relight(face, 0.5, 0)
            '''
            face = relight(face, random.uniform(0.5, 1.5), random.randint(-50, 50))
            cv2.imshow('img', face)
            cv2.imwrite(out_dir+'/'+str(n)+'.jpg', face)
            n+=1
        key = cv2.waitKey(30) & 0xff
        if key == 27:
            break
    else:
        break

Credits

aliceding

aliceding

1 project • 1 follower
graduate student
Zhang Uranus

Zhang Uranus

1 project • 1 follower
Xubin Ni

Xubin Ni

1 project • 1 follower
sheng

sheng

1 project • 1 follower

Comments

Add projectSign up / Login