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
fa2c0be0
Commit
fa2c0be0
authored
Jan 12, 2024
by
Inès EL HADRI
💤
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix vision script
parent
683e5fa2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
cam_vision
tuto_vision/scripts/cam_vision
+19
-19
No files found.
tuto_vision/scripts/cam_vision
View file @
fa2c0be0
...
@@ -22,9 +22,9 @@ class CameraVision(Node):
...
@@ -22,9 +22,9 @@ class CameraVision(Node):
# Initialize subscribers
# Initialize subscribers
self
.
create_subscription
(
Image
,
'cam_rgb'
,
self
.
rgb_callback
,
10
)
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_depth', self.depth_callback, 10)
self
.
create_subscription
(
Image
,
'cam_infra_1'
,
self
.
infra1_callback
,
10
)
#
self.create_subscription(Image, 'cam_infra_1', self.infra1_callback, 10)
self
.
create_subscription
(
Image
,
'cam_infra_2'
,
self
.
infra2_callback
,
10
)
#
self.create_subscription(Image, 'cam_infra_2', self.infra2_callback, 10)
# Initialize subcriber variables
# Initialize subcriber variables
self
.
_rgb_img
=
None
self
.
_rgb_img
=
None
self
.
_depth_img
=
None
self
.
_depth_img
=
None
...
@@ -32,9 +32,9 @@ class CameraVision(Node):
...
@@ -32,9 +32,9 @@ class CameraVision(Node):
self
.
_infra2_img
=
None
self
.
_infra2_img
=
None
# Initialize publishers
# Initialize publishers
self
.
_
detection_publisher
=
self
.
create_publisher
(
Image
,
'cam
_detection'
,
10
)
self
.
_
rgb_detection_publisher
=
self
.
create_publisher
(
Image
,
'rgb
_detection'
,
10
)
self
.
_mask_publisher
=
self
.
create_publisher
(
Image
,
'mask_detection'
,
10
)
self
.
_mask_
detection_
publisher
=
self
.
create_publisher
(
Image
,
'mask_detection'
,
10
)
self
.
_
bottle_detected_publisher
=
self
.
create_publisher
(
String
,
'bottle_detected
'
,
10
)
self
.
_
detection_publisher
=
self
.
create_publisher
(
String
,
'detection
'
,
10
)
# Initialize a clock for the publisher
# Initialize a clock for the publisher
self
.
create_timer
(
timerFreq
,
self
.
loop
)
self
.
create_timer
(
timerFreq
,
self
.
loop
)
...
@@ -45,12 +45,12 @@ class CameraVision(Node):
...
@@ -45,12 +45,12 @@ class CameraVision(Node):
# Callbacks
# Callbacks
def
rgb_callback
(
self
,
img
):
def
rgb_callback
(
self
,
img
):
self
.
_rgb_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
self
.
_rgb_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
def
depth_callback
(
self
,
img
):
#
def depth_callback(self, img):
self
.
_depth_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
#
self._depth_img = self._bridge.imgmsg_to_cv2(img, desired_encoding='passthrough')
def
infra1_callback
(
self
,
img
):
#
def infra1_callback(self, img):
self
.
_infra1_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
#
self._infra1_img = self._bridge.imgmsg_to_cv2(img, desired_encoding='passthrough')
def
infra2_callback
(
self
,
img
):
#
def infra2_callback(self, img):
self
.
_infra2_img
=
self
.
_bridge
.
imgmsg_to_cv2
(
img
,
desired_encoding
=
'passthrough'
)
#
self._infra2_img = self._bridge.imgmsg_to_cv2(img, desired_encoding='passthrough')
# Node internal loop
# Node internal loop
...
@@ -92,19 +92,19 @@ class CameraVision(Node):
...
@@ -92,19 +92,19 @@ class CameraVision(Node):
ros2_mask_image
.
header
.
stamp
=
self
.
get_clock
()
.
now
()
.
to_msg
()
ros2_mask_image
.
header
.
stamp
=
self
.
get_clock
()
.
now
()
.
to_msg
()
ros2_mask_image
.
header
.
frame_id
=
"image"
ros2_mask_image
.
header
.
frame_id
=
"image"
ros2_image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_HSV2BGR
)
ros2_
rgb_
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_HSV2BGR
)
ros2_
image
=
self
.
_bridge
.
cv2_to_imgmsg
(
ros2
_image
,
"bgr8"
)
ros2_
rgb_image
=
self
.
_bridge
.
cv2_to_imgmsg
(
ros2_rgb
_image
,
"bgr8"
)
ros2_image
.
header
.
stamp
=
self
.
get_clock
()
.
now
()
.
to_msg
()
ros2_
rgb_
image
.
header
.
stamp
=
self
.
get_clock
()
.
now
()
.
to_msg
()
ros2_image
.
header
.
frame_id
=
"image"
ros2_
rgb_
image
.
header
.
frame_id
=
"image"
# Publish String message -> to inform that we have detected a bottle
# Publish String message -> to inform that we have detected a bottle
str
=
String
()
str
=
String
()
str
.
data
=
"A bottle has been detected"
str
.
data
=
"A bottle has been detected"
self
.
_
bottle_detected
_publisher
.
publish
(
str
)
self
.
_
detection
_publisher
.
publish
(
str
)
# Publish Image -> to be able to detect false positives and improve the algorithm
# Publish Image -> to be able to detect false positives and improve the algorithm
self
.
_
detection_publisher
.
publish
(
ros2
_image
)
self
.
_
rgb_detection_publisher
.
publish
(
ros2_rgb
_image
)
self
.
_mask_publisher
.
publish
(
ros2_mask_image
)
self
.
_mask_
detection_
publisher
.
publish
(
ros2_mask_image
)
...
...
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