Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
石磊
/
cihai
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ca5e1a2b
authored
Dec 07, 2017
by
徐甲彬
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
更新
1 parent
bd61a49b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
16 additions
and
9 deletions
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipDefaultClient.java
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipImageClassifyClient.java
serverside/cihai-core/src/test/java/com/dookay/cihai/core/aip/AipDefaultClientTest.java
serverside/cihai-core/src/test/java/com/dookay/cihai/core/aip/AipImageClassifyClientTest.java
serverside/cihai-core/src/test/resources/baidu.txt
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipDefaultClient.java
View file @
ca5e1a2
...
...
@@ -21,7 +21,9 @@ import com.dookay.cihai.core.aip.enums.ScanResultTypeEnum;
import
com.dookay.cihai.core.aip.model.GeneralRecognitionResult
;
import
com.dookay.cihai.core.aip.model.ImageResult
;
import
com.dookay.cihai.core.aip.model.ScanResult
;
import
com.dookay.coral.common.core.exception.ServiceException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.json.JSONException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
...
...
@@ -51,15 +53,20 @@ public class AipDefaultClient {
*/
public
ScanResult
scan
(
String
imageBase64
)
throws
JSONException
{
ScanResult
result
=
new
ScanResult
();
GeneralRecognitionResult
generalRecognitionResult
=
aipOcrClient
.
generalRecognition
(
imageBase64
,
ImageInputTypeEnum
.
BASE64
);
if
(
generalRecognitionResult
.
getWordsResultNum
()>
0
){
result
.
setType
(
ScanResultTypeEnum
.
WORDS
.
getValue
());
result
.
setWordsList
(
generalRecognitionResult
.
getWordsResult
());
}
else
{
ImageResult
imageResult
=
aipImageClassifyClient
.
getImageResult
(
imageBase64
);
if
(
StringUtils
.
isNoneBlank
(
imageResult
.
getName
())){
result
.
setType
(
ScanResultTypeEnum
.
PICTURE
.
getValue
());
ImageResult
imageResult
=
aipImageClassifyClient
.
getImageResult
(
imageBase64
);
result
.
setWordsList
(
Collections
.
singletonList
(
imageResult
.
getName
()));
}
else
{
GeneralRecognitionResult
generalRecognitionResult
=
aipOcrClient
.
generalRecognition
(
imageBase64
,
ImageInputTypeEnum
.
BASE64
);
if
(
generalRecognitionResult
.
getWordsResultNum
()>
0
){
result
.
setType
(
ScanResultTypeEnum
.
WORDS
.
getValue
());
result
.
setWordsList
(
generalRecognitionResult
.
getWordsResult
());
}
else
{
throw
new
ServiceException
(
"图片识别失败"
);
}
}
return
result
;
}
...
...
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipImageClassifyClient.java
View file @
ca5e1a2
...
...
@@ -133,7 +133,7 @@ public class AipImageClassifyClient {
List
<
ImageResult
>
imageResultList2
=
this
.
getPlantDetect
(
image
,
ImageInputTypeEnum
.
BASE64
);
imageResultList
.
addAll
(
imageResultList2
);
log
.
info
(
JSON
.
toJSONString
(
imageResultList
));
return
imageResultList
.
stream
().
filter
(
x
->
!
Objects
.
equals
(
x
.
getName
(),
"非动物"
)).
sorted
(
Comparator
.
comparing
(
ImageResult:
:
getScore
).
reversed
()).
findFirst
().
orElse
(
new
ImageResult
());
return
imageResultList
.
stream
().
filter
(
x
->
x
.
getScore
()>
0.1
).
filter
(
x
->
!
Objects
.
equals
(
x
.
getName
(),
"非动物"
)).
sorted
(
Comparator
.
comparing
(
ImageResult:
:
getScore
).
reversed
()).
findFirst
().
orElse
(
new
ImageResult
());
}
}
serverside/cihai-core/src/test/java/com/dookay/cihai/core/aip/AipDefaultClientTest.java
View file @
ca5e1a2
...
...
@@ -22,7 +22,7 @@ public class AipDefaultClientTest extends CihaiCoreApplicationTests {
@Test
public
void
scan
()
throws
Exception
{
File
file
=
ResourceUtils
.
getFile
(
"classpath:
daxiang
.txt"
);
File
file
=
ResourceUtils
.
getFile
(
"classpath:
baidu
.txt"
);
String
image
=
AipUtils
.
txt2String
(
file
);
...
...
serverside/cihai-core/src/test/java/com/dookay/cihai/core/aip/AipImageClassifyClientTest.java
View file @
ca5e1a2
...
...
@@ -22,7 +22,7 @@ public class AipImageClassifyClientTest extends CihaiCoreApplicationTests {
@Test
public
void
getImageResult
()
throws
Exception
{
File
file
=
ResourceUtils
.
getFile
(
"classpath:
mudan
.txt"
);
File
file
=
ResourceUtils
.
getFile
(
"classpath:
wenzi
.txt"
);
System
.
out
.
println
(
AipUtils
.
txt2String
(
file
));
String
image
=
AipUtils
.
txt2String
(
file
);
log
.
info
(
image
);
...
...
serverside/cihai-core/src/test/resources/baidu.txt
0 → 100644
View file @
ca5e1a2
This diff could not be displayed because it is too large.
Write
Preview
Markdown
is supported
Attach a file
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 post a comment