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

Python 3 compatibility (Melodic) #312

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
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
43 changes: 37 additions & 6 deletions .travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,38 @@ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main
wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
sudo apt-get update -qq || echo Ignore error on apt-get update
# Install ROS
sudo apt-get install -qq -y python-catkin-pkg python-catkin-tools python-rosdep python-wstool ros-$ROS_DISTRO-catkin
source /opt/ros/$ROS_DISTRO/setup.bash
# Setup for rosdep
sudo rosdep init
rosdep update
if [ "x${ROS_PYTHON_VERSION}" == "x3" ]; then
sudo apt-get install -qq -y python3-catkin-pkg python3-rosdep python3-rosinstall-generator python3-wstool python3-vcstool build-essential
wget https://bootstrap.pypa.io/get-pip.py
python3 ./get-pip.py
rm ./get-pip.py
pip3 install catkin_tools
# Update rosdep definitions
sudo rosdep init
rosdep update
# Create an underlay with all dependencies
mkdir -p ~/underlay_ws/src
cd ~/underlay_ws
# FIXME: use RPP instead of hardcoded list?
# FIXME: change --upstream-devel to releases?
rosinstall_generator cv_bridge image_geometry --deps --deps-only --upstream-devel --rosdistro $ROS_DISTRO > deps.rosinstall
vcs import --input deps.rosinstall ./src
# FIXME: roslisp does not get pulled somehow
if [ ! -d "./src/roslisp" ]; then
git clone https://github.com/ros/roslisp src/roslisp
fi
rosdep install --from-paths ./src --ignore-src -y
catkin config --install --cmake-args -DCMAKE_BUILD_TYPE=Release
catkin build
source ~/underlay_ws/install/setup.bash
else
sudo apt-get install -qq -y python-catkin-pkg python-catkin-tools python-rosdep python-wstool ros-$ROS_DISTRO-catkin
source /opt/ros/$ROS_DISTRO/setup.bash
# Setup for rosdep
sudo rosdep init
rosdep update
fi

travis_time_end

travis_time_start setup.install
Expand Down Expand Up @@ -67,7 +94,11 @@ travis_time_end
travis_time_start setup.script
# Compile and test.
#script:
source /opt/ros/$ROS_DISTRO/setup.bash
if [ "x${ROS_PYTHON_VERSION}" == "x3" ]; then
source ~/underlay_ws/install/setup.bash
else
source /opt/ros/$ROS_DISTRO/setup.bash
fi
cd ~/catkin_ws
catkin build -p1 -j1 --no-status
catkin run_tests -p1 -j1
Expand Down
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ sudo: required
dist: trusty
language: generic
env:
- ROS_DISTRO=melodic
- ROS_DISTRO=melodic ROS_PYTHON_VERSION=2
- ROS_DISTRO=melodic ROS_PYTHON_VERSION=3
# Install system dependencies, namely ROS.
before_install:
# Define some config vars.
Expand All @@ -11,7 +12,7 @@ before_install:
- export ROS_PARALLEL_JOBS='-j8 -l6'
script:
- echo "Testing branch $TRAVIS_BRANCH of $REPOSITORY_NAME"
- docker run --rm -i -v $CI_SOURCE_PATH:$CI_SOURCE_PATH -e "CI_SOURCE_PATH=$CI_SOURCE_PATH" -e "HOME=$HOME" -e "ROS_DISTRO=$ROS_DISTRO" -e "ROS_PARALLEL_JOBS=$ROS_PARALLEL_JOBS" -t ubuntu:bionic sh -c "cd $CI_SOURCE_PATH; ./.travis.sh"
- docker run --rm -i -v $CI_SOURCE_PATH:$CI_SOURCE_PATH -e "CI_SOURCE_PATH=$CI_SOURCE_PATH" -e "HOME=$HOME" -e "ROS_DISTRO=$ROS_DISTRO" -e "ROS_PARALLEL_JOBS=$ROS_PARALLEL_JOBS" -e "ROS_PYTHON_VERSION=$ROS_PYTHON_VERSION" -t ubuntu:bionic sh -c "cd $CI_SOURCE_PATH; ./.travis.sh"
after_failure:
- find ${HOME}/.ros/test_results -type f -exec echo "== {} ==" \; -exec cat {} \;
- for file in ${HOME}/.ros/log/rostest-*; do echo "=== $file ==="; cat $file; done
17 changes: 11 additions & 6 deletions cv_bridge/package.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<package format="2">
<package format="3">
<name>cv_bridge</name>
<version>1.13.0</version>
<description>
Expand All @@ -21,21 +21,26 @@

<build_depend>boost</build_depend>
<build_depend>libopencv-dev</build_depend>
<build_depend>python</build_depend>
<build_depend>python-opencv</build_depend>
<build_depend condition="$ROS_PYTHON_VERSION == 2">python</build_depend>
<build_depend condition="$ROS_PYTHON_VERSION == 3">python3</build_depend>
<build_depend condition="$ROS_PYTHON_VERSION == 2">python-opencv</build_depend>
<build_depend condition="$ROS_PYTHON_VERSION == 3">python3-opencv</build_depend>
<build_depend>rosconsole</build_depend>
<build_depend>sensor_msgs</build_depend>

<exec_depend>boost</exec_depend>
<exec_depend>libopencv-dev</exec_depend>
<exec_depend>python</exec_depend>
<exec_depend>python-opencv</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 2">python-opencv</exec_depend>
<exec_depend condition="$ROS_PYTHON_VERSION == 3">python3-opencv</exec_depend>
<exec_depend>rosconsole</exec_depend>
<build_export_depend>libopencv-dev</build_export_depend>
<build_export_depend>sensor_msgs</build_export_depend>

<test_depend>rostest</test_depend>
<test_depend>python-numpy</test_depend>
<test_depend condition="$ROS_PYTHON_VERSION == 2">python-numpy</test_depend>
<test_depend condition="$ROS_PYTHON_VERSION == 3">python3-numpy</test_depend>

<doc_depend>dvipng</doc_depend>
</package>
3 changes: 2 additions & 1 deletion cv_bridge/src/module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ int convert_to_CvMat2(const PyObject* o, cv::Mat& m);
PyObject* pyopencv_from(const cv::Mat& m);

#if PYTHON3
static int do_numpy_import( )
static void* do_numpy_import( )
{
import_array( );
return NULL;
}
#else
static void do_numpy_import( )
Expand Down
10 changes: 5 additions & 5 deletions cv_bridge/test/enumerants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def test_enumerants_cv2(self):
img_msg.height = 480
img_msg.encoding = "rgba8"
img_msg.step = 640*4
img_msg.data = (640 * 480) * "1234"
img_msg.data = (640 * 480) * b"1234"

bridge_ = CvBridge()
cvim = bridge_.imgmsg_to_cv2(img_msg, "rgb8")
import sys
self.assertRaises(sys.getrefcount(cvim) == 2)
self.assertTrue(sys.getrefcount(cvim) == 2)

# A 3 channel image cannot be sent as an rgba8
self.assertRaises(CvBridgeError, lambda: bridge_.cv2_to_imgmsg(cvim, "rgba8"))
Expand All @@ -31,9 +31,9 @@ def test_enumerants_cv2(self):
bridge_.cv2_to_imgmsg(cvim, "rgb8")
bridge_.cv2_to_imgmsg(cvim, "bgr8")

self.assertRaises(getCvType("32FC4") == cv2.CV_8UC4)
self.assertRaises(getCvType("8UC1") == cv2.CV_8UC1)
self.assertRaises(getCvType("8U") == cv2.CV_8UC1)
self.assertFalse(getCvType("32FC4") == cv2.CV_8UC4)
self.assertTrue(getCvType("8UC1") == cv2.CV_8UC1)
self.assertTrue(getCvType("8U") == cv2.CV_8UC1)

def test_numpy_types(self):
import cv2
Expand Down
7 changes: 5 additions & 2 deletions cv_bridge/test/python_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

import cv_bridge

import sys
if sys.version > '3':
xrange = range

def test_cvtColorForDisplay():
# convert label image to display
Expand All @@ -11,11 +14,11 @@ def test_cvtColorForDisplay():
label_value = 0
grid_num_y, grid_num_x = 3, 4
for grid_row in xrange(grid_num_y):
grid_size_y = height / grid_num_y
grid_size_y = int(height / grid_num_y)
min_y = grid_size_y * grid_row
max_y = min_y + grid_size_y
for grid_col in xrange(grid_num_x):
grid_size_x = width / grid_num_x
grid_size_x = int(width / grid_num_x)
min_x = grid_size_x * grid_col
max_x = min_x + grid_size_x
label[min_y:max_y, min_x:max_x] = label_value
Expand Down