ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Hello @autonomy,
Don't worry, the cv_bridge method isn't compressing your images twice, otherwise, we would open a PR now. So, you are right regarding the cv2.imdecode
use, however, the cv_bridge just uses it to read an image from the specified buffer in the memory as you can check here.
Just for completing the answer we can analyze the snippet of the code available here:
str_msg = cmprs_img_msg.data
buf = np.ndarray(shape=(1, len(str_msg)) dtype=np.uint8, buffer=cmprs_img_msg.data)
im = cv2.imdecode(buf, cv2.IMREAD_ANYCOLOR)
At the first line, it just initializing the compressed data provided to a variable. At the second, it assigns the compressed data to a buffer method (buffer=cmprs_img_msg.data
). At the third, it uses the cv2.imdecode
to read the buffer using the cv2.IMREAD_ANYCOLOR, which just guarantees the use of any possible color format.
PS: In the second line, It could have used the variable defined before (str_msg
), I don't know why it didn't.
So, don't worry about that keep pushing you ROS knowledge!
Waiting for your reply.