ros-perception / vision_opencv

Apache License 2.0
557 stars 601 forks source link

using cv_bridge with python 3.6 on ubunut 16.04 #347

Open waspinator opened 4 years ago

waspinator commented 4 years ago

I need to use python 3.6 in a kinetic ROS package that manipulates images using opencv. To transfer images in and out of the package I'm using cv_bridge, but it is only supported on python 2.7 so I'm trying to figure out a way to get around that. I have seen reports of this being possible but I'm unable to reproduce the results.

Below is the dockerfile which I use to build my environment. Running it, starting a python3.6 shell and importing cv_bridge

from cv_bridge.boost.cv_bridge_boost import getCvType

gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)

running source /cv_bridge_ws/install/setup.bash doesn't help. Strangely though if I run that exact same command another time then it seems to work.

How do I properly source the workspace to use cv_bridge?


FROM ros:kinetic

RUN apt-get update && apt-get install -y \
    software-properties-common python-catkin-tools \
    curl wget python-dev build-essential checkinstall \
    libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev

RUN apt-get update && apt-get install -y \
    ros-kinetic-cv-bridge \
    ros-kinetic-image-transport \
    ros-kinetic-tf \
    ros-kinetic-diagnostic-updater \
    ros-kinetic-ddynamic-reconfigure

RUN add-apt-repository -y ppa:deadsnakes/ppa \
    && apt-get update && apt-get install -y python3.6-dev

RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
    python2 get-pip.py && python3.6 get-pip.py

RUN pip3 install opencv-python PyYAML cython rospkg

RUN ln -s /usr/lib/x86_64-linux-gnu/libboost_python-py35.so /usr/lib/x86_64-linux-gnu/libboost_python3.so
RUN mkdir --parents /cv_bridge_ws/src
WORKDIR /cv_bridge_ws
RUN catkin config \
    -DPYTHON_EXECUTABLE=/usr/bin/python3.6 \
    -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m \
    -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
RUN catkin config --install
RUN git -C /cv_bridge_ws/src clone -b 1.12.8 https://github.com/ros-perception/vision_opencv.git 
RUN catkin config --extend /opt/ros/kinetic && \
    catkin clean --yes && \
    catkin build
MasterKID223 commented 3 years ago

try source /cv_bridge_ws/install/setup.bash --extend