Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
DA-Platform
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
文档服务地址:
http://47.92.0.57:3000/
周报索引地址:
http://47.92.0.57:3000/s/NruNXRYmV
Open sidebar
Berlin
DA-Platform
Commits
323dd92f
Commit
323dd92f
authored
Jun 22, 2020
by
convivae
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
image
parent
538cff80
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
113 additions
and
89 deletions
+113
-89
Image.py
DAPlatform/Dao/Image.py
+113
-89
No files found.
DAPlatform/Dao/Image.py
View file @
323dd92f
# from peewee import *
import
traceback
import
traceback
import
json
import
json
from
flask_mongoengine
import
MongoEngine
from
flask_mongoengine
import
MongoEngine
...
@@ -19,7 +18,7 @@ class Result:
...
@@ -19,7 +18,7 @@ class Result:
# 像素点
# 像素点
class
Point
(
db
.
EmbeddedDocument
):
class
Point
(
db
.
EmbeddedDocument
):
pointId
=
db
.
IntField
(
required
=
True
,
unique
=
True
)
pointId
=
db
.
IntField
(
required
=
True
)
X
=
db
.
FloatField
(
required
=
True
)
X
=
db
.
FloatField
(
required
=
True
)
Y
=
db
.
FloatField
(
required
=
True
)
Y
=
db
.
FloatField
(
required
=
True
)
...
@@ -31,7 +30,7 @@ class Point(db.EmbeddedDocument):
...
@@ -31,7 +30,7 @@ class Point(db.EmbeddedDocument):
# 标签
# 标签
class
Label
(
db
.
EmbeddedDocument
):
class
Label
(
db
.
EmbeddedDocument
):
labelId
=
db
.
IntField
(
required
=
True
,
unique
=
True
)
labelId
=
db
.
IntField
(
required
=
True
)
labelName
=
db
.
StringField
(
required
=
True
)
labelName
=
db
.
StringField
(
required
=
True
)
pointList
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
Point
))
pointList
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
Point
))
...
@@ -96,30 +95,9 @@ def create_images(image_list):
...
@@ -96,30 +95,9 @@ def create_images(image_list):
return
res
return
res
# 获取图片
def
getImage
(
relation_list
):
try
:
image_list
=
Image
.
objects
(
relationId__in
=
relation_list
)
data
=
[
json
.
dumps
(
image
.
to_json
(),
ensure_ascii
=
False
)
for
image
in
image_list
]
return
Result
(
1
,
len
(
image_list
),
data
)
except
Exception
as
e
:
traceback
.
print_exc
()
return
Result
(
0
,
repr
(
e
),
{})
# 保存图片标注结果
def
saveImage
(
image_list
):
try
:
images
=
create_images
(
image_list
)
return
Result
(
1
,
len
(
images
),
{})
except
Exception
as
e
:
traceback
.
print_exc
()
return
Result
(
0
,
repr
(
e
),
{})
# 图层实体
# 图层实体
class
Layer
I
ntity
(
db
.
EmbeddedDocument
):
class
Layer
E
ntity
(
db
.
EmbeddedDocument
):
layerId
=
db
.
IntField
(
unique
=
True
)
layerId
=
db
.
IntField
(
required
=
True
)
layerName
=
db
.
StringField
(
required
=
True
)
layerName
=
db
.
StringField
(
required
=
True
)
layerUrl
=
db
.
StringField
(
required
=
True
)
layerUrl
=
db
.
StringField
(
required
=
True
)
...
@@ -131,19 +109,46 @@ class LayerIntity(db.EmbeddedDocument):
...
@@ -131,19 +109,46 @@ class LayerIntity(db.EmbeddedDocument):
# 图层标注的数据库
# 图层标注的数据库
class
Layer
(
db
.
Document
):
class
Layer
(
db
.
Document
):
relationId
=
db
.
IntField
(
required
=
True
)
relationId
=
db
.
IntField
(
required
=
True
,
unique
=
True
)
layer
List
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
LayerI
ntity
))
layer
EntityList
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
LayerE
ntity
))
labelList
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
Label
))
labelList
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
Label
))
def
to_json
(
self
):
def
to_json
(
self
):
return
{
"relationId"
:
self
.
relationId
,
return
{
"relationId"
:
self
.
relationId
,
"layer
List"
:
[
i
.
to_json
for
i
in
self
.
layer
List
],
"layer
EntityList"
:
[
i
.
to_json
()
for
i
in
self
.
layerEntity
List
],
"labelList"
:
[
i
.
to_json
for
i
in
self
.
labelList
]
"labelList"
:
[
i
.
to_json
()
for
i
in
self
.
labelList
]
}
}
# 根据json列表创建对象列表
def
create_layer_entities
(
layer_entity_list
):
res
=
[]
for
i
in
layer_entity_list
:
layer_entity
=
LayerEntity
(
layerId
=
i
[
'layerId'
],
layerName
=
i
[
'layerName'
],
layerUrl
=
i
[
'layerUrl'
]
)
res
.
append
(
layer_entity
)
return
res
# 根据json列表创建对象列表
def
create_layers
(
layer_list
):
res
=
[]
for
i
in
layer_list
:
layer
=
Layer
(
relationId
=
i
[
'relationId'
],
layerEntityList
=
create_layer_entities
(
i
[
'layerEntityList'
]),
labelList
=
create_labels
(
i
[
'labelList'
])
)
layer
.
save
()
res
.
append
(
layer
)
return
res
# 地标实体
# 地标实体
class
Landmark
I
ntity
(
db
.
EmbeddedDocument
):
class
Landmark
E
ntity
(
db
.
EmbeddedDocument
):
landmarkId
=
db
.
IntField
(
required
=
True
)
landmarkId
=
db
.
IntField
(
required
=
True
)
landmarkName
=
db
.
StringField
()
landmarkName
=
db
.
StringField
()
X
=
db
.
FloatField
(
required
=
True
)
X
=
db
.
FloatField
(
required
=
True
)
...
@@ -158,67 +163,86 @@ class LandmarkIntity(db.EmbeddedDocument):
...
@@ -158,67 +163,86 @@ class LandmarkIntity(db.EmbeddedDocument):
# 地标存储表
# 地标存储表
class
Landmark
(
db
.
Document
):
class
Landmark
(
db
.
Document
):
relationId
=
db
.
IntField
(
required
=
True
)
relationId
=
db
.
IntField
(
required
=
True
,
unique
=
True
)
layer
List
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
LayerI
ntity
))
layer
EntityList
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
LayerE
ntity
))
landmark
List
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
LandmarkI
ntity
))
landmark
EntityList
=
db
.
ListField
(
db
.
EmbeddedDocumentField
(
LandmarkE
ntity
))
def
to_json
(
self
):
def
to_json
(
self
):
return
{
"relationId"
:
self
.
relationId
,
return
{
"relationId"
:
self
.
relationId
,
"layer
List"
:
[
i
.
to_json
for
i
in
self
.
layer
List
],
"layer
EntityList"
:
[
i
.
to_json
()
for
i
in
self
.
layerEntity
List
],
"landmark
List"
:
[
i
.
to_json
for
i
in
self
.
landmark
List
]
"landmark
EntityList"
:
[
i
.
to_json
()
for
i
in
self
.
landmarkEntity
List
]
}
}
# def getLayer(relation_list):
# 根据json列表创建对象列表
# try:
def
create_landmark_entities
(
landmark_entity_list
):
# fragment_list = [Fragment.get(Fragment.relationId == r_id) for r_id in relation_list]
res
=
[]
# data = [fragment.to_json for fragment in fragment_list]
for
i
in
landmark_entity_list
:
# return Result(1, len(fragment_list), data)
landmark_entity
=
LandmarkEntity
(
# except:
landmarkId
=
i
[
'landmarkId'
],
# return Result(0, "some relation ids don't exist", {})
landmarkName
=
i
[
'landmarkName'
],
#
X
=
i
[
'X'
],
#
Y
=
i
[
'Y'
]
# def saveLayer(fragment_list, landmark_list):
)
# try:
res
.
append
(
landmark_entity
)
# for item in fragment_list:
return
res
# fragment = Fragment(relationId=item['relationId'],
# layerList=item['layerList'],
# labelList=item['labelList']
# 根据json列表创建对象列表
# )
def
create_landmarks
(
landmark_list
):
# fragment.save()
res
=
[]
#
for
i
in
landmark_list
:
# for item in landmark_list:
landmark
=
Landmark
(
# landmark = Landmark(relationId=item['relationId'],
relationId
=
i
[
'relationId'
],
# layerList=item['layerList'],
layerEntityList
=
create_layer_entities
(
i
[
'layerEntityList'
]),
# landmark_list=item['landmark_list']
landmarkEntityList
=
create_landmark_entities
(
i
[
'landmarkEntityList'
])
# )
)
# landmark.save()
res
.
append
(
landmark
)
#
landmark
.
save
()
# return Result(1, len(fragment_list), {})
return
res
# except:
# return Result(0, "error", {})
# 获取图片
# meta = {"imageList": [
def
getImage
(
relation_list
):
# {"relationId": 123,
try
:
# "imageUrl": "tom@qq.com",
image_list
=
Image
.
objects
(
relationId__in
=
relation_list
)
# "labelList": [{
data
=
[
json
.
dumps
(
image
.
to_json
(),
ensure_ascii
=
False
)
for
image
in
image_list
]
# "labelId": 123,
return
Result
(
1
,
len
(
image_list
),
{
"imageList"
:
data
})
# "labelName": "标注",
except
Exception
as
e
:
# "pointList": [{
traceback
.
print_exc
()
# "pointId": 14,
return
Result
(
0
,
repr
(
e
),
{})
# "X": 234,
# "Y": 14.25
# }]
# 保存图片标注结果
# }]},
def
saveImage
(
image_list
):
# {"relationId": 156,
try
:
# "imageUrl": "jerry@qq.com",
images
=
create_images
(
image_list
)
# "labelList": [{
return
Result
(
1
,
len
(
images
),
{})
# "labelId": 13,
except
Exception
as
e
:
# "labelName": "标注",
traceback
.
print_exc
()
# "pointList": [{
return
Result
(
0
,
repr
(
e
),
{})
# "pointId": 145,
# "X": 2.834,
# "Y": 145
# 获取图层
# }]
def
getLayer
(
relation_list
):
# }]}
try
:
# ]}
layer_list
=
Layer
.
objects
(
relationId__in
=
relation_list
)
landmark_list
=
Landmark
.
objects
(
relationId__in
=
relation_list
)
layer_data
=
[
json
.
dumps
(
layer
.
to_json
(),
ensure_ascii
=
False
)
for
layer
in
layer_list
]
landmark_data
=
[
json
.
dumps
(
landmark
.
to_json
(),
ensure_ascii
=
False
)
for
landmark
in
landmark_list
]
return
Result
(
1
,
[
"layers:"
,
len
(
layer_data
),
"landmarks:"
,
len
(
landmark_data
)],
{
"layerList"
:
layer_data
,
"landmarkList"
:
landmark_data
})
except
Exception
as
e
:
traceback
.
print_exc
()
return
Result
(
0
,
repr
(
e
),
{})
# 保存图层标注结果
def
saveLayer
(
layer_list
,
landmark_list
):
try
:
layers
=
create_layers
(
layer_list
)
landmarks
=
create_landmarks
(
landmark_list
)
return
Result
(
1
,
[
"layers:"
,
len
(
layers
),
"landmarks:"
,
len
(
landmarks
)],
{})
except
Exception
as
e
:
traceback
.
print_exc
()
return
Result
(
0
,
repr
(
e
),
{})
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