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
1a67b882
Commit
1a67b882
authored
1 year ago
by
Théo Martinez
Browse files
Options
Downloads
Patches
Plain Diff
add node script to use happypose with real time camera image
parent
e941649a
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
+56
-0
56 additions, 0 deletions
scripts/happypose_with_camera.py
with
56 additions
and
0 deletions
scripts/happypose_with_camera.py
0 → 100644
+
56
−
0
View file @
1a67b882
from
happypose.pose_estimators.cosypose.cosypose.scripts.run_inference_on_example
import
(
run_inference
,
)
from
happypose.pose_estimators.cosypose.cosypose.utils.cosypose_wrapper
import
(
CosyPoseWrapper
,
)
from
happypose.toolbox.inference.types
import
(
ObservationTensor
,
)
import
rospy
from
sensor_msgs.msg
import
Image
,
CameraInfo
from
geometry_msgs.msg
import
Pose
,
Point
,
Quaternion
from
pytorch3d
import
transforms
def
run_inference_from_realtime_camera
(
camera_info
:
CameraInfo
,
image
:
Image
,
model_name
:
str
,
dataset_to_use
:
str
,
)
->
None
:
try
:
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
except
AttributeError
as
err
:
print
(
"
rien trouvé
"
)
return
[]
if
__name__
==
"
__main__
"
:
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
):
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
),
)
pub
=
rospy
.
Publisher
(
"
tf/happypose_object
"
,
Pose
,
queue_size
=
10
)
pub
.
publish
(
pose
)
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