Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2021-1-capstone-design2
/
2016104095
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
강세희
2021-05-06 21:54:09 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f7821189af143286dd52cf8c0ec86ae581883729
f7821189
1 parent
ca9cb520
[UPDATE] 프레임 당 합칠 두 객체 선정
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
6 deletions
codes/Project/project.py
codes/Project/project.py
View file @
f782118
import
time
import
math
import
cv2
import
numpy
as
np
from
copy
import
deepcopy
from
model.yolo_model
import
YOLO
class
Point2D
:
...
...
@@ -56,17 +56,25 @@ if __name__ == '__main__':
x
,
y
,
w
,
h
=
box
name
=
all_classes
[
cl
]
size
=
int
(
w
*
h
)
if
size
<=
4000
:
# 사이즈가 너무 작아 썸네일로 적합하지 않은 경우
continue
if
x
<=
0
or
x
+
w
>=
image
.
shape
[
1
]
or
y
<=
0
or
y
+
h
>=
image
.
shape
[
0
]:
# 검출된 객체가 프레임 밖으로 나간 경우
continue
# 얼마나 가운데인지 확인하는 알고리즘
object
=
Point2D
(
width
=
x
+
h
/
2
,
height
=
y
+
w
/
2
)
object
=
Point2D
(
width
=
x
+
w
/
2
,
height
=
y
+
h
/
2
)
a
=
image
.
shape
[
1
]
/
2
-
object
.
width
b
=
image
.
shape
[
0
]
/
2
-
object
.
height
coordinatevalue
=
int
(
math
.
sqrt
((
a
*
a
)
+
(
b
*
b
)))
top
=
max
(
0
,
np
.
floor
(
x
+
0.5
)
.
astype
(
int
))
left
=
max
(
0
,
np
.
floor
(
y
+
0.5
)
.
astype
(
int
))
right
=
min
(
image
.
shape
[
1
],
np
.
floor
(
x
+
w
+
0.5
)
.
astype
(
int
))
bottom
=
min
(
image
.
shape
[
0
],
np
.
floor
(
y
+
h
+
0.5
)
.
astype
(
int
))
# 객체 정보 및 계산 값 저장
detectionInfo
.
append
([
i
,
name
,
size
,
coordinatevalue
,
int
(
x
),
int
(
y
),
int
(
w
),
int
(
h
)
])
detectionInfo
.
append
([
i
,
name
,
size
,
coordinatevalue
,
top
,
left
,
right
,
bottom
])
f
=
open
(
"detectionInfo.txt"
,
'w'
)
for
i
in
range
(
len
(
detectionInfo
)):
...
...
@@ -117,10 +125,41 @@ if __name__ == '__main__':
# 계획2 : 프레임별로 나온 객체 겹치는 부분 제외하고 넓이 구해 큰거 Indexlist에 넣기
# 모든 프레임에 적용하지 않고 여러 객체가 나온 프레임 선정, 프레임 인덱스 저장하는 best 딕셔너리
best
=
list
(
list
(
zip
(
*
detectionInfo
))[
0
])
bestList
=
{}
for
i
in
range
(
len
(
detectionInfo
)):
if
best
.
count
(
detectionInfo
[
i
][
0
])
==
2
:
if
detectionInfo
[
i
][
0
]
in
bestList
:
bestList
[
detectionInfo
[
i
][
0
]]
.
append
(
detectionInfo
[
i
][
1
:])
else
:
bestList
[
detectionInfo
[
i
][
0
]]
=
[
detectionInfo
[
i
][
1
:]]
elif
best
.
count
(
best
[
i
])
>
2
:
if
best
[
i
]
in
bestList
:
bestList
[
best
[
i
]]
.
append
([
i
,
detectionInfo
[
i
][
3
]])
else
:
bestList
[
best
[
i
]]
=
[[
i
,
detectionInfo
[
i
][
3
]]]
for
key
,
value
in
bestList
.
items
():
if
len
(
value
[
0
])
==
2
:
tmpValue
=
deepcopy
(
value
)
first
,
second
=
0
,
0
indexList
=
list
(
list
(
zip
(
*
tmpValue
))[
0
])
coordiList
=
list
(
list
(
zip
(
*
tmpValue
))[
1
])
minCordi
=
coordiList
.
index
(
min
(
coordiList
))
first
=
indexList
[
minCordi
]
coordiList
[
minCordi
]
=
99999
minCordi
=
coordiList
.
index
(
min
(
coordiList
))
second
=
indexList
[
minCordi
]
print
(
first
,
second
)
bestList
[
key
]
=
[
detectionInfo
[
first
][
1
:],
detectionInfo
[
second
][
1
:]]
# beOverlap 에서 선정된 두 객체의 top, left, right, bottom 값 비교하여 두 객체의 합산 size 계산, 이를 overlapped에 저장
# 이 때, value는 항상 두 가지 값만을 가짐
#for key, value in bestList.items():
# a_top, a_left, a_right, a_bottom = value[0][4:]
# b_top, b_left, b_right, b_bottom = value[1][4:]
# 모든 프레임에 적용하지 않고 베스트 컷 10컷 정도 선정
# 선정된 프레임 내에서 일정 크기 이상의 객체 중, 겹치는 객체 선정해서 하나의 검출물로 처리
# 정리된 검출 리스트 output3 에 출력
...
...
Please
register
or
login
to post a comment