Using the face detection function of Watson Visual Recognition, I tried to process a whole body image of a person into an image of only the face part

Introduction

Watson Visual Recognition's Detect Face face detection feature allows you to read a person's age, gender, and position of the face in an image. This time, we implemented a code in Java that uses a face detection function called Detect Face to detect the position of the face from a human image and process it into an image of only the face part.

Java execution environment construction

  1. JDK installation Install the JDK from the URL below. http://www.oracle.com/technetwork/java/javase/downloads/index.html

Please refer to the following URL for the installation method. http://qiita.com/hiesiea/items/54e49dabfb5606edb54d#2-jdk%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB    2. Install eclipse Install eclipse from the following URL. http://www.eclipse.org/downloads/

Please refer to the following URL for the installation method. http://qiita.com/hiesiea/items/54e49dabfb5606edb54d#3-eclipse%E3%81%AE%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB    3. Create Maven project Create "New"-> "Project"-> "Maven Project" of eclipse. maven1.png

Get code, set

  1. Download code Download the code from the URL below. https://github.com/takana-at/VisualRecognition-training
    After downloading, unzip the code.
  2. Code placement Copy the following class to the sample.app project. ・DetectFaces.java ・DetectFacesThread.java ・TrainingDefinition.java

Implementation of face detection function of Visual Recognition

Creating a Visual Recognition service

  1. Create a Visual Recognition service on Bluemix. Log in to Bluemix from the URL below and create a "Catalog"-> "Watson"-> "Visual Recognition" service. https://console.bluemix.net/

  2. After creating the Visual Recognition service, check {api_key} from "Service Credentials"-> "Credentials-1" and make a note of it. visual_recognition1.png

Execute Java code

This time, we will execute DetectFaces.java, which is a code that cuts and saves only the face part of a person's image.

  1. Modify the code in DetectFacesThread.java. Change the {api_key} in the code for this class to the api_key you noted earlier.

  2. Place the image you want to detect the face. For images, create a "trainImage" folder directly under the project, create a "image ID name" folder in the "trainImage" folder, and place the image in the "image ID name" folder. This image ID is used to sort by person, so place the same person in the folder with the same image ID name.

PROJECTNAME
|-trainImage
   |-IMGID_NAME
      |-IMG  
      |-IMG

For example, the images of "m010462.jpg " and "m010469.jpg " are stored in the folder with the image ID name "femaleA" as shown below.

reface1.png

  1. Put the following in the argument and implement. 「./trainImage」 DetectFaces2.png

  2. The execution result is as follows. face2.png

  3. After execution, a folder with the image ID will be created in the faceImage folder directly under the project, and the image will be saved in that image ID folder.

reface2.png

  1. The image under this faceImage will be the image that the image under trainImage is extracted, renamed, and saved. 【trainImage/female/m010462.jpg】 m010462.jpg        ↓ 【faceImage/female/m010462.jpg_face.jpg】    m010462.jpg_face.jpg

Recommended Posts

Using the face detection function of Watson Visual Recognition, I tried to process a whole body image of a person into an image of only the face part
I tried to make a simple face recognition Android application using OpenCV
I tried to make a message function of Rails Tutorial extension (Part 1): Create a model
I tried using the Server Push function of Servlet 4.0
I tried to make a reply function of Rails Tutorial extension (Part 3): Corrected a misunderstanding of specifications
I tried to make the sample application into a microservice according to the idea of the book "Microservice Architecture".
I tried to make a message function of Rails Tutorial extension (Part 2): Create a screen to display
[Swift] I tried to implement the function of the vending machine
[Rails] Implementation of multi-layer category function using ancestry "I tried to make a window with Bootstrap 3"
I tried to implement the image preview function with Rails / jQuery
I tried using the cache function of Application Container Cloud Service
How to set an image in the drawable Left / Right of a button using an icon font (Iconics)
I tried to make a sample program using the problem of database specialist in Domain Driven Design
I tried to implement a function equivalent to Felica Lite with HCE-F of Android
What I tried when I wanted to get all the fields of a bean