Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
alpha
sun
Commits
b939fca8
Commit
b939fca8
authored
Feb 14, 2019
by
张永
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
注释扫脸逻辑
parent
b329f630
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
23 deletions
+23
-23
user.py
api/user.py
+23
-23
No files found.
api/user.py
View file @
b939fca8
...
...
@@ -113,29 +113,29 @@ class UserImage(APIView):
user_id
=
user_id
,
image_id
=
image_id
)
.
unwrap
()
if
resp
:
return
self
.
write_success
(
data
=
''
,
message
=
'操作成功'
)
try
:
data
=
self
.
rpc
[
'saber/face/detect'
](
url
=
image_url
)
.
unwrap
()
except
Exception
as
e
:
error_logger
.
error
(
u'分析人脸失败:
%
s'
,
e
)
return
self
.
write_fail
(
code
=-
1
,
message
=
'分析人脸失败'
)
faces
=
[{
"point"
:
[
item
[
"rect"
][
"left"
],
item
[
"rect"
][
"top"
],
item
[
"rect"
][
"right"
]
-
item
[
"rect"
][
"left"
],
item
[
"rect"
][
"bottom"
]
-
item
[
"rect"
][
"top"
]]}
for
item
in
data
.
get
(
"faces"
,
[])]
if
faces
:
point
=
faces
[
0
]
.
get
(
'point'
,
[])
else
:
return
self
.
write_fail
(
code
=-
1
,
message
=
'获取人脸失败'
)
file_path
=
download_img_func
(
image_url
,
user_id
,
suffix
=
"png"
)
images
=
tailor_image
(
file_path
,
[
point
])
header_pic_path
=
images
[
0
]
with
open
(
header_pic_path
,
'rb'
)
as
f
:
image_url
=
upload_with_short
(
f
,
img_type
=
IMG_TYPE
.
USEREXTRA
)[
0
]
# 目前不需要 从图片中切出人脸
#
try:
#
data = self.rpc['saber/face/detect'](url=image_url).unwrap()
#
except Exception as e:
#
error_logger.error(u'分析人脸失败:%s', e)
#
return self.write_fail(code=-1, message='分析人脸失败')
#
faces = [{
#
"point": [
#
item["rect"]["left"],
#
item["rect"]["top"],
#
item["rect"]["right"]-item["rect"]["left"],
#
item["rect"]["bottom"]-item["rect"]["top"]]} for item in data.get("faces", [])]
#
if faces:
#
point = faces[0].get('point', [])
#
else:
#
return self.write_fail(code=-1, message='获取人脸失败')
#
file_path = download_img_func(image_url, user_id, suffix="png")
#
images = tailor_image(file_path, [point])
#
header_pic_path = images[0]
#
with open(header_pic_path, 'rb') as f:
#
image_url = upload_with_short(f, img_type=IMG_TYPE.USEREXTRA)[0]
try
:
result
=
self
.
rpc
[
'venus/sun/user/create_update_image'
](
image_url
=
image_url
,
user_id
=
user_id
,
image_id
=
image_id
)
.
unwrap
()
...
...
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