4.17每日总结
昨天完成了图像识别的初步筛选。
今天将完成所有筛选,并且将微信截图与小票分别开,并且显示店铺。
难点小票识别检测出店铺。
下面
/*
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
class Ocr{
public String ocrtext="";
public double moneys;
public String shanghu="微信或支付宝支付";
public void OcrText(String imagelocation) throws Exception {
// 通用文字识别
String url = "https://api.textin.com/ai/service/v2/recognize";
// 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-app-id
// 示例代码中 x-ti-app-id 非真实数据
String appId = "596054ba211a5dfa32bbc1e532c058fe";
// 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-secret-code
// 示例代码中 x-ti-secret-code 非真实数据
String secretCode = "ae4ce3701207b51a4ba3f7c48e336536";
BufferedReader in = null;
DataOutputStream out = null;
String result = "";
try {
byte[] imgData = readfile(imagelocation); // image
URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)realUrl.openConnection();
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setRequestProperty("x-ti-app-id", appId);
conn.setRequestProperty("x-ti-secret-code", secretCode);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST"); // 设置请求方式
out = new DataOutputStream(conn.getOutputStream());
out.write(imgData);
out.flush();
out.close();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.out.println(result);
//查找出相应的内容
for(int i=0;i<result.length();i++) {
if(i+2<result.length()&i>2) {
if(result.charAt(i)=='t'&result.charAt(i+2)==':'&result.charAt(i-1)=='x') {
int m=i+4;
while(result.charAt(m)!='"') {
ocrtext=ocrtext+result.charAt(m);
m++;
}
}
}
}
System.out.println(ocrtext);
//查找出相应的内容
//找出钱数
String regex="\\d+(?:\\.\\d+)?";
// 使用正则表达式解析
Matcher m= Pattern.compile(regex, Pattern.MULTILINE).matcher(ocrtext);
//获取一个String 中所有的数字放到集合中
// List<String> result=new ArrayList<String>();
// while(m.find()){
// result.add(m.group());
// }
// 获取第一个数字
String wenben="";
if(m.find()){
wenben=wenben+m.group();
}
moneys=Double.parseDouble(wenben);
System.out.println(moneys);
//找出钱数
}
public byte[] readfile(String path)
{
String imgFile = path;
InputStream in = null;
byte[] data = null;
try
{
in = new FileInputStream(imgFile);
data = new byte[in.available()];
in.read(data);
in.close();
}
catch (IOException e) {
e.printStackTrace();
}
return data;
}
}
*/{"code":200,"message":"success","duration":105,"result":{"angle":0,"width":999,"lines":[{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.997,"position":[132,48,324,48,324,89,132,89],"text":"铁大校园卡"},{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.999,"position":[430,250,586,250,586,292,430,292],"text":"付款金额"},{"angle":180,"type":"text","direction":0,"handwritten":0,"score":0.992,"position":[424,406,373,403,378,338,428,341],"text":"夫"},{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.998,"position":[434,338,634,340,633,420,434,418],"text":"5.00"},{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.971,"position":[433,476,615,476,615,517,433,517],"text":"账单详情>"},{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.998,"position":[48,615,206,615,206,658,48,658],"text":"支付方式"},{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.999,"position":[238,615,357,615,357,658,238,658],"text":"零钱通"},{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.998,"position":[49,699,203,699,203,740,49,740],"text":"收单机构"},{"angle":0,"type":"text","direction":1,"handwritten":0,"score":0.999,"position":[236,696,662,696,662,743,236,743],"text":"财付通支付科技有限公司"}],"height":804},"version":"v2.0.0"}
铁大校园卡付款金额夫5.00账单详情>支付方式零钱通收单机构财付通支付科技有限公司
/*
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.IOException;
class OCRXP{
public String ocrtext="";
public double moneys;
public String shanghu;
public void Ocrxp(String imagesloction) {
// 增值税发票识别
String url = "https://api.textin.com/robot/v1.0/api/vat_invoice";
// 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-app-id
// 示例代码中 x-ti-app-id 非真实数据
String appId = "596054ba211a5dfa32bbc1e532c058fe";
// 请登录后前往 “工作台-账号设置-开发者信息” 查看 x-ti-secret-code
// 示例代码中 x-ti-secret-code 非真实数据
String secretCode = "ae4ce3701207b51a4ba3f7c48e336536";
BufferedReader in = null;
DataOutputStream out = null;
String result = "";
try {
byte[] imgData = readfile(imagesloction); // image
URL realUrl = new URL(url);
HttpURLConnection conn = (HttpURLConnection)realUrl.openConnection();
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.setRequestProperty("x-ti-app-id", appId);
conn.setRequestProperty("x-ti-secret-code", secretCode);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST"); // 设置请求方式
out = new DataOutputStream(conn.getOutputStream());
out.write(imgData);
out.flush();
out.close();
in = new BufferedReader(
new InputStreamReader(conn.getInputStream(), "UTF-8"));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.out.println(result);
//查找出相应的内容
for(int i=0;i<result.length();i++) {
if(i+2<result.length()&i>2) {
if(result.charAt(i)=='e'&result.charAt(i+2)==':'&result.charAt(i-1)=='u'&result.charAt(i-2)=='l') {
int m=i+4;
while(result.charAt(m)!='"') {
ocrtext=ocrtext+result.charAt(m);
m++;
}
}
}
}
System.out.println(ocrtext);
//查找出相应的内容
//找出钱数
String regex="\\d+(?:\\.\\d+)?";
// 使用正则表达式解析
Matcher m= Pattern.compile(regex, Pattern.MULTILINE).matcher(ocrtext);
//获取一个String 中所有的数字放到集合中
// List<String> result=new ArrayList<String>();
// while(m.find()){
// result.add(m.group());
// }
// 获取第一个数字
String wenben="";
if(m.find()){
wenben=wenben+m.group();
}
shanghu=ocrtext.replace(wenben,"");
shanghu=shanghu.replace("欢迎光临", "");
shanghu=shanghu.replace("欢迎", "");
shanghu=shanghu.replace("感谢", "");
shanghu=shanghu.replace("谢谢惠顾", "");
moneys=Double.parseDouble(wenben);
System.out.println(moneys);
System.out.println(shanghu);
moneys=Double.parseDouble(wenben);
System.out.println(moneys);
//找出钱数
}
public byte[] readfile(String path)
{
String imgFile = path;
InputStream in = null;
byte[] data = null;
try
{
in = new FileInputStream(imgFile);
data = new byte[in.available()];
in.read(data);
in.close();
}
catch (IOException e) {
e.printStackTrace();
}
return data;
}
}
*/{"message":"success","result":{"image_angle":0,"type_description":"其他","rotated_image_width":340,"rotated_image_height":542,"kind":"other","product_list":[],"item_list":[{"value":"63.00","description":"金额","position":[44,262,89,259,90,283,46,286],"key":"money","confidence":0.991},{"value":"","description":"单号","position":[],"key":"no","confidence":1},{"value":"","description":"时间","position":[],"key":"date","confidence":1},{"value":"欢迎光临新宝音像","description":"商户","position":[96,67,237,58,238,81,98,89],"key":"shop","confidence":0.6},{"value":"格调","description":"商品","position":[],"key":"sku","confidence":0.8}],"kind_description":"其他","type":"other"},"cost_time":790,"code":200}
63.00欢迎光临新宝音像格调