Skip to content

Commit 28940c2

Browse files
committed
first commit
0 parents  commit 28940c2

File tree

14 files changed

+33698
-0
lines changed

14 files changed

+33698
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.idea
2+
*.log
3+
*.json
4+
*pyc*
5+
.env

Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM jjanzic/docker-python3-opencv:latest
2+
# RPI: FROM sgtwilko/rpi-raspbian-opencv:latest
3+
4+
WORKDIR /src
5+
6+
COPY requirements.txt /src/requirements.txt
7+
8+
RUN pip install --upgrade pip && \
9+
pip install -r requirements.txt
10+
11+
COPY src/ /src
12+
13+
CMD ["/bin/bash"]

Dockerfile-rpi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM sgtwilko/rpi-raspbian-opencv:latest
2+
#FROM mohaseeb/raspberrypi3-python-opencv:latest
3+
4+
WORKDIR /src
5+
6+
COPY requirements.txt /src/requirements.txt
7+
8+
RUN pip install --upgrade pip && \
9+
pip install -r requirements.txt
10+
11+
COPY src/ /src
12+
13+
CMD ["/bin/bash"]

LICENSE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Copyright (c) 2019 Guillain Sanchez <[email protected]>
2+
3+
Private License
4+
5+
Distribution not allowed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# gPhoto-object-extraction
2+
_How to run easily the object recognition_
3+
4+
For the demo and to make it more funny:
5+
- the source of information (means the photo galery) is *Google Photo*!
6+
- the object recognized are stored on *AWS S3*!
7+
- all run in docker :)
8+
- ... compatible with Raspberry
9+
10+
## Pre-requisite
11+
- Docker host
12+
- Internet access
13+
14+
## Easy Run
15+
After have cloned the repository localy (`git clone https://github.com/guillain/gPhoto-object-extraction`)
16+
and enter in the new directory (`cd gPhoto-object-extraction`) execute the following commands:
17+
18+
1/ create your own confguration file:
19+
- `cp sample.env .env && vi .env` and add your AWS credentials info
20+
- import the files `google-photo.json` and `google-photo-token.json` as GCP credentials info
21+
- if you need to run it on Raspberry, invert the comment on the first two lines in the `Dockerfile`
22+
23+
2/ execute the container with the desired date for your Google Photos: `./run "29/12/2019"`
24+
25+
26+
## Support
27+
- Original post:
28+
- https://www.hackster.io/mjrobot/real-time-face-recognition-an-end-to-end-project-a10826
29+
- https://github.com/Mjrovai/OpenCV-Face-Recognition
30+
- Raspberry: https://www.raspberrypi.org
31+
- Docker: https://www.docker.com
32+
- OpenCV: https://opencv.org

requirements.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
tensorflow
2+
python-forecastio
3+
opencv-python==4.1.0.25
4+
awscli
5+
boto3
6+
numpy
7+
google-api-python-client
8+
httplib2
9+
oauth2client
10+
python-dotenv

run

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
. .env
3+
4+
# my_date=${1} if not provided, go in bash
5+
6+
# Name of the container (to build & run)
7+
NAME="gphoto-object-extraction"
8+
9+
# If no date, go in console
10+
if [ "${1}" == "" ]; then
11+
echo -e '\n/!\ No date provided, we jump in the console (exit to go out) /!\ \n'
12+
RUN="/bin/bash"
13+
else
14+
RUN="python app.py"
15+
fi
16+
17+
# Build the image
18+
docker build -t ${NAME} .
19+
20+
# Test the image and the cv2 import
21+
docker run -it --rm ${NAME} python -c "import cv2; print(cv2.__version__)"
22+
23+
# Run the app
24+
docker run -it --rm \
25+
-e my_date=${1} \
26+
--env-file=`pwd`/.env \
27+
-v `pwd`/google-photo.json:/src/google-photo.json \
28+
-v `pwd`/google-photo-token.json:/src/google-photo-token.json \
29+
${NAME} ${RUN}
30+
31+
# Done & Bye
32+
exit 0

sample.env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
aws_s3_bucket=my_obects
2+
aws_region_name=eu-central-1
3+
aws_key_id=
4+
aws_access_key=
5+
6+
gcp_ident_file=google-photo.json
7+
gcp_token_file=google-photo-token.json

setup.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from setuptools import setup, find_packages
2+
3+
NAME="gPhoto-object-extraction"
4+
__version__ = '1.0.0'
5+
AUTHOR="Guillain"
6+
AUTHOR_EMAIL="[email protected]"
7+
8+
with open('requirements.txt') as f:
9+
requirements = f.read().splitlines()
10+
11+
setup(
12+
name=NAME,
13+
version=__version__,
14+
description="Image analysis with IA",
15+
url='https://gitlab.com/bo-art-of-bonsai/' + NAME,
16+
author=AUTHOR,
17+
author_email=AUTHOR_EMAIL,
18+
license='Private',
19+
install_requires=requirements,
20+
packages=find_packages(),
21+
zip_safe=False
22+
)

src/app.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8
3+
import os
4+
import requests
5+
6+
from lib.aws import AWS
7+
from lib.opencv import OpenCV
8+
from lib.gcp import GCP
9+
10+
from dotenv import load_dotenv
11+
load_dotenv()
12+
13+
14+
def main(my_date):
15+
# my_date = "29/11/2019"
16+
17+
# Instancies
18+
aws = AWS(bucket=os.getenv('aws_s3_bucket'))
19+
gcp = GCP(cred_file=os.getenv('gcp_token_file'))
20+
cv = OpenCV()
21+
22+
# Get list of photos
23+
photos = gcp.listMedia(date_filter=my_date, media_type=["PHOTO"])
24+
if photos is None:
25+
print('error', 'No photos found, exit')
26+
exit(0)
27+
print('{} photos found'.format(len(photos)))
28+
29+
# For each photo: download, extract each face and store individual face in S3
30+
face_catalog = []
31+
for photo in photos:
32+
# Download photo data
33+
photo_data = requests.get(photo['baseUrl']).content
34+
with open(photo['filename'], 'wb') as handler:
35+
handler.write(photo_data)
36+
37+
faces = cv.extract_faces(photo['filename'])
38+
#faces = cv.extract_faces_from_buffer(photo_data)
39+
40+
i_face = 1
41+
for face in faces:
42+
filename = 'extract/{}'.format(face)
43+
44+
aws.s3_upload_file(face, filename)
45+
os.remove(face)
46+
#aws.s3_upload_data(face, filename)
47+
48+
face = dict(photo)
49+
face['face_id'] = i_face
50+
face['face_filename'] = filename
51+
#del face['baseUrl']
52+
face_catalog.append(face)
53+
54+
i_face = i_face + 1
55+
56+
os.remove(photo['filename'])
57+
print('{} face(s) found in the photo {}'.format(i_face - 1, photo['filename']))
58+
59+
if face_catalog:
60+
for face in face_catalog:
61+
print('JSON catalog of faces\n{}'.format(face))
62+
print('{} face(s) found in total'.format(len(face_catalog)))
63+
else:
64+
print('No face found :(')
65+
66+
67+
if __name__ == '__main__':
68+
main(os.getenv('my_date'))
69+

0 commit comments

Comments
 (0)