1、最简单的是用requests,支持post/get,也支持header格式,例如:
# face++ detect face attribute (jpg/png)f = open(image_file, 'rb') # 用open,而不用imread,保留jpg格式信息 #frame = cv2.imread(imgfile)
img = base64.b64encode(f.read()) # 参数images:图像base64编码,把byte类型的img转换为str类型#采用image_file参数时,要用multipart/form-data的方式上传
#request.add_header('Content-Type', 'multipart/form-data')
2.用Popen调用curl命令,例如(face++):
def compareTtoT(face_token_1,face_token_2):
result=Popen('curl -X POST "https://api-cn.faceplusplus.com/facepp/v3/compare" -F \
"api_key={api_key}" -F \
"api_secret={api_secret}" -F \
"face_token1={face_token_1}" -F \
"face_token2={face_token_2}"'
.format(api_key=api_key,api_secret=api_secret,face_token_1=face_token_1,
face_token_2=face_token_2),shell=True,stdout=PIPE)
wait=""
result=(result.stdout.read())
return result
3、用urllib库(百度),例如:
# 识别图片中的人脸4、用调用windows DLL (科大讯飞)
from ctypes import *
import ctypes
import time
# 加载 dll
kdxf_dll = ctypes.windll.LoadLibrary("msc_x64.dll")
#设置返回值类型
kdxf_dll.QTTSSessionBegin.restype = ctypes.c_char_p
# 字符串数组的类型及变量
#str = b"engine_type = cloud, voice_name = xiaoyan, text_encoding = UTF8 "
#paramsp = ctypes.cast(str, ctypes.POINTER(ctypes.c_ubyte)) #
paramsp = create_string_buffer(b"engine_type = cloud, voice_name = xiaoyan, text_encoding = UTF8 ")
# POINTER:类型指针化,但不能用作参数
errorCode = ctypes.c_int()
errorCodep = ctypes.byref(errorCode)
print( "sessionID = ", kdxf_dll.QTTSSessionBegin(paramsp, errorCodep) )
print("params =", repr(paramsp.raw))
print("errorCode = ", errorCode)