[python, openCV] base64 Face recognition with images

environment

Repository

https://github.com/hirokoma/face_detection_of_base64_string

code

!/usr/bin/python
 -*- coding: utf-8 -*-

import sys
import cv2, os
import numpy as np
from PIL import Image
import base64
from StringIO import StringIO

import scipy.misc

# Haar-like feature classifier
cascadePath = "/path/to/haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath)

def readb64(base64_string):
    sbuf = StringIO()
    sbuf.write(base64.b64decode(base64_string))
    pimg = Image.open(sbuf)
    return pimg
    #cv2.cvtColor(np.array(pimg), cv2.COLOR_RGB2BGR)

def detect():
 # Load base64 in grayscale
    image_pil = readb64(sys.argv[1].replace("\\", "\\\\")).convert('L')
 Stored in an array of # NumPy
    image = np.array(image_pil, 'uint8')
 # Haar-like Feature classifier detects face (parameters are appropriate)
    faces = faceCascade.detectMultiScale(image,1.1,9,0)

    scipy.misc.imsave('outfile.jpg', image)

 # Display the coordinates of the detected face image
    for (x, y, w, h) in faces:
        print x,y,w,h

detect()

Recommended Posts

[python, openCV] base64 Face recognition with images
Try face recognition with python + OpenCV
Face recognition with camera with opencv3 + python2.7
Face recognition with Python's OpenCV
Face detection with Python + OpenCV
Face recognition / cutting with OpenCV
Try face recognition with Python
Number recognition in images with Python
Cut out face with Python + OpenCV
Load gif images with Python + OpenCV
I tried face recognition with OpenCV
Face detection with Python + OpenCV (rotation invariant)
Capturing images with Pupil, python and OpenCV
[Python] Read images with OpenCV (for beginners)
Serverless face recognition API made with Python
Face recognition with Edison
Binarization with OpenCV / Python
Hello World and face detection with OpenCV 4.3 + Python
Performance comparison of face detector with Python + OpenCV
[Python3] [Ubuntu16] [Docker] Try face recognition with OpenFace
Bordering images with python Part 1
Base64 encoding images in Python 3
"Apple processing" with OpenCV3 + Python3
Image editing with python OpenCV
Camera capture with Python + OpenCV
[Python] Using OpenCV with Python (Basic)
Try projective transformation of images using OpenCV with Python
Face detection with Python + dlib
Using OpenCV with Python @Mac
Image recognition with Keras + OpenCV
I tried "morphology conversion" of images with Python + OpenCV
Anime face detection with OpenCV
[Super easy] Simultaneous face recognition and facial expression recognition in real time with Python and OpenCV!
Real-time face recognition with video acquired by getUserMedia [HTML5, openCV]
A memo when face is detected with Python + OpenCV quickly
I tried face recognition from the video (OpenCV: python version)
Handle Base91 keys with python + redis.
Shining life with Python and OpenCV
[Python] Using OpenCV with Python (Image Filtering)
Face detection with Lambda (Python) + Rekognition
[Python] Using OpenCV with Python (Edge Detection)
Try face recognition with Generated Photos
Easy Python + OpenCV programming with Canopy
[OpenCV] Personal identification with face photo
Post multiple Twitter images with python
Animate multiple still images with Python
python x tensoflow x image face recognition
First Anime Face Recognition with Chainer
[Python] Collect images easily with icrawler!
Find image similarity with Python + OpenCV
Use OpenCV with Python 3 in Window
Draw an illustration with Python + OpenCV
Track baseball balls with Python + OpenCV
Graph Based Segmentation with Python + OpenCV
Object recognition with openCV by traincascade
Working with DICOM images in Python
Draw arrows (vectors) with opencv / python
Basic study of OpenCV with Python
Object extraction in images by pattern matching using OpenCV with Python
Replace your face with Twitter icon with openCV face recognition and do ZOOM
The fastest way to get camera images regularly with python opencv