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
7a83f16c
Commit
7a83f16c
authored
Mar 16, 2021
by
雷紫添
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加影源ocr
parent
00d121f5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
84 additions
and
5 deletions
+84
-5
src/main/java/com/founder/controller/OcrController.java
+80
-1
src/main/java/com/founder/util/OcrFounder.java
+3
-3
src/main/resources/application.yml
+1
-1
No files found.
src/main/java/com/founder/controller/OcrController.java
View file @
7a83f16c
...
...
@@ -13,6 +13,7 @@ import org.springframework.web.multipart.MultipartFile;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.text.DateFormat
;
import
java.util.Base64
;
import
java.util.Date
;
import
sun.misc.BASE64Encoder
;
...
...
@@ -60,8 +61,46 @@ public class OcrController {
}
catch
(
IOException
e
)
{
}
String
ocrRes
=
""
;
try
{
result
=
ocrFounder
.
getOcrFounder
(
fileByte
);
ocrRes
=
ocrFounder
.
getOcrFounder
(
fileByte
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//图片文字与简要案情比对
Float
ocrCompJyaq
=
getSimilarityRatio
(
ocrRes
,
"立案"
);
//图片文字与嫌疑人比对
Float
ocrCompZbfzxry
=
getSimilarityRatio
(
ocrRes
,
"王岩"
);
//图片文字与受害人人比对
Float
ocrCompBhr
=
getSimilarityRatio
(
ocrRes
,
"大类"
);
//图片文字与受害人人比对
Float
ocrCompws
=
getSimilarityRatio
(
ocrRes
,
"立案决定书"
);
if
(
ocrCompws
<
0.000001
){
}
else
if
(
ocrCompJyaq
<
0.000001
&&
ocrCompZbfzxry
<
0.000001
&&
ocrCompBhr
<
0.000001
)
{
}
JSONObject
j
=
new
JSONObject
();
j
.
put
(
"msg"
,
ocrRes
);
Date
date1
=
new
Date
();
DateFormat
df3
=
DateFormat
.
getDateTimeInstance
();
//可以精确到时分秒
System
.
out
.
println
(
df3
.
format
(
date1
)+
"结束时间"
);
return
j
;
}
@ResponseBody
@CrossOrigin
@PostMapping
(
"/OcrFounderByte"
)
public
JSONObject
queryOcrFounderFlws
(
@RequestBody
String
fileByte
)
{
final
Base64
.
Decoder
decoder
=
Base64
.
getMimeDecoder
();
byte
[]
data
=
decoder
.
decode
(
fileByte
);
DateFormat
df2
=
DateFormat
.
getDateTimeInstance
();
//可以精确到时分秒
String
result
=
""
;
try
{
result
=
ocrFounder
.
getOcrFounder
(
data
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -72,4 +111,44 @@ public class OcrController {
System
.
out
.
println
(
df3
.
format
(
date1
)+
"结束时间"
);
return
j
;
}
public
static
float
getSimilarityRatio
(
String
str
,
String
target
)
{
int
d
[][];
// 矩阵
int
n
=
str
.
length
();
int
m
=
target
.
length
();
int
i
;
// 遍历str的
int
j
;
// 遍历target的
char
ch1
;
// str的
char
ch2
;
// target的
int
temp
;
// 记录相同字符,在某个矩阵位置值的增量,不是0就是1
if
(
n
==
0
||
m
==
0
)
{
return
0
;
}
d
=
new
int
[
n
+
1
][
m
+
1
];
for
(
i
=
0
;
i
<=
n
;
i
++)
{
// 初始化第一列
d
[
i
][
0
]
=
i
;
}
for
(
j
=
0
;
j
<=
m
;
j
++)
{
// 初始化第一行
d
[
0
][
j
]
=
j
;
}
for
(
i
=
1
;
i
<=
n
;
i
++)
{
// 遍历str
ch1
=
str
.
charAt
(
i
-
1
);
// 去匹配target
for
(
j
=
1
;
j
<=
m
;
j
++)
{
ch2
=
target
.
charAt
(
j
-
1
);
if
(
ch1
==
ch2
||
ch1
==
ch2
+
32
||
ch1
+
32
==
ch2
)
{
temp
=
0
;
}
else
{
temp
=
1
;
}
// 左边+1,上边+1, 左上角+temp取最小
d
[
i
][
j
]
=
Math
.
min
(
Math
.
min
(
d
[
i
-
1
][
j
]
+
1
,
d
[
i
][
j
-
1
]
+
1
),
d
[
i
-
1
][
j
-
1
]
+
temp
);
}
}
return
(
1
-
(
float
)
d
[
n
][
m
]
/
Math
.
max
(
str
.
length
(),
target
.
length
()))
*
100
F
;
}
}
src/main/java/com/founder/util/OcrFounder.java
View file @
7a83f16c
...
...
@@ -14,8 +14,8 @@ import java.awt.image.*;
import
java.io.*
;
@Component
public
class
OcrFounder
{
private
static
String
dllPath
=
"
D:\\ocr\\windows\\bin-x64
"
;
private
static
String
dllName
=
"
wmreader.dll"
;
//lunix 使用 libwmreader.so
private
static
String
dllPath
=
"
/opt
"
;
private
static
String
dllName
=
"
libwmreader.so"
;
//lunix 使用 libwmreader.so
private
static
String
image
=
"D:\\ocr\\images\\img2.jpg"
;
public
String
getOcrFounder
(
byte
[]
data
)
throws
Exception
{
int
code
=
OcrUtil
.
init
(
dllPath
,
dllName
);
...
...
@@ -33,7 +33,7 @@ public class OcrFounder {
System
.
out
.
println
(
"识别图像失败,错误码:"
+
code
);
System
.
exit
(
0
);
}
String
result
=
OcrUtil
.
getResult
();
String
result
=
OcrUtil
.
getResult
()
.
replaceAll
(
" "
,
""
)
;
return
result
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
...
...
src/main/resources/application.yml
View file @
7a83f16c
...
...
@@ -27,7 +27,7 @@ jslocation: E:/sysDictJs/common/dict/
ssdw
:
140000000000
server
:
port
:
8762
port
:
9061
xxcx
:
author
:
Basic 9b6c45cfcf3a4a629e3ed90fa3e5d058
orc
:
http://39.99.224.27:8866/predict/chinese_ocr_db_crnn_mobile
...
...
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