Go call encapsulates rainbow soft ArcFace face recognition

I. Project Introduction

As the company is a heavy user of hongsoft, for the need of work and personal interest, we are thinking of using golang to encapsulate the C++ SDK and achieve cross-platform effect by utilizing the cross-platform features of golang (of course, the premise is the platform supported by SDK).

The project has been open source to Github (portal), supported SDK version: v2.xv3.x v4.0.0

2. Preparation of compilation environment and running environment

  1. Install the GO SDK

It is recommended to install the software using the Go Module (you can change the version number according to the required version) :

go get -u -d github.com/windosx/face-engine/v4
Copy the code
  1. Installing the GCC Environment

In Linux, you can install MinGW or MINGW-W64 using the corresponding package manager. In Windows, you can install MinGW or MINGW-W64 based on the 32-bit or 64-bit system

  1. Runtime environment

Linux: Place libarcsoft_face_engine.so and libarcsoft_face_engine.so in /usr/lib64. DLL and libarcsoft_face_engine. DLL in the lib directory of the MinGW installation directory, and in the %WINDIR% or %WINDIR/System32% directory

Iii. Code structure description

├─ exercises, exercises, exercises, exercises, exercises, exercises, exercises, exercises, exercises ├─ image_util.go ├─go.mod ├─ engine.Go ├─mask.jpg ├─test.jpg examples Include is the SDK header file Image_util. go is a tool that uses golang's native API to process images. Engine. Go is a packaged SDK and two JPEG images are used for sample codeCopy the code

Four, code call example

package main

import (
    "fmt"

    . "github.com/windosx/face-engine/v4"
    "github.com/windosx/face-engine/v4/util"
)

// Get the processed image information
var imageInfo = util.GetResizedImageInfo("./mask.jpg")

func main(a) {
    / / activate the SDK
    if err := OnlineActivation("YourAppID"."YourSDKKey"."YourActiveCode"); err ! = nil { fmt.Printf("%#v\n", err)
        return
    }
    // Initialize the engine
    engine, err := NewFaceEngine(DetectModeImage,
        OrientPriority0,
        10.// 4.0 supports up to 10 facesEnableFaceDetect|EnableFaceRecognition|EnableFace3DAngle|EnableLiveness|EnableIRLiveness|EnableAge|EnableGender|EnableMa skDetect|EnableFaceLandMark)iferr ! = nil { fmt.Printf("%#v\n", err)
        return
    }
    deviceInfo, err := GetActiveDeviceInfo()
    iferr ! = nil { fmt.Printf("%#v\n", err)
    }
    fmt.Printf("Device info: %s\n", deviceInfo)
    // Check the face
    info, err := engine.DetectFaces(imageInfo.Width, imageInfo.Height, ColorFormatBGR24, imageInfo.DataUInt8)
    iferr ! = nil { fmt.Printf("%#v\n", err)
        return
    }
    // Process face data
    iferr = engine.Process(imageInfo.Width, imageInfo.Height, ColorFormatBGR24, imageInfo.DataUInt8, info, EnableAge|EnableGender|EnableFace3DAngle|EnableLiveness|EnableMaskDetect|EnableFaceLandMark); err ! = nil { fmt.Printf("%#v\n", err)
        return
    }
    // Get the age
    ageInfo, err := engine.GetAge()
    iferr ! = nil { fmt.Printf("%#v\n", err)
        return
    }
    fmt.Printf("ageInfo: %v\n", ageInfo)
    // Get mask information
    maskInfo, err := engine.GetMask()
    iferr ! = nil { fmt.Printf("%#v\n", err)
        return
    }
    fmt.Printf("Mask info: %#v\n", maskInfo)
    // Get the forehead point
    landMark, err := engine.GetFaceLandMarkInfo()
    iferr ! = nil { fmt.Printf("%#v\n", err)
        return
    }
    fmt.Printf("Forehead dot: %#v\n", landMark)
    // Destroy the engine
    iferr = engine.Destroy(); err ! = nil { fmt.Printf("%#v\n", err)
        return}}Copy the code

Five, matters needing attention

FaceFeatureExtract or FaceFeatureExtractEx method to extract face feature information, after use should call its Release() method to Release memory, to avoid memory overflow, this is due to some limitations of CGO.

More sample code

  • ArcFace+ GOCV processing video stream

(If you want to share your own examples, welcome PR)

Vii. Open source explanation

This project uses MIT protocol, if it is helpful to you, please light up the star to support it 🙂To learn more about face recognition products, please visitRainbow soft visual open platformoh

List of topics: juejin, github, smartblue, cyanosis, channing-cyan, fancy, hydrogen, condensed-night-purple, greenwillow, v-green, vue-pro, healer-readable, mk-cute, jzman, geek-black, awesome-green, qklhk-chocolate

Contribution Subject:Github.com/xitu/juejin…

theme: juejin highlight: