Skip to content

Commit 1850121

Browse files
committed
Fix up mostly minor comments from review.
Signed-off-by: Chris Lalancette <[email protected]>
1 parent 7eca1ce commit 1850121

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

image_tools_py/src/cam2image_py.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
# System imports
16-
import sys
1716
import argparse
17+
import sys
1818

1919
# ROS2 imports
2020
import rclpy
@@ -36,9 +36,7 @@ def flip_image_cb(msg):
3636
global is_flipped
3737
is_flipped = msg.data
3838

39-
output = 'off'
40-
if is_flipped:
41-
output = 'on'
39+
output = 'on' if is_flipped else 'off'
4240

4341
print('Set flip mode to: ' + output)
4442

@@ -54,15 +52,15 @@ def mat2encoding(frame):
5452
encoding += prefix
5553
break
5654
else:
57-
raise Exception("Unsupported frame shape %d" % (frame.shape[2]))
55+
raise ValueError("Unsupported frame shape %d" % (frame.shape[2]))
5856

5957
types = {'uint8': '8', 'int16': '16'}
6058
for dtype, num in types.items():
6159
if frame.dtype == dtype:
6260
encoding += num
6361
break
6462
else:
65-
raise Exception("Unsupported frame type " + frame.dtype)
63+
raise ValueError("Unsupported frame type " + frame.dtype)
6664

6765
return encoding
6866

@@ -167,7 +165,7 @@ def main():
167165

168166
if args.show_camera == 1:
169167
# Show the image in a window called 'cam2imagepy', if requested.
170-
cv2.imshow('cam2imagepy', frame)
168+
cv2.imshow('cam2image_py', frame)
171169
# Draw the image to the screen and wait 1 millisecond
172170
cv2.waitKey(1)
173171

@@ -176,7 +174,7 @@ def main():
176174
pub.publish(msg)
177175
frame_number += 1
178176

179-
# Do some work in rclcpp and wait for more to come in.
177+
# Do some work in rclpy and wait for more to come in.
180178
rclpy.spin_once(node, 1.0 / float(args.frequency))
181179

182180
if __name__ == '__main__':

image_tools_py/src/image_qos_profile.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def create_qos_profile(depth, reliability_policy, keep):
3232
elif reliability_policy == 1:
3333
qos_profile.reliability = QoSReliabilityPolicy.RMW_QOS_POLICY_RELIABILITY_RELIABLE
3434
else:
35-
raise Exception("Invalid reliability policy (must be 0 for best effort or 1 for reliable")
35+
raise ValueError("Invalid reliability policy (must be 0 for best effort or 1 for reliable")
3636

37-
# The history policy determins how messages are saved until the message is
37+
# The history policy determines how messages are saved until the message is
3838
# taken by the reader.
3939
# KEEP_ALL saves all messages until they are taken.
4040
# KEEP_LAST enforces a limit on the number of messages that are saved,
@@ -44,7 +44,7 @@ def create_qos_profile(depth, reliability_policy, keep):
4444
elif keep == 1:
4545
qos_profile.history = QoSHistoryPolicy.RMW_QOS_POLICY_HISTORY_KEEP_ALL
4646
else:
47-
raise Exception("Invalid keep policy (must be 0 for keep last or 1 for keep all")
47+
raise ValueError("Invalid keep policy (must be 0 for keep last or 1 for keep all")
4848

4949
qos_profile.durability = QoSDurabilityPolicy.RMW_QOS_POLICY_DURABILITY_VOLATILE
5050

image_tools_py/src/showimage_py.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# OpenCV imports
2424
import cv2
2525

26+
# Numpy imports
2627
import numpy
2728

2829
# Local imports
@@ -35,14 +36,14 @@ def encoding2mat(encoding):
3536
if encoding.startswith(prefix):
3637
break
3738
else:
38-
raise Exception("Unsupported encoding " + encoding)
39+
raise ValueError("Unsupported encoding " + encoding)
3940

4041
types = {'8': 'uint8', '16': 'int16'}
4142
for prefix, dtype in types.items():
4243
if encoding[channels:] == prefix:
4344
break
4445
else:
45-
raise Exception("Unsupported encoding " + encoding)
46+
raise ValueError("Unsupported encoding " + encoding)
4647

4748
return dtype, channels
4849

@@ -69,7 +70,7 @@ def main():
6970
args = parser.parse_args()
7071

7172
if args.show_camera == 1:
72-
cv2.namedWindow('showimagepy')
73+
cv2.namedWindow('showimage_py')
7374

7475
# Initialize a ROS 2 node to subscribe to images read from the OpenCV interface to
7576
# the camera.
@@ -96,7 +97,7 @@ def image_cb(msg):
9697
dtype=dtype,
9798
buffer=bytes(msg.data))
9899

99-
cv2.imshow("showimagepy", frame)
100+
cv2.imshow("showimage_py", frame)
100101
# Draw the image to the screen and wait 1 millisecond
101102
cv2.waitKey(1)
102103

0 commit comments

Comments
 (0)