/*
package com.ssh.acm;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20170112.ImageAsyncScanRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
/**
public class PicturetoWord {
public static void main(String[] args) throws Exception {
//请替换成你自己的accessKeyId、accessKeySecret
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "LTAIzuajFMA4u8jD", "KCgSEAApd3jI9pC4xEGkq6mOh2YXc9");
DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
IAcsClient client = new DefaultAcsClient(profile);
ImageAsyncScanRequest imageAsyncScanRequest = new ImageAsyncScanRequest();
imageAsyncScanRequest.setAcceptFormat(FormatType.JSON); // 指定api返回格式
imageAsyncScanRequest.setContentType(FormatType.JSON);
imageAsyncScanRequest.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法
imageAsyncScanRequest.setEncoding("utf-8");
imageAsyncScanRequest.setRegionId("cn-shanghai");
List<Map<String, Object>> tasks = new ArrayList<Map<String, Object>>();
Map<String, Object> task1 = new LinkedHashMap<String, Object>();
task1.put("dataId", UUID.randomUUID().toString());
task1.put("url", "https://localhost:8888/SSH/images/lixiang@163.com/111.jpg");
task1.put("time", new Date());
tasks.add(task1);
JSONObject data = new JSONObject();
/**
* porn: 色情
* terrorism: 暴恐
* qrcode: 二维码
* ad: 图片广告
* ocr: 文字识别
*/
data.put("scenes", Arrays.asList("ocr"));
data.put("tasks", tasks);
imageAsyncScanRequest.setContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
/**
* 请务必设置超时时间
*/
imageAsyncScanRequest.setConnectTimeout(3000);
imageAsyncScanRequest.setReadTimeout(6000);
try {
HttpResponse httpResponse = client.doAction(imageAsyncScanRequest);
if(httpResponse.isSuccess()){
JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getContent(), "UTF-8"));
System.out.println(JSON.toJSONString(scrResponse, true));
if (200 == scrResponse.getInteger("code")) {
JSONArray taskResults = scrResponse.getJSONArray("data");
for (Object taskResult : taskResults) {
if(200 == ((JSONObject)taskResult).getInteger("code")){
String taskId = ((JSONObject)taskResult).getString("taskId");
// 将taskId 保存下来,间隔一段时间来轮询结果, 参照ImageAsyncScanResultsRequest
System.out.println("args = [" + taskId + "]");
}else{
System.out.println("task process fail:" + ((JSONObject)taskResult).getInteger("code"));
}
}
} else {
System.out.println("detect not success. code:" + scrResponse.getInteger("code"));
}
}else{
System.out.println("response not success. status:" + httpResponse.getStatus());
}
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
https://localhost:8888
这个地址是你本地的地址,如果是测试服务一般是 HTTP 协议,可以尝试将 https
改成http
,或者换成图片实际的地址。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。