Skip to content

evalphobia/go-face-plusplus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-face-plusplus

GoDoc License: MIT Release Build Status Go Report Card Code Climate BCH compliance

Unofficial golang library for Face++.

Current Supported API List

  • Face
    • Detect
    • Compare
  • Beautify
    • Merge Face

Quick Usage

Face

Detect

package main

import (
	"fmt"

	"github.com/evalphobia/go-face-plusplus/config"
	"github.com/evalphobia/go-face-plusplus/face"
)

func getFacesFromURL(url string) ([]face.Faces, error) {
	conf := config.Config{
		APIKey:    "",
		APISecret: "",
		Debug:     true,
	}

	svc, err := face.New(conf)
	if err != nil {
		return nil, err
	}

	resp, err:= svc.DetectByURL(
		url,
		face.WithReturnLandmark(face.ReturnLandmarkYES),
        face.WithReturnAttributes(face.GetAllReturnAttributes()...))
	if err != nil {
		return nil, err
    }

    fmt.Printf("Face Count: %d\n", resp.FaceNum)
    return resp.Faces, nil
}

Compare

package main

import (
	"fmt"

	"github.com/evalphobia/go-face-plusplus/config"
	"github.com/evalphobia/go-face-plusplus/face"
)

func compareFacesFromURL(url1, url2 string) ([]face.Faces, []face.Faces, error) {
	conf := config.Config{
		APIKey:    "",
		APISecret: "",
		Debug:     true,
	}

	svc, err := face.New(conf)
	if err != nil {
		return nil, err
	}

	resp, err:= svc.CompareByURL(url1, url2)
	if err != nil {
		return nil, err
    }

    fmt.Printf("Compare Confidence: %f\n", resp.Confidence)
    return resp.Faces1, resp.Faces2, nil
}

Beautify

Merge Face

package main

import (
	"flag"
	"fmt"
	"io/ioutil"

	"github.com/evalphobia/go-face-plusplus/beautify"
	"github.com/evalphobia/go-face-plusplus/config"
)

func main() {
	var templateURL string
	var mergeURL string
	flag.StringVar(&templateURL, "url1", "", "set temaplte image url")
	flag.StringVar(&mergeURL, "url2", "", "set merge image url")
	flag.Parse()

	conf := config.Config{
		APIKey:    "",
		APISecret: "",
		// Debug:     true,  // big base64 response data  will show up in stdout.
	}

	svc, err := beautify.New(conf)
	if err != nil {
		panic(err)
	}

	resp, err := svc.MergeFace(beautify.MergeFaceRequest{
		TemplateURL: templateURL,
		MergeURL:    mergeURL,
	})
	if err != nil {
		panic(err)
	}

	img, err := resp.GetResultImage()
	if err != nil {
		panic(err)
	}

	fileName := "merge_face_example.jpg"
	if err := ioutil.WriteFile(fileName, img, 0644); err != nil {
		panic(err)
	}
	fmt.Printf("Success merge face! see: %s\n", fileName)
}

Environment variables

Name Description
FACEPP_API_KEY API Key of Face++.
FACEPP_API_SECRET API Secret of Face++.