Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tracker_node.py #15

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions script/tracker_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def image_callback(self, msg):
header = msg.header
encoding = msg.encoding
numpy_image = ros_numpy.numpify(msg)

# Convert RGBA to RGB
if numpy_image.shape[2] == 4: # Check if the image has 4 channels
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section assumes that all 4-channel images are RGBA. If the original encoding is bgra8 or bgra16, this could lead to bugs.

numpy_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGBA2RGB)
encoding = "bgr8"
Comment on lines +46 to +47
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Your code uses tab for indentation, but please unify it with 4 spaces.
  • cv2.COLOR_RGBA2RGB converts from RGBA to RGB and outputs in RGB order. However, encoding = "bgr8" indicates BGR order.
Suggested change
numpy_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGBA2RGB)
encoding = "bgr8"
numpy_image = cv2.cvtColor(numpy_image, cv2.COLOR_RGBA2RGB)
encoding = "rgb8"


results = self.model.track(
source=numpy_image,
conf=self.conf_thres,
Expand Down