车牌识别

前置知识

#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();
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值