Detect & Find Faces and Landmarks (Eyes, Nose & Mouth) in an Image using Go

Our facial recognition API targets key features of the human face and returns each identified feature with x/y coordinates indicating its location within the image. For example, the tag for an eyebrow identified on the right side of a face would return as such:

"RightEyebrow": [
{
"X": 0,
"Y": 0

With code samples below, you can easily take advantage of this API for your Go project. Copy and paste, including your file & API key where indicated, and await your results:

package mainimport (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)
func main() {url := "https://api.cloudmersive.com/image/face/locate-with-landmarks"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, errFile1 := os.Open("/path/to/file")
defer file.Close()
part1,
errFile1 := writer.CreateFormFile("imageFile",filepath.Base("/path/to/file"))
_, errFile1 = io.Copy(part1, file)
if errFile1 != nil {
fmt.Println(errFile1)
return
}
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "multipart/form-data")
req.Header.Add("Apikey", "YOUR-API-KEY-HERE")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}

To get your Cloudmersive API key, head to our website (www.cloudmersive.com) and create an account. There are several account options to choose from, including a free-tier option with a limit of 800 API calls per month.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store