Detect Faces in an Image in C/C++

If you have a website or application that allows users to upload photos for profile pictures, editing, or any other reason, it can help to have a system set up that automatically identifies the faces of people in the image. In addition, this technology can assist with accessibility features and metadata entry for your business. In the following tutorial, we will provide instructions on how to detect faces in an image using an API in C/C++; common file formats such as PNG and JPEG are supported.

To begin, we will install libcurl into your C/C++ project:


Next, we can perform the operation by calling the function:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "imageFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);

The response will be delivered quickly and accurately, providing you with the number of faces per quadrant, as well as the total count.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.