Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xzxt-api-report
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
雷紫添
xzxt-api-report
Commits
5e6bf6f1
Commit
5e6bf6f1
authored
Feb 04, 2021
by
雷紫添
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加缺失的字段
parent
d123d1a1
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
5 deletions
+42
-5
src/main/java/com/founder/controller/OcrController.java
+9
-0
src/main/java/com/founder/service/impl/OcrServiceImpl.java
+28
-3
src/main/resources/application.yml
+3
-1
src/main/resources/static/ocr.html
+2
-1
No files found.
src/main/java/com/founder/controller/OcrController.java
View file @
5e6bf6f1
...
...
@@ -11,6 +11,9 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.text.DateFormat
;
import
java.util.Date
;
import
sun.misc.BASE64Encoder
;
@RestController
@RequestMapping
(
value
=
"/ocr"
,
produces
=
"application/json; charset=utf-8"
)
...
...
@@ -20,6 +23,9 @@ public class OcrController {
@ResponseBody
@PostMapping
(
"/InvoiceOcr"
)
public
JSONObject
query
(
HttpServletRequest
request
,
MultipartFile
file
)
{
DateFormat
df2
=
DateFormat
.
getDateTimeInstance
();
//可以精确到时分秒
Date
date
=
new
Date
();
System
.
out
.
println
(
df2
.
format
(
date
)+
"开始时间"
);
byte
[]
fileByte
=
null
;
try
{
fileByte
=
file
.
getBytes
();
...
...
@@ -31,6 +37,9 @@ public class OcrController {
String
voiceBase64
=
encoder
.
encode
(
fileByte
);
JSONObject
j
=
new
JSONObject
();
j
.
put
(
"msg"
,
ocrjService
.
getOcr
(
voiceBase64
));
Date
date1
=
new
Date
();
DateFormat
df3
=
DateFormat
.
getDateTimeInstance
();
//可以精确到时分秒
System
.
out
.
println
(
df3
.
format
(
date1
)+
"结束时间"
);
return
j
;
}
...
...
src/main/java/com/founder/service/impl/OcrServiceImpl.java
View file @
5e6bf6f1
...
...
@@ -8,7 +8,17 @@ import com.founder.util.InvoiceOcr;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.methods.HttpPost
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.text.DateFormat
;
import
java.util.Date
;
import
java.util.Map
;
/**
* Created by wangxing on 2019/8/14.
...
...
@@ -20,16 +30,31 @@ public class OcrServiceImpl implements OcrService {
@Override
public
String
getOcr
(
String
encoder
)
{
InvoiceOcr
ac
=
new
InvoiceOcr
(
orc
);
/*
InvoiceOcr ac = new InvoiceOcr(orc);
JSONArray arry = new JSONArray();
JSONObject j = new JSONObject();
arry.add(encoder);
j.put("images",arry);
String
result
=
ac
.
post
(
j
.
toJSONString
());
String result = ac.post(j.toJSONString());*/
String
result
=
getRestTemplate
(
encoder
);
System
.
out
.
println
(
result
);
return
result
;
}
public
String
getRestTemplate
(
String
encoder
){
HttpHeaders
headers
=
new
HttpHeaders
();
//设置请求头格式
//Set the request header format
headers
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
//构建请求参数
//Build request parameters
MultiValueMap
<
String
,
String
>
map
=
new
LinkedMultiValueMap
<
String
,
String
>();
map
.
add
(
"images"
,
encoder
);
HttpEntity
<
MultiValueMap
<
String
,
String
>>
request
=
new
HttpEntity
<
MultiValueMap
<
String
,
String
>>(
map
,
headers
);
RestTemplate
restTemplate
=
new
RestTemplate
();
Map
json
=
restTemplate
.
postForEntity
(
orc
,
request
,
Map
.
class
).
getBody
();
String
sss
=
JSONObject
.
toJSONString
(
json
.
get
(
"results"
));
return
sss
;
}
//接口地址
...
...
src/main/resources/application.yml
View file @
5e6bf6f1
...
...
@@ -27,4 +27,6 @@ server:
port
:
9061
xxcx
:
author
:
Basic 9b6c45cfcf3a4a629e3ed90fa3e5d058
orc
:
http://39.99.224.27:8866/predict/chinese_ocr_db_crnn_mobile
orc
:
http://47.92.223.200:8866/predict/ocr_system
ce
:
http://39.99.224.27:8866/predict/chinese_ocr_db_crnn_mobile
ce1
:
http://39.99.224.27:8866/predict/ocr_system
src/main/resources/static/ocr.html
View file @
5e6bf6f1
...
...
@@ -47,6 +47,7 @@
var
uploadInst
=
upload
.
render
({
elem
:
'#test1'
,
url
:
'/ocr/InvoiceOcr'
//改成您自己的上传接口
,
size
:
1024
,
before
:
function
(
obj
){
//预读本地文件示例,不支持ie8
...
...
@@ -63,7 +64,7 @@
//上传成功
$
(
'#demoText2'
).
html
(
res
.
msg
);
alert
(
res
.
msg
);
}
,
error
:
function
(){
//演示失败状态,并实现重传
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment