1

我正在尝试使用 IQ 引擎识别图片,但无法上传图片。有没有人练习使用这个 api 或任何其他来识别图片?我尝试加载位图,使用 Base64,加载图片链接,但并不总是得到 img - 此字段是必需的。最后一个代码示例是

    public void postData() {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    HttpPost httppost = new HttpPost("http://api.iqengines.com/v1.2/query/");
    MultipartEntity entity = new MultipartEntity(
            HttpMultipartMode.BROWSER_COMPATIBLE);

    File file = new File(path);

    try {
        // Add your data

        String time = myTime();
        String m = "api_key" + apiKey + "img" + file.getPath() + "json1"
                + "time_stamp" + time;

        try {
            sign = HmacSha1Signature.calculateRFC2104HMAC(m, secret);
        } catch (InvalidKeyException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SignatureException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        entity.addPart("api_key", new StringBody(apiKey));
        entity.addPart("api_sig", new StringBody(sign));
        entity.addPart("time_stamp", new StringBody(time));
        entity.addPart("json", new StringBody("1"));
        entity.addPart("img", new FileBody(file));
        httppost.setEntity(entity);

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        HttpEntity entity1 = response.getEntity();
        String result = EntityUtils.toString(entity1);
        tv.setText(result);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

谁能告诉它必须是什么,或者给出android上任何其他免费api图像识别的工作示例?

4

0 回答 0