本文主要是介绍基于翔云平台实现人脸识别功能,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
base64 Linux提供的图片的BCM转base64流的工具
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>#define true 1
#define false 0typedef unsigned int bool;size_t readData( void *ptr, size_t size, size_t nmemb, void *stream)
{char buf[1024] = {'\0'};strcpy(buf, ptr);if (strstr(ptr, "是")) {printf("yes\n");} else {printf("no\n");}
}char* getImg(char *img)
{int fd;char *buf;char cmd[36] = {'\0'};sprintf(cmd, "base64 %s > imgFife", img);system(cmd);fd = open("imgFife", O_RDONLY);int fileLen = lseek(fd, 0, SEEK_END);lseek(fd, 0, SEEK_SET);buf = (char*)malloc(fileLen + 5);read(fd, buf, fileLen + 5);return buf;
}bool postUrl()
{CURL *curl;CURLcode res;char *postString;char *key = " "; //自行补充char *secret = " "; //自行补充int typeId = 21;char *format = "xml";system("raspistill -t 200 -tl 3000 -o img2.jpg"); //拍照char *img1 = getImg("img1.jpg");char *img2 = getImg("img2.jpg");system("rm img2.jpg");postString = (char*)malloc(sizeof(typeId) + strlen(key) + strlen(secret) + strlen(format) + strlen(img1) + strlen(img2));memset(postString, '\0', strlen(postString));sprintf(postString, "&img1=%s&img&img2=%s&key=%s&secret=%s&typeId=%d&format=%s",img1, img2, key, secret, typeId, format);curl = curl_easy_init();if (curl){curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postString); // 指定post内容curl_easy_setopt(curl, CURLOPT_URL, "https://netocr.com/api/faceliu.do"); // 指定urlcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, readData); //回调函数res = curl_easy_perform(curl);curl_easy_cleanup(curl);}return true;
}int main(void)
{postUrl();
}
这篇关于基于翔云平台实现人脸识别功能的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!