Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
ros_cosypose
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Dorian Baudu
ros_cosypose
Commits
f32d418d
Commit
f32d418d
authored
1 year ago
by
Théo Martinez
Browse files
Options
Downloads
Patches
Plain Diff
rewrite happypose node into a service
parent
15791a78
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scripts/happypose_with_camera.py
+45
-21
45 additions, 21 deletions
scripts/happypose_with_camera.py
with
45 additions
and
21 deletions
scripts/happypose_with_camera.py
+
45
−
21
View file @
f32d418d
...
...
@@ -9,7 +9,10 @@ from happypose.toolbox.inference.types import (
)
import
rospy
import
tf
from
ros_cosypose.srv
import
Inference
,
InferenceResponse
from
sensor_msgs.msg
import
Image
,
CameraInfo
from
std_msgs.msg
import
Int32MultiArray
from
geometry_msgs.msg
import
Pose
,
Point
,
Quaternion
from
pytorch3d
import
transforms
...
...
@@ -24,33 +27,54 @@ def run_inference_from_realtime_camera(
observation
=
ObservationTensor
.
from_numpy
(
image
.
data
,
None
,
camera_info
.
K
)
CosyPose
=
CosyPoseWrapper
(
dataset_name
=
dataset_to_use
,
n_workers
=
8
)
predictions
=
CosyPose
.
inference
(
observation
)
return
predictions
.
poses
rospy
.
loginfo
()
return
predictions
.
poses
,
predictions
.
infos
except
AttributeError
as
err
:
print
(
"
rien trouvé
"
)
return
[]
rospy
.
loginfo
(
"
rien trouvé
"
)
return
[]
,
[]
if
__name__
==
"
__main__
"
:
def
retrieve_parameters_and_run_inference
()
:
dataset
=
rospy
.
get_param
(
"
~dataset
"
,
"
ycbv
"
)
model
=
rospy
.
get_param
(
"
~model
"
,
"
megapose-1.0-RGB-multi-hypothesis
"
)
rospy
.
init_node
(
"
caemra_listener
"
,
anonymous
=
True
)
cam_info
=
rospy
.
wait_for_message
(
"
/camera/color/camera_info
"
,
CameraInfo
)
image
=
rospy
.
wait_for_message
(
"
/camera/color/image_raw
"
,
Image
)
inference
=
run_inference_from_realtime_camera
(
cam_info
,
image
,
model
,
dataset
)
for
i
,
pose
in
enumerate
(
inference
):
return
run_inference_from_realtime_camera
(
cam_info
,
image
,
model
,
dataset
)
def
convert_list_to_ros_msg
(
list
):
res
=
Int32MultiArray
()
res
.
data
.
append
(
list
)
return
res
.
data
def
get_nb_objects_in_image
(
req
):
inference
,
inference_infos
=
retrieve_parameters_and_run_inference
()
nb_objects_in_image
=
[
0
for
_
in
range
(
31
)]
if
inference_infos
==
[]:
return
convert_list_to_ros_msg
(
nb_objects_in_image
)
labels
=
inference_infos
[
"
label
"
]
for
idx
,
pose
in
enumerate
(
inference
):
object_number
=
labels
[
idx
][
-
2
:]
if
not
object_number
.
isnumeric
():
raise
RuntimeError
(
"
label doesn
'
t end with tless object index :
"
,
object_number
)
object_number
=
int
(
object_number
)
nb_objects_in_image
[
object_number
]
+=
1
quat
=
transforms
.
matrix_to_quaternion
(
pose
[:
3
,
:
3
])
pose
=
Pose
(
position
=
Point
(
pose
[
0
,
3
],
pose
[
1
,
3
],
pose
[
2
,
3
]),
orientation
=
Quaternion
(
quat
[
0
],
quat
[
1
],
quat
[
2
],
quat
[
3
]),
)
pub
=
rospy
.
Publisher
(
f
"
tf/happypose_object_
{
i
}
"
,
Pose
,
queue_size
=
10
)
pub
.
publish
(
pose
)
if
inference
==
[]:
pose
=
Pose
(
position
=
Point
(
0
,
0
,
0
),
orientation
=
Quaternion
(
1
,
0
,
0
,
0
),
br
=
tf
.
TransformBroadcaster
()
br
.
sendTransform
(
(
pose
[
0
,
3
],
pose
[
1
,
3
],
pose
[
2
,
3
]),
(
quat
[
0
],
quat
[
1
],
quat
[
2
],
quat
[
3
]),
rospy
.
Time
.
now
(),
f
"
tf/happypose_object_
{
object_number
}
_
{
nb_objects_in_image
[
object_number
]
}
"
,
"
camera_color_optical_frame
"
,
)
pub
=
rospy
.
Publisher
(
"
tf/happypose_object
"
,
Pose
,
queue_size
=
10
)
pub
.
publish
(
pose
)
return
convert_list_to_ros_msg
(
nb_objects_in_image
)
if
__name__
==
"
__main__
"
:
rospy
.
init_node
(
"
inference_on_camera_image
"
,
anonymous
=
True
)
s
=
rospy
.
Service
(
"
happypose_inference
"
,
Inference
,
get_nb_objects_in_image
)
rospy
.
spin
()
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