Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FruitBin
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Guillaume Duret
FruitBin
Commits
4eff969e
Commit
4eff969e
authored
2 years ago
by
Guillaume Duret
Browse files
Options
Downloads
Patches
Plain Diff
add if in the case no category instance in the world
parent
e987bc9a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compute_features.py
+88
-86
88 additions, 86 deletions
compute_features.py
with
88 additions
and
86 deletions
compute_features.py
+
88
−
86
View file @
4eff969e
...
@@ -62,97 +62,99 @@ def process_compute(data_name, camera, Nb_camera, Nb_world, list_categories, occ
...
@@ -62,97 +62,99 @@ def process_compute(data_name, camera, Nb_camera, Nb_world, list_categories, occ
for
categories
in
list_categories
:
for
categories
in
list_categories
:
if
len
(
catergories_occ_array
[
categories
])
==
1
:
if
categories
in
catergories_occ_array
.
keys
()
:
meta
=
{}
if
len
(
catergories_occ_array
[
categories
])
==
1
:
if
categories
in
list_count_categories
.
keys
():
meta
=
{}
list_count_categories
[
categories
]
+=
1
else
:
list_count_categories
[
categories
]
=
1
meta
[
'
id_generated
'
]
=
list_count_categories
[
categories
]
if
categories
in
list_count_categories
.
keys
():
meta
[
'
id_original
'
]
=
p
list_count_categories
[
categories
]
+=
1
meta
[
'
id_category
'
]
=
catergories_label_to_id
[
categories
]
meta
[
'
id_instance
'
]
=
catergories_occ_array
[
categories
][
0
]
meta
[
'
id_dataset
'
]
=
1
meta
[
'
world
'
]
=
i
meta
[
'
camera
'
]
=
f
"
grabber_
{
j
}
"
meta
[
'
occlusion
'
]
=
occ_target
meta
[
'
Nb_instance_category
'
]
=
1
if
not
os
.
path
.
isfile
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
):
with
open
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
feeds
=
{}
feeds
[
meta
[
'
id_generated
'
]]
=
meta
f
.
write
(
json
.
dumps
(
feeds
,
indent
=
2
))
else
:
with
open
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
)
as
feedsjson
:
feeds
=
json
.
load
(
feedsjson
)
feeds
[
meta
[
'
id_generated
'
]]
=
meta
with
open
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
feeds
,
indent
=
4
))
# with open(f'{data_name}/Generated/Meta_Gen/{categories}/{categories}.json', "a") as meta_file:
# json.dump(meta, meta_file, indent=4)
for
k
in
range
(
len
(
data_3D_pose
)):
if
data_3D_pose
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
rpy
=
data_3D_pose
[
k
][
'
pose
'
][
'
rpy
'
]
rot
=
convert2
(
rpy
)
R_exp
=
transformation
@
rot
R_exp
=
np
.
array
(
R_exp
)
xyz
=
data_3D_pose
[
k
][
'
pose
'
][
'
xyz
'
]
T_exp
=
transformation
@
xyz
T_exp
=
np
.
array
(
T_exp
)
num_arr
=
np
.
c_
[
R_exp
,
T_exp
[
0
]]
np
.
save
(
f
'
{
data_name
}
/Generated/Pose_transformed/
{
categories
}
/
{
p
}
.npy
'
,
num_arr
)
# save
else
:
else
:
continue
list_count_categories
[
categories
]
=
1
if
data_Bbox_2d
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
meta
[
'
id_generated
'
]
=
list_count_categories
[
categories
]
bbox
=
bbox_2d
(
data_Bbox_2d
[
k
])
meta
[
'
id_original
'
]
=
p
np
.
savetxt
(
f
'
{
data_name
}
/Generated/Bbox/
{
categories
}
/
{
p
}
.txt
'
,
np
.
array
(
bbox
).
reshape
((
1
,
4
)))
# save
meta
[
'
id_category
'
]
=
catergories_label_to_id
[
categories
]
meta
[
'
id_instance
'
]
=
catergories_occ_array
[
categories
][
0
]
meta
[
'
id_dataset
'
]
=
1
meta
[
'
world
'
]
=
i
meta
[
'
camera
'
]
=
f
"
grabber_
{
j
}
"
meta
[
'
occlusion
'
]
=
occ_target
meta
[
'
Nb_instance_category
'
]
=
1
if
not
os
.
path
.
isfile
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
):
with
open
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
feeds
=
{}
feeds
[
meta
[
'
id_generated
'
]]
=
meta
f
.
write
(
json
.
dumps
(
feeds
,
indent
=
2
))
else
:
else
:
continue
with
open
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
)
as
feedsjson
:
feeds
=
json
.
load
(
feedsjson
)
id
=
catergories_occ_array
[
categories
][
0
]
feeds
[
meta
[
'
id_generated
'
]]
=
meta
img
=
cv2
.
imread
(
f
"
{
data_name
}
/Instance_Segmentation/
{
p
}
.png
"
,
cv2
.
IMREAD_UNCHANGED
)
# plt.imread(path)
with
open
(
f
'
{
data_name
}
/Generated/Meta_Gen/
{
categories
}
/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
feeds
,
indent
=
4
))
instance_img
=
instance
(
img
,
id
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/Instance_Mask/
{
categories
}
/
{
p
}
.png
"
,
255
*
instance_img
)
# with open(f'{data_name}/Generated/Meta_Gen/{categories}/{categories}.json', "a") as meta_file:
# json.dump(meta, meta_file, indent=4)
img
=
image
.
imread
(
f
"
{
data_name
}
/RGB/
{
p
}
.png
"
)
for
k
in
range
(
len
(
data_3D_pose
)):
np
.
set_printoptions
(
precision
=
15
)
if
data_3D_pose
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
pose
=
np
.
load
(
f
'
{
data_name
}
/Generated/Pose_transformed/
{
categories
}
/
{
p
}
.npy
'
)
rpy
=
data_3D_pose
[
k
][
'
pose
'
][
'
rpy
'
]
#print(pose)
rot
=
convert2
(
rpy
)
R_exp
=
pose
[
0
:
3
,
0
:
3
]
R_exp
=
transformation
@
rot
tVec
=
pose
[
0
:
3
,
3
]
R_exp
=
np
.
array
(
R_exp
)
#print(tVec)
xyz
=
data_3D_pose
[
k
][
'
pose
'
][
'
xyz
'
]
# camera = np.matrix([[1386.4138492513919, 0.0, 960.5],
T_exp
=
transformation
@
xyz
# [0.0, 1386.4138492513919, 540.5],
T_exp
=
np
.
array
(
T_exp
)
# [0.0, 0.0, 1.0]])
num_arr
=
np
.
c_
[
R_exp
,
T_exp
[
0
]]
np
.
save
(
f
'
{
data_name
}
/Generated/Pose_transformed/
{
categories
}
/
{
p
}
.npy
'
,
num_arr
)
# save
else
:
fps_points
=
np
.
loadtxt
(
f
'
{
data_name
}
/Generated/FPS/
{
categories
}
_fps_3d.txt
'
)
continue
# process(pcd_bbox, pcd, R_exp, tVec, camera, img)
points
=
process2
(
fps_points
,
R_exp
,
tVec
,
camera
,
img
,
vis
)
if
data_Bbox_2d
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
out
=
np
.
zeros
((
1
,
401
))
bbox
=
bbox_2d
(
data_Bbox_2d
[
k
])
np
.
savetxt
(
f
'
{
data_name
}
/Generated/Bbox/
{
categories
}
/
{
p
}
.txt
'
,
np
.
array
(
bbox
).
reshape
((
1
,
4
)))
# save
out
[
0
]
=
catergories_occ_array
[
categories
]
#obj_id #len have to be 1 !!
else
:
ind
=
1
continue
for
point
in
points
:
out
[
0
][
ind
]
=
point
[
0
][
0
]
/
img
.
shape
[
1
]
id
=
catergories_occ_array
[
categories
][
0
]
out
[
0
][
ind
+
1
]
=
point
[
0
][
1
]
/
img
.
shape
[
0
]
img
=
cv2
.
imread
(
f
"
{
data_name
}
/Instance_Segmentation/
{
p
}
.png
"
,
cv2
.
IMREAD_UNCHANGED
)
# plt.imread(path)
ind
+=
2
np
.
savetxt
(
f
'
{
data_name
}
/Generated/FPS/
{
categories
}
/
{
p
}
.txt
'
,
out
)
instance_img
=
instance
(
img
,
id
)
#print("stop")
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/Instance_Mask/
{
categories
}
/
{
p
}
.png
"
,
255
*
instance_img
)
img
=
image
.
imread
(
f
"
{
data_name
}
/RGB/
{
p
}
.png
"
)
np
.
set_printoptions
(
precision
=
15
)
pose
=
np
.
load
(
f
'
{
data_name
}
/Generated/Pose_transformed/
{
categories
}
/
{
p
}
.npy
'
)
#print(pose)
R_exp
=
pose
[
0
:
3
,
0
:
3
]
tVec
=
pose
[
0
:
3
,
3
]
#print(tVec)
# camera = np.matrix([[1386.4138492513919, 0.0, 960.5],
# [0.0, 1386.4138492513919, 540.5],
# [0.0, 0.0, 1.0]])
fps_points
=
np
.
loadtxt
(
f
'
{
data_name
}
/Generated/FPS/
{
categories
}
_fps_3d.txt
'
)
# process(pcd_bbox, pcd, R_exp, tVec, camera, img)
points
=
process2
(
fps_points
,
R_exp
,
tVec
,
camera
,
img
,
vis
)
out
=
np
.
zeros
((
1
,
401
))
out
[
0
]
=
catergories_occ_array
[
categories
]
#obj_id #len have to be 1 !!
ind
=
1
for
point
in
points
:
out
[
0
][
ind
]
=
point
[
0
][
0
]
/
img
.
shape
[
1
]
out
[
0
][
ind
+
1
]
=
point
[
0
][
1
]
/
img
.
shape
[
0
]
ind
+=
2
np
.
savetxt
(
f
'
{
data_name
}
/Generated/FPS/
{
categories
}
/
{
p
}
.txt
'
,
out
)
#print("stop")
print
(
list_count_categories
)
print
(
list_count_categories
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment