Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
larm-astro
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Inès EL HADRI
larm-astro
Commits
ef6780b7
Commit
ef6780b7
authored
Jan 10, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic node form cam_vision
parent
562e5d33
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
cam_vision
tuto_vision/scripts/cam_vision
+69
-0
No files found.
tuto_vision/scripts/cam_vision
0 → 100644
View file @
ef6780b7
#!/usr/bin/python3
import
rclpy
from
rclpy.node
import
Node
from
sensor_msgs.msg
import
Image
import
numpy
as
np
import
sys
,
cv2
from
cv_bridge
import
CvBridge
class
CameraVision
(
Node
):
def
__init__
(
self
,
name
=
"cam_vision"
,
timerFreq
=
1
/
60.0
):
super
()
.
__init__
(
name
)
# Create the node
# Initialize subscribers
self
.
create_subscription
(
Image
,
'cam_rgb'
,
self
.
rgb_callback
,
10
)
self
.
create_subscription
(
Image
,
'cam_depth'
,
self
.
depth_callback
,
10
)
self
.
create_subscription
(
Image
,
'cam_infra_1'
,
self
.
infra1_callback
,
10
)
self
.
create_subscription
(
Image
,
'cam_infra_2'
,
self
.
infra2_callback
,
10
)
# Initialize publishers
# self._rgb_publisher = self.create_publisher(Image, 'cam_rgb', 10)
# Initialize a clock for the publisher
self
.
create_timer
(
timerFreq
,
self
.
loop
)
# Initialize a ROS2 Image to CV2 image converter
self
.
_bridge
=
CvBridge
()
# Callbacks
def
rgb_callback
(
self
,
img
):
self
.
_rgb_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
def
depth_callback
(
self
,
img
):
self
.
_depth_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
def
infra1_callback
(
self
,
img
):
self
.
_infra1_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
def
infra2_callback
(
self
,
img
):
self
.
_infra2_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
# Publish functions
# def publish_rgb(self):
# """
# Publish RGB image
# """
# self._rgb_publisher.publish(self._rgb_image)
# return 0
# Node internal loop
def
loop
(
self
):
pass
def
main
():
"""
Main loop
"""
rclpy
.
init
()
rosNode
=
CameraDriver
(
timerFreq
=
1.0
/
120
)
rclpy
.
spin
(
rosNode
)
rosNode
.
destroy_node
()
rclpy
.
shutdown
()
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment