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
af446c7b
Commit
af446c7b
authored
2 years ago
by
Guillaume Duret
Browse files
Options
Downloads
Patches
Plain Diff
cleaning
parent
0382a646
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compute_features.py
+5
-42
5 additions, 42 deletions
compute_features.py
main.py
+2
-54
2 additions, 54 deletions
main.py
with
7 additions
and
96 deletions
compute_features.py
+
5
−
42
View file @
af446c7b
import
math
import
numpy
as
np
import
numpy
as
np
import
json
import
json
from
utils
import
compute_categories_id
,
compute_id_good_occ
from
utils
import
compute_categories_id
,
compute_id_good_occ
...
@@ -51,7 +48,6 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
...
@@ -51,7 +48,6 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
with
open
(
f
'
{
data_name
}
/Generated/Count_
{
p
-
1
}
.json
'
)
as
f
:
with
open
(
f
'
{
data_name
}
/Generated/Count_
{
p
-
1
}
.json
'
)
as
f
:
list_count_categories
=
json
.
load
(
f
)
list_count_categories
=
json
.
load
(
f
)
for
categories
in
list_categories
:
for
categories
in
list_categories
:
if
categories
in
catergories_occ_array
.
keys
():
if
categories
in
catergories_occ_array
.
keys
():
if
len
(
catergories_occ_array
[
categories
])
==
1
:
if
len
(
catergories_occ_array
[
categories
])
==
1
:
...
@@ -73,7 +69,6 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
...
@@ -73,7 +69,6 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
meta
[
'
occlusion
'
]
=
occ_target
meta
[
'
occlusion
'
]
=
occ_target
meta
[
'
Nb_instance_category
'
]
=
1
meta
[
'
Nb_instance_category
'
]
=
1
if
not
os
.
path
.
isfile
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Meta_Gen/
{
categories
}
.json
'
):
if
not
os
.
path
.
isfile
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Meta_Gen/
{
categories
}
.json
'
):
with
open
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Meta_Gen/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
with
open
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Meta_Gen/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
feeds
=
{}
feeds
=
{}
...
@@ -86,9 +81,6 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
...
@@ -86,9 +81,6 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
with
open
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Meta_Gen/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
with
open
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Meta_Gen/
{
categories
}
.json
'
,
mode
=
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
feeds
,
indent
=
4
))
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
)):
for
k
in
range
(
len
(
data_3D_pose
)):
if
data_3D_pose
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
if
data_3D_pose
[
k
][
'
id
'
]
==
catergories_occ_array
[
categories
][
0
]:
...
@@ -122,73 +114,44 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
...
@@ -122,73 +114,44 @@ def process_compute(data_name, camera, camera_resized, new_size, Nb_camera, Worl
instance_img
=
instance
(
img
,
id
)
instance_img
=
instance
(
img
,
id
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/Instance_Mask/
{
p
}
.png
"
,
255
*
instance_img
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/Instance_Mask/
{
p
}
.png
"
,
255
*
instance_img
)
cat_mask
=
cv2
.
resize
(
instance_img
,
new_size
)
instance_img_resized
=
cv2
.
resize
(
instance_img
,
new_size
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/Instance_Mask_resized/
{
p
}
.png
"
,
255
*
cat_mask
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/Instance_Mask_resized/
{
p
}
.png
"
,
255
*
instance_img_resized
)
img
=
cv2
.
imread
(
f
"
{
data_name
}
/RGB/
{
p
}
.png
"
)
img
=
cv2
.
imread
(
f
"
{
data_name
}
/RGB/
{
p
}
.png
"
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/RGB_Gen/
{
p
}
.png
"
,
img
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/RGB_Gen/
{
p
}
.png
"
,
img
)
img_resized
=
cv2
.
resize
(
img
,
new_size
)
img_resized
=
cv2
.
resize
(
img
,
new_size
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/RGB_resized/
{
p
}
.png
"
,
img_resized
)
cv2
.
imwrite
(
f
"
{
data_name
}
/Generated/
{
categories
}
/RGB_resized/
{
p
}
.png
"
,
img_resized
)
np
.
set_printoptions
(
precision
=
15
)
np
.
set_printoptions
(
precision
=
15
)
pose
=
np
.
load
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Pose_transformed/
{
p
}
.npy
'
)
pose
=
np
.
load
(
f
'
{
data_name
}
/Generated/
{
categories
}
/Pose_transformed/
{
p
}
.npy
'
)
#print(pose)
R_exp
=
pose
[
0
:
3
,
0
:
3
]
R_exp
=
pose
[
0
:
3
,
0
:
3
]
tVec
=
pose
[
0
:
3
,
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/
{
categories
}
/
{
categories
}
_fps_3d.txt
'
)
fps_points
=
np
.
loadtxt
(
f
'
{
data_name
}
/Generated/
{
categories
}
/
{
categories
}
_fps_3d.txt
'
)
# process(pcd_bbox, pcd, R_exp, tVec, camera, img)
center
=
fps_points
.
mean
(
0
)
center
=
fps_points
.
mean
(
0
)
fps_points
=
np
.
append
(
fps_points
,
[
center
],
axis
=
0
)
fps_points
=
np
.
append
(
fps_points
,
[
center
],
axis
=
0
)
points
=
process2
(
fps_points
,
R_exp
,
tVec
,
camera
,
img
,
vis
)
points
=
process2
(
fps_points
,
R_exp
,
tVec
,
camera
,
img
,
vis
)
#out = np.zeros((1, ))
out
=
[
int
(
catergories_occ_array
[
categories
][
0
])]
#len have to be 1 !!
out
=
[
int
(
catergories_occ_array
[
categories
][
0
])]
# [catergories_occ_array[categories][0]] #obj_id #len have to be 1 !!
print
(
out
)
ind
=
1
ind
=
1
for
point
in
points
:
for
point
in
points
:
#out[0][ind] = point[0][0] / img.shape[1]
#[0][ind + 1] = point[0][1] / img.shape[0]
x
=
point
[
0
][
0
]
/
img
.
shape
[
1
]
x
=
point
[
0
][
0
]
/
img
.
shape
[
1
]
y
=
point
[
0
][
1
]
/
img
.
shape
[
0
]
y
=
point
[
0
][
1
]
/
img
.
shape
[
0
]
out
.
append
(
x
)
out
.
append
(
x
)
out
.
append
(
y
)
out
.
append
(
y
)
ind
+=
2
ind
+=
2
np
.
savetxt
(
f
'
{
data_name
}
/Generated/
{
categories
}
/FPS/
{
p
}
.txt
'
,
np
.
array
(
out
).
reshape
(
1
,
len
(
out
)))
np
.
savetxt
(
f
'
{
data_name
}
/Generated/
{
categories
}
/FPS/
{
p
}
.txt
'
,
np
.
array
(
out
).
reshape
(
1
,
len
(
out
)))
#print("stop")
points_resized
=
process2
(
fps_points
,
R_exp
,
tVec
,
camera_resized
,
img_resized
,
vis
)
points_resized
=
process2
(
fps_points
,
R_exp
,
tVec
,
camera_resized
,
img_resized
,
vis
)
#out = np.zeros((1, ))
out_resized
=
[
int
(
catergories_occ_array
[
categories
][
0
])]
#len have to be 1 !
out_resized
=
[
int
(
catergories_occ_array
[
categories
][
0
])]
# [catergories_occ_array[categories][0]] #obj_id #len have to be 1 !!
print
(
out
)
ind_resized
=
1
ind_resized
=
1
for
point_resized
in
points_resized
:
for
point_resized
in
points_resized
:
#out[0][ind] = point[0][0] / img.shape[1]
#[0][ind + 1] = point[0][1] / img.shape[0]
x_resized
=
point_resized
[
0
][
0
]
/
img_resized
.
shape
[
1
]
x_resized
=
point_resized
[
0
][
0
]
/
img_resized
.
shape
[
1
]
y_resized
=
point_resized
[
0
][
1
]
/
img_resized
.
shape
[
0
]
y_resized
=
point_resized
[
0
][
1
]
/
img_resized
.
shape
[
0
]
out_resized
.
append
(
x_resized
)
out_resized
.
append
(
x_resized
)
out_resized
.
append
(
y_resized
)
out_resized
.
append
(
y_resized
)
ind_resized
+=
2
ind_resized
+=
2
np
.
savetxt
(
f
'
{
data_name
}
/Generated/
{
categories
}
/FPS_resized/
{
p
}
.txt
'
,
np
.
array
(
out_resized
).
reshape
(
1
,
len
(
out_resized
)))
np
.
savetxt
(
f
'
{
data_name
}
/Generated/
{
categories
}
/FPS_resized/
{
p
}
.txt
'
,
np
.
array
(
out_resized
).
reshape
(
1
,
len
(
out_resized
)))
#print("stop")
with
open
(
f
'
{
data_name
}
/Generated/Count_
{
p
}
.json
'
,
mode
=
'
w
'
)
as
f
:
with
open
(
f
'
{
data_name
}
/Generated/Count_
{
p
}
.json
'
,
mode
=
'
w
'
)
as
f
:
f
.
write
(
json
.
dumps
(
list_count_categories
,
indent
=
4
))
f
.
write
(
json
.
dumps
(
list_count_categories
,
indent
=
4
))
print
(
list_count_categories
)
print
(
list_count_categories
)
...
...
This diff is collapsed.
Click to expand it.
main.py
+
2
−
54
View file @
af446c7b
import
os
import
os
import
numpy
as
np
import
numpy
as
np
import
json
from
prepare_data
import
reform_data
from
prepare_data
import
reform_data
#from pose import transform_pose
#from bbox_2d import generate_2d_bbox
#from instance_mask import generate_instance_mask
from
fps_alg
import
apply_fps
from
fps_alg
import
apply_fps
from
bbox_3d
import
get_3D_bbox
from
bbox_3d
import
get_3D_bbox
from
compute_features
import
process_compute
from
compute_features
import
process_compute
from
utils
import
compute_categories_id
,
compute_id_good_occ
import
shutil
import
open3d
as
o3d
import
open3d
as
o3d
# Import the library
import
argparse
from
scipy.spatial
import
distance
from
scipy.spatial
import
distance
import
argparse
def
generate_folders
(
name
,
list_categories
):
def
generate_folders
(
name
,
list_categories
):
is_exist
=
os
.
path
.
exists
(
name
)
is_exist
=
os
.
path
.
exists
(
name
)
...
@@ -52,31 +45,20 @@ if __name__ == '__main__':
...
@@ -52,31 +45,20 @@ if __name__ == '__main__':
# Parse the argument
# Parse the argument
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
### parameters ###
### parameters ###
Categories
=
[]
# to read
Categories
=
[]
# to read
Nb_instance
=
1
Nb_instance
=
1
occ_target
=
0.5
occ_target
=
0.5
dataset_src
=
"
/media/gduret/DATA/dataset/s2rg/Fruits_all_medium/data
"
dataset_src
=
"
/media/gduret/DATA/dataset/s2rg/Fruits_all_medium/data
"
#dataset_src = "/media/mahmoud/E/Fruits_easy/data"
choice
=
"
low
"
# depth of rgb resolution datas
choice
=
"
low
"
# depth of rgb resolution datas
data_options
=
{
"
high
"
:
"
ground_truth_rgb
"
,
data_options
=
{
"
high
"
:
"
ground_truth_rgb
"
,
"
low
"
:
"
ground_truth_depth
"
}
"
low
"
:
"
ground_truth_depth
"
}
dataset_type
=
data_options
[
choice
]
dataset_type
=
data_options
[
choice
]
dataset_name
=
f
"
GUIMOD_
{
choice
}
"
dataset_name
=
f
"
GUIMOD_
{
choice
}
"
list_categories
=
[
"
banana1
"
,
"
kiwi1
"
,
"
pear2
"
,
"
strawberry1
"
,
"
apricot
"
,
"
orange2
"
,
"
peach1
"
,
"
lemon2
"
,
"
apple2
"
]
list_categories
=
[
"
banana1
"
,
"
kiwi1
"
,
"
pear2
"
,
"
strawberry1
"
,
"
apricot
"
,
"
orange2
"
,
"
peach1
"
,
"
lemon2
"
,
"
apple2
"
]
# frame = "1_600000000"
#frame = "1_926000000"
Nb_camera
=
15
Nb_camera
=
15
#Nb_world = 2
generate_folders
(
dataset_name
,
list_categories
)
generate_folders
(
dataset_name
,
list_categories
)
# for cat in list_categories:
# src_bbox = f"Models/{cat}/{cat.lower()}.ply"
# dst_bbox = f"{dataset_name}/Generated/{cat}/{cat.lower()}.ply"
# shutil.copy(src_bbox, dst_bbox)
if
choice
==
'
high
'
:
if
choice
==
'
high
'
:
camera
=
np
.
matrix
([[
1386.4138492513919
,
0.0
,
960.5
],
camera
=
np
.
matrix
([[
1386.4138492513919
,
0.0
,
960.5
],
...
@@ -94,13 +76,11 @@ if __name__ == '__main__':
...
@@ -94,13 +76,11 @@ if __name__ == '__main__':
[
0.0
,
0.0
,
1.0
]])
[
0.0
,
0.0
,
1.0
]])
new_camera
=
trans
@
camera
new_camera
=
trans
@
camera
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/camera_
{
choice
}
.txt
'
,
camera
)
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/camera_
{
choice
}
.txt
'
,
camera
)
reform_data
(
dataset_src
,
dataset_name
,
dataset_type
,
Nb_camera
,
args
.
World_begin
,
args
.
Nb_worlds
)
reform_data
(
dataset_src
,
dataset_name
,
dataset_type
,
Nb_camera
,
args
.
World_begin
,
args
.
Nb_worlds
)
list_categories
=
[
"
banana1
"
,
"
kiwi1
"
,
"
pear2
"
,
"
strawberry1
"
,
"
apricot
"
,
"
orange2
"
,
"
peach1
"
,
"
lemon2
"
,
"
apple2
"
]
list_categories
=
[
"
banana1
"
,
"
kiwi1
"
,
"
pear2
"
,
"
strawberry1
"
,
"
apricot
"
,
"
orange2
"
,
"
peach1
"
,
"
lemon2
"
,
"
apple2
"
]
objs
=
{
"
banana1
"
:
[
0.02949700132012367249
,
0.1511049866676330566
,
0.06059300713241100311
],
objs
=
{
"
banana1
"
:
[
0.02949700132012367249
,
0.1511049866676330566
,
0.06059300713241100311
],
"
kiwi1
"
:
[
0.04908600077033042908
,
0.07206099480390548706
,
0.04909799993038177490
],
"
kiwi1
"
:
[
0.04908600077033042908
,
0.07206099480390548706
,
0.04909799993038177490
],
"
pear2
"
:
[
0.06601099669933319092
,
0.1287339925765991211
,
0.06739201396703720093
],
"
pear2
"
:
[
0.06601099669933319092
,
0.1287339925765991211
,
0.06739201396703720093
],
...
@@ -115,49 +95,17 @@ if __name__ == '__main__':
...
@@ -115,49 +95,17 @@ if __name__ == '__main__':
point_cloud
=
f
"
Models/
{
categories
}
/
{
categories
.
lower
()
}
.ply
"
point_cloud
=
f
"
Models/
{
categories
}
/
{
categories
.
lower
()
}
.ply
"
pcd
=
o3d
.
io
.
read_point_cloud
(
point_cloud
)
pcd
=
o3d
.
io
.
read_point_cloud
(
point_cloud
)
#print("pcd", pcd)
fps_points
=
apply_fps
(
pcd
,
8
)
fps_points
=
apply_fps
(
pcd
,
8
)
#print(fps_points)
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/
{
categories
}
/
{
categories
}
_fps_3d.txt
'
,
fps_points
)
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/
{
categories
}
/
{
categories
}
_fps_3d.txt
'
,
fps_points
)
#point_cloud = f'/home/mahmoud/PycharmProjects/data/GUIMOD_low/Models/{obj}/{obj.lower()}.ply'
#pcd = o3d.io.read_point_cloud(point_cloud)
point_cloud_in_numpy
=
np
.
asarray
(
pcd
.
points
)
point_cloud_in_numpy
=
np
.
asarray
(
pcd
.
points
)
dim
=
calc_pts_diameter2
(
point_cloud_in_numpy
)
*
100
dim
=
calc_pts_diameter2
(
point_cloud_in_numpy
)
*
100
print
(
dim
)
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/
{
categories
}
/
{
categories
}
_diameter.txt
'
,
np
.
array
([
dim
]))
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/
{
categories
}
/
{
categories
}
_diameter.txt
'
,
np
.
array
([
dim
]))
size_bb
=
objs
[
categories
]
size_bb
=
objs
[
categories
]
ext
=
[
x
/
2
for
x
in
size_bb
]
ext
=
[
x
/
2
for
x
in
size_bb
]
bbox
=
get_3D_bbox
(
ext
)
bbox
=
get_3D_bbox
(
ext
)
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/
{
categories
}
/
{
categories
}
_bbox_3d.txt
'
,
bbox
)
# save
np
.
savetxt
(
f
'
{
dataset_name
}
/Generated/
{
categories
}
/
{
categories
}
_bbox_3d.txt
'
,
bbox
)
# save
# json_num = 2
# catergories_instance_array_id_to_cat, catergories_instance_array_cat_to_id, catergories_label_to_id = compute_categories_id(dataset_name, json_num)
# print(f'{dataset_name}/Bbox_3d/{json_num}.json')
# with open(f"{dataset_name}/Bbox_3d/{json_num}.json", 'r') as f:
# data_Bbox_3d = json.load(f)
# print("catergories_instance_array_cat_to_id : ", catergories_instance_array_cat_to_id)
# print("data_Bbox_3d : ", data_Bbox_3d)
# for k in range(len(data_Bbox_3d)):
# if data_Bbox_3d[k]['id'] in catergories_instance_array_cat_to_id[categories]:
# print(data_Bbox_3d)
# size_bb = data_Bbox_3d[k]["bbox"]["size"]
# ext = [x / 2 for x in size_bb]
# bbox = get_3D_bbox(ext)
# np.savetxt(f'{dataset_name}/Generated/{categories}/{categories}_bbox_3d.txt', bbox) # save
# break
process_compute
(
dataset_name
,
camera
,
new_camera
,
new_size
,
Nb_camera
,
args
.
World_begin
,
args
.
Nb_worlds
,
list_categories
,
occ_target
,
False
)
process_compute
(
dataset_name
,
camera
,
new_camera
,
new_size
,
Nb_camera
,
args
.
World_begin
,
args
.
Nb_worlds
,
list_categories
,
occ_target
,
False
)
#transform_pose(dataset_name, Nb_camera, Nb_world, list_categories, occ_target)
#generate_2d_bbox(dataset_name, Nb_camera, Nb_world, list_categories, occ_target)
#generate_instance_mask(dataset_name, Nb_camera, Nb_world, list_categories, occ_target)
#generate_fps(dataset_name, camera, Nb_camera, Nb_world, list_categories, occ_target, True)
#generate_3d_bbox(dataset_name)
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