<?php
require_once 'curl.func.php';
$appkey = 'your_appkey_here';//你的appkey
$url = "https://api.jisuapi.com/businesscardrecognition/recognize?appkey=$appkey";
$post = array(
'pic'=>curl_file_create(realpath('11.jpg')) //'@'.realpath('11.jpg')
);
$result = curlOpen($url, array('post'=>$post, 'isupfile'=>true));
$jsonarr = json_decode($result, true);
//exit(var_dump($jsonarr));
if($jsonarr['status'] != 0)
{
echo $jsonarr['msg'];
exit();
}
$result = $jsonarr['result'];
foreach($result as $key=>$val)
{
if(!is_array($val)) echo $key.':'.$val. '
';
else
{
foreach($val as $v)
{
echo $key.':'.$v.'
';
}
}
}
#!/usr/bin/python
# encoding:utf-8
import urllib2, json, urllib
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
# 1.名片识别
data = {}
data["appkey"] = "your_appkey_here"
register_openers()
datagen, headers = multipart_encode({"pic": open("11.jpg", "rb")})
url_values = urllib.urlencode(data)
url = "https://api.jisuapi.com/businesscardrecognition/recognize" + "?" + url_values
request = urllib2.Request(url,datagen, headers)
result = urllib2.urlopen(request)
jsonarr = json.loads(result.read())
if jsonarr["status"] != u"0":
print jsonarr["msg"]
exit()
result = jsonarr["result"]
for key in result:
if isinstance(result[key] , list) :
for v in result[key]:
print key , ":" ,v
else:
print key , ":" ,result[key]
package api.jisuapi.businesscardrecognition;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import Decoder.BASE64Encoder;
import api.util.HttpUtil;
import net.sf.json.JSONObject;
public class Recognize {
public static final String APPKEY = "your_appkey_here";// 你的appkey
public static final String URL = "https://api.jisuapi.com/businesscardrecognition/recognize";
public static final String pic = "11.jpg";// 图片地址
public static void Get() {
String result = null;
String url = URL + "?appkey=" + APPKEY;
Map param = new HashMap();
try {
param.put("pic", getBase64(pic));
result = HttpUtil.sendPost(url, param, "UTF-8");
JSONObject json = JSONObject.fromObject(result);
if (json.getInt("status") != 0) {
System.out.println(json.getString("msg"));
} else {
JSONObject resultarr = (JSONObject) json.opt("result");
Iterator itt = resultarr.keys();
while (itt.hasNext()) {
String key = itt.next().toString();
String value = resultarr.getString(key);
System.out.println(key + ":" + value);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 图片转为Base64编码格式
*
* @param imgFile
* @return
*/
public static String getBase64(String imgFile) {
InputStream inputStream = null;
byte[] data = null;
try {
inputStream = new FileInputStream(imgFile);
data = new byte[inputStream.available()];
inputStream.read(data);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
// 加密
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
}