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 c7810746
authored
Dec 07, 2017
by
侯昆
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'master' of
http://gitlab.coralcodes.com:30000/shil0009/cihai
2 parents
a7f41c42
71b99fbe
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 @
c781074
...
@@ -21,7 +21,9 @@ import com.dookay.cihai.core.aip.enums.ScanResultTypeEnum;
...
@@ -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.GeneralRecognitionResult
;
import
com.dookay.cihai.core.aip.model.ImageResult
;
import
com.dookay.cihai.core.aip.model.ImageResult
;
import
com.dookay.cihai.core.aip.model.ScanResult
;
import
com.dookay.cihai.core.aip.model.ScanResult
;
import
com.dookay.coral.common.core.exception.ServiceException
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
...
@@ -51,15 +53,20 @@ public class AipDefaultClient {
...
@@ -51,15 +53,20 @@ public class AipDefaultClient {
*/
*/
public
ScanResult
scan
(
String
imageBase64
)
throws
JSONException
{
public
ScanResult
scan
(
String
imageBase64
)
throws
JSONException
{
ScanResult
result
=
new
ScanResult
();
ScanResult
result
=
new
ScanResult
();
GeneralRecognitionResult
generalRecognitionResult
=
aipOcrClient
.
generalRecognition
(
imageBase64
,
ImageInputTypeEnum
.
BASE64
);
ImageResult
imageResult
=
aipImageClassifyClient
.
getImageResult
(
imageBase64
);
if
(
generalRecognitionResult
.
getWordsResultNum
()>
0
){
if
(
StringUtils
.
isNoneBlank
(
imageResult
.
getName
())){
result
.
setType
(
ScanResultTypeEnum
.
WORDS
.
getValue
());
result
.
setWordsList
(
generalRecognitionResult
.
getWordsResult
());
}
else
{
result
.
setType
(
ScanResultTypeEnum
.
PICTURE
.
getValue
());
result
.
setType
(
ScanResultTypeEnum
.
PICTURE
.
getValue
());
ImageResult
imageResult
=
aipImageClassifyClient
.
getImageResult
(
imageBase64
);
result
.
setWordsList
(
Collections
.
singletonList
(
imageResult
.
getName
()));
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
;
return
result
;
}
}
...
...
serverside/cihai-core/src/main/java/com/dookay/cihai/core/aip/AipImageClassifyClient.java
View file @
c781074
...
@@ -133,7 +133,7 @@ public class AipImageClassifyClient {
...
@@ -133,7 +133,7 @@ public class AipImageClassifyClient {
List
<
ImageResult
>
imageResultList2
=
this
.
getPlantDetect
(
image
,
ImageInputTypeEnum
.
BASE64
);
List
<
ImageResult
>
imageResultList2
=
this
.
getPlantDetect
(
image
,
ImageInputTypeEnum
.
BASE64
);
imageResultList
.
addAll
(
imageResultList2
);
imageResultList
.
addAll
(
imageResultList2
);
log
.
info
(
JSON
.
toJSONString
(
imageResultList
));
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 @
c781074
...
@@ -22,7 +22,7 @@ public class AipDefaultClientTest extends CihaiCoreApplicationTests {
...
@@ -22,7 +22,7 @@ public class AipDefaultClientTest extends CihaiCoreApplicationTests {
@Test
@Test
public
void
scan
()
throws
Exception
{
public
void
scan
()
throws
Exception
{
File
file
=
ResourceUtils
.
getFile
(
"classpath:
daxiang
.txt"
);
File
file
=
ResourceUtils
.
getFile
(
"classpath:
baidu
.txt"
);
String
image
=
AipUtils
.
txt2String
(
file
);
String
image
=
AipUtils
.
txt2String
(
file
);
...
...
serverside/cihai-core/src/test/java/com/dookay/cihai/core/aip/AipImageClassifyClientTest.java
View file @
c781074
...
@@ -22,7 +22,7 @@ public class AipImageClassifyClientTest extends CihaiCoreApplicationTests {
...
@@ -22,7 +22,7 @@ public class AipImageClassifyClientTest extends CihaiCoreApplicationTests {
@Test
@Test
public
void
getImageResult
()
throws
Exception
{
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
));
System
.
out
.
println
(
AipUtils
.
txt2String
(
file
));
String
image
=
AipUtils
.
txt2String
(
file
);
String
image
=
AipUtils
.
txt2String
(
file
);
log
.
info
(
image
);
log
.
info
(
image
);
...
...
serverside/cihai-core/src/test/resources/baidu.txt
0 → 100644
View file @
c781074
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