|
基于人工智能的通用图片识别平台
开发文档
Delphi

通用识别(JSON / Base64)

        
uses
  System.SysUtils, System.Classes, System.JSON, System.NetEncoding,
  REST.Client, REST.Types;

procedure PredictBase64;
var
  Client: TRESTClient;
  Request: TRESTRequest;
  Response: TRESTResponse;
  JsonObj: TJSONObject;
  ImgStream: TFileStream;
  ImgBytes: TBytes;
  ImgBase64: string;
begin
  Client := TRESTClient.Create('http://api.ttshitu.com/predict');
  Request := TRESTRequest.Create(nil);
  Response := TRESTResponse.Create(nil);
  JsonObj := TJSONObject.Create;
  try
    Request.Client := Client;
    Request.Response := Response;
    Request.Method := rmPOST;
    Request.Timeout := 60000; // 建议超时 60 秒

    ImgStream := TFileStream.Create('C:\temp\captcha.jpg', fmOpenRead);
    try
      SetLength(ImgBytes, ImgStream.Size);
      ImgStream.ReadBuffer(ImgBytes, ImgStream.Size);
      ImgBase64 := TNetEncoding.Base64.EncodeBytesToString(ImgBytes);
    finally
      ImgStream.Free;
    end;

    JsonObj.AddPair('username', '你的账号');
    JsonObj.AddPair('password', '你的密码');
    JsonObj.AddPair('typeid', '3'); // 数英混合
    JsonObj.AddPair('image', ImgBase64);

    Request.AddBody(JsonObj.ToJSON, ctAPPLICATION_JSON);
    Request.Execute;
    Writeln(Response.Content);
    // success=true 时 data.result 为识别结果,data.id 可用于报错
  finally
    JsonObj.Free;
    Response.Free;
    Request.Free;
    Client.Free;
  end;
end;
        
    

报错脚本

        
// POST http://api.ttshitu.com/reporterror.json
// JSON: {"id":"识别成功返回的id"}
        
    

余额查询(GET)

        
// GET http://api.ttshitu.com/queryAccountInfo.json?username=你的账号&password=你的密码
// 返回 data.balance / data.consumed / data.successNum / data.failNum
        
    
 
您好,有什么需要帮助的吗?