properties:添加百度人工智能车牌识别ID,KEY。pom:导入阿里巴巴json库。添加百度AI识别业务

master
Miku 1 year ago
parent fb92592140
commit 043108188c

@ -106,7 +106,11 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.73</version>
</dependency>
<!-- Excel相关 --> <!-- Excel相关 -->
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>

@ -0,0 +1,17 @@
package com.smart.module.car.util;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* AI
*/
@Data
@ConfigurationProperties(prefix = "bai-du")
public class BaiDuProperties {
private String appId;
private String apiKey;
private String accessKeySecret;
}

@ -0,0 +1,79 @@
package com.smart.module.car.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baidu.aip.ocr.AipOcr;
import com.smart.common.util.SslUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import java.util.HashMap;
/**
* AI
*/
@Component
@Configuration
@EnableConfigurationProperties({BaiDuProperties.class})
public class BaiDuUtils {
private final static Logger LOGGER = LoggerFactory.getLogger(BaiDuUtils.class);
private BaiDuProperties baiDu;
public BaiDuUtils(BaiDuProperties baiDu) {
this.baiDu = baiDu;
}
private AipOcr client;
@PostConstruct
public void init() {
try {
// 使用配置文件中的AppID、API Key和Access Key Secret创建AipOcr客户端
client = new AipOcr(baiDu.getAppId(), baiDu.getApiKey(), baiDu.getAccessKeySecret());
// 设置连接超时时间为2秒
client.setConnectionTimeoutInMillis(2000);
// 设置Socket超时时间为60秒
client.setSocketTimeoutInMillis(60000);
} catch (Exception e) {
LOGGER.error("百度智能AI初始化失败,{}", e.getMessage());
}
}
/**
*
*
*/
public String plateLicense(String image) {
try {
HashMap<String, String> options = new HashMap<>();
/**
* false
* true
*/
options.put("multi_detect", "true");
// 忽略SSL证书验证
SslUtils.ignoreSsl();
// 调用百度智能AI的车牌识别接口获取识别结果
JSONObject res = client.plateLicense(image, options);
System.out.println(res.toString());
// 从识别结果中解析出车牌号码
Object result = res.get("words_result");
JSONArray array = JSON.parseArray(result.toString());
com.alibaba.fastjson.JSONObject object = JSON.parseObject(array.get(0).toString());
Object number = object.get("number");
return number.toString();
}catch (Exception e){
e.printStackTrace();
return "";
}
}
}

@ -75,4 +75,8 @@ spring.mqtt.password = public
spring.mqtt.url = tcp://10.136.7.105:1883 spring.mqtt.url = tcp://10.136.7.105:1883
spring.mqtt.client.id = HDC-188 spring.mqtt.client.id = HDC-188
spring.mqtt.default.topic = topic spring.mqtt.default.topic = topic
spring.mqtt.default.completionTimeout = 3000 spring.mqtt.default.completionTimeout = 3000
bai-du.appId = 37831547
bai-du.apiKey = znwWRqlIGRC8wbD3VhhQtojo
bai-du.accessKeySecret = zseU22B9XbhESFXm5UYGEtEGGLVokGfW
Loading…
Cancel
Save