#include <stdio.h>
#include <curl/curl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
typedef unsigned int bool;
#define true 1
#define false 0
char buf[1024] = {'\0'};
size_t readData( void *ptr, size_t size,size_t nmemb, void *stream)
{
strncpy(buf,ptr,1024);
// printf("==================get data================\n");
printf("%s\n",buf );
}
char* getPicBase64FromFile(char *filePath)
{
char *bufPic;
char cmd[128] = {'\0'};
sprintf(cmd,"base64 %s > tmpFile",filePath);
system(cmd);
int fd = open("./tmpFile",O_RDWR);
int fileLen = lseek(fd,0,SEEK_END)+2;
lseek(fd,0,SEEK_SET);
bufPic = (char *)malloc(fileLen);
memset(bufPic,'\0',fileLen);
read(fd,bufPic,fileLen);
close(fd);
system("rm -f tmpFile");
return bufPic;
}
bool postUrl()
{
CURL *curl;
CURLcode res;
char *postString;
char *key = "5Fr48MNMbvTMDbjhD4EtPZ";
char *secret = "f6b80478f43148c9bf4de0c9b9ec84be";
int typeId = 19;
char *format = "xml";
char *bufPic = getPicBase64FromFile("car.jpg");
int len = strlen(key)+strlen(secret)+strlen(bufPic)+124;
postString = (char *)malloc(len);
memset(postString,'\0',len);
sprintf(postString,"&img=%s&key=%s&secret=%s&typeId=%d&format=%s",bufPic,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/recogliu.do"); // 指定url
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, readData);
res = curl_easy_perform(curl);
printf("Return:%d\n",res);
curl_easy_cleanup(curl);
}
return true;
}
int main(void)
{
postUrl();
}
车牌识别
最新推荐文章于 2023-07-20 17:24:15 发布