Identify the Gender of People in an Image using Go
With high-powered facial recognition capabilities, our Image API’s gender detection iteration will find a face within an image and provide a JSON result with a Gender Classification Confidence score & a Gender Class determination. It’ll also return the coordinates of the face it recognized during the operation. Here’s a preview of a full JSON response model:
{
"Successful": true,
"PersonWithGender": [
{
"FaceLocation": {
"LeftX": 0,
"TopY": 0,
"RightX": 0,
"BottomY": 0
},
"GenderClassificationConfidence": 0,
"GenderClass": "string"
}
],
"PeopleIdentified": 0
}
To take advantage of this API in your Go project, copy & paste code included below from our API console page. All you need to do is supply your image file & API key where indicated:
package mainimport (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"io"
"net/http"
"io/ioutil"
)func main() {url := "https://api.cloudmersive.com/image/face/detect-gender"
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))
}
If you’re short an API key, head to our website (www.cloudmersive.com) and create an account to get one. Our account tiers include a free option with a limit of 800 API calls per month.