ros-perception / image_transport_plugins

A set of plugins for publishing and subscribing to sensor_msgs/Image topics in representations other than raw pixel data.
BSD 3-Clause "New" or "Revised" License
55 stars 120 forks source link

Fix passing parameters to cv::imencode() for OpenCV 4.7 #130

Closed meyerj closed 1 year ago

meyerj commented 1 year ago

The number of elements in vector params needs to be even (cv::imencode(), cv::imwrite()).

OpenCV version 4.7 complains if the vector has an odd number of elements, like 3 or 9: https://github.com/opencv/opencv/commit/f0df78b7e743a8d735a4bc669ae64a155f08645d#diff-c43d1948c31949b9c25dea5c7f019e1bfed04d98ee9fb1a97f7b1b98dd9b5525R718

The reserve() + emplace_back() approach has been adapted from the rolling branch, where the bug has already been fixed in the same way in https://github.com/ros-perception/image_transport_plugins/commit/7ca907277eda51ec2fbb71409bda33d1395d6127.

ijnek commented 1 year ago

Thanks for the contribution @meyerj! I agree with the changes, and wonder why the numbers were off-by-one before... :thinking:

meyerj commented 1 year ago

Thanks for the contribution @meyerj! I agree with the changes, and wonder why the numbers were off-by-one before... thinking

Likely because C programmers are used to add one more element to arrays for a terminating null character ;-) Or maybe it even had to be like that in older versions of OpenCV, too...