fix(vision): correct LCM serialization for detection class_id and results_length#1368
Conversation
Greptile SummaryFixed critical LCM serialization bugs that prevented detection data transmission. The PR correctly addresses three issues: converts Key Changes:
Minor Note: Confidence Score: 4/5
Important Files Changed
Last reviewed commit: 1c0ff7d |
| bbox = (x1, y1, x2, y2) | ||
|
|
||
| # Extract hypothesis info | ||
| # Note: LCM decodes class_id as str (LCM string type), convert back to int |
There was a problem hiding this comment.
I remember investigating this on my end, and concluded that weirdly, ROS vision messages does define class_id as string
https://github.com/ros-perception/vision_msgs/blob/ros2/vision_msgs/msg/ObjectHypothesis.msg
https://docs.ros.org/en/rolling/p/vision_msgs/msg/ObjectHypothesis.html
There was a problem hiding this comment.
Since String class_id is a legitimate attribute in ROS, I think perhaps we should conform to this on our end as well and simply make our class_ids strings as well in order to maintain full interop with ROS detections.
IDK what's the rationale in ROS for this, but I assume it allows us to mark things as "a chair" etc. How does this sound?
|
@leshy I looked into the rationale behind ROS defining The reason we initially had it as an I dug into YOLO's So, instead of just casting the integer to a string (e.g.,
One quick question for you: |
Problem
The robot's detection data was not being correctly transmitted via LCM due to two primary serialization bugs:
ObjectHypothesis.class_idis defined as a string in the LCM schema, but we were passing an int. This caused anAttributeError: 'int' object has no attribute 'encode'during the lcm_encode() process.results_lengthin the Detection2D message was either hardcoded or incorrectly handled, leading to empty detection arrays or index errors during deserialization.Solution
ROSDetection2Dmessage creation to setresults_length=len(results)dynamically, ensuring the LCM library knows exactly how many objects to serialize.Breaking Changes
None
How to Test