Ubuntu20.04 cv_bridge按装

不要按装在虚拟环境中

退出虚拟环境

conda deactivate

进入虚拟环境

conda activate

 进入指定虚拟环境

conda activate pytorch

准备按装

退出当前虚拟环境

conda deactivate

按装依赖包   需要先按装ROS Noetic  sudo apt install ros-noetic-desktop-full 

sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-noetic-cv-bridge

python-catkin-tools 改python3-catkin-tools 即可

注Melodic是Kinetic的升级版本 

没有可用的软件包 python-catkin-tools

E: 无法定位软件包 ros-kinetic-cv-bridge

 换源 更新软件源和软件

sudo gedit /etc/apt/sources.list

sudo apt-get update 
sudo apt-get  upgrade 

ubuntu 20.04 LTS (focal) 阿里源 

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

 

 再次按装依赖包   

ubuntu ros版本对应关系

20.04  Noetic 

18.04   Melodic

16.04   Kinetic

14.04   Indigo

python-catkin-tools改python3-catkin-tools

sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-noetic-cv-bridge

E: 软件包 python-catkin-tools 没有可安装候选   

可以用pip3按装

sudo apt install python3

sudo apt install python3-pip

sudo pip3 install catkin-tools

//

ubuntu22.04不支持直接用apt安装cv_bridge,需要从源码安装且先按装ROS Noetic。cv_bridge的源码位于https://github.com/ros-perception/vision_opencv注意需要使用其中的noetic分支

/

Ubuntu 22.04上使用cv bridge需要先安装ROS Noetic,然后再安装cv bridge

sudo apt update

sudo apt install ros-noetic-desktop-full

sudo apt install ros-noetic-cv-bridge

测试

rosrun cv_bridge cv_bridge_test

按装依赖1   注意需要先按装ROS Noetic

sudo apt install python3-catkin-pkg-modules python3-rospkg-modules python3-empy python3-nose python3-yaml python3-setuptools python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential cmake

 按装依赖2   注意需要先按装ROS Noetic

sudo apt-get install python3-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-noetic-cv-bridge

下载cv_bridge源码

到根目录

cd ~

创建文件夹

mkdir -p catkin_workspace/src

到指定文件下

cd catkin_workspace

Compilation 在当前文件下执行

catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so

 编译

catkin config --install

到src目录 /home/chuanmei/catkin_workspace/src/

cd src/

 下载源代码

git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv

可以直接网页下载 

然后放src文件夹下,依次执行

1.

conda deactivate
sudo apt-get install python3-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-noetic-cv-bridge
mkdir -p catkin_workspace/src

2.

cd ~
cd catkin_workspace
catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.6m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.6m.so

3. 

catkin config --install
git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv

版本检查

apt-cache show ros-noetic-cv-bridge | grep Version

cd ~

cd /home/chuanmei/catkin_workspace/src/vision_opencv

cd ../../

编译

catkin build

 根目录

cd

创建文件夹

mkdir test

创建文件

touch test.py

到指定目录

cd test/

删除文件 

rm test.py

编缉文件

gedit test.py

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import torch
import cv2
from cv_bridge import CvBridge,CvBridgeError

import sys
try:
    sys.path.remove('/opt/ros/noetic/lib/python3/dist-packages')
	
except:
    pass
print('hello pytorch cv_bridge')
cd ..
cd test/
python test.py

环境Ok 

 

环境Ok

 退出

exit()

查看python指向

ls -l python*

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

激活环境

conda activate pytorch

到根目录

cd ~

到指定目录

cd catkin_workspace/

 apt按装opencv

sudo apt install python3-opencv

pip3 install opencv-python 清华镜像

pip3 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple

#这里 --extend 参数的作用是让这次的路径配置不影响之前配置好的路径,否则这一次source会覆盖掉之前配置的路径。
source install/setup.bash --extend 

source install/setup.bash --extend

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import torch
import cv2
from cv_bridge import CvBridge,CvBridgeError

import sys
try:
    sys.path.remove('/opt/ros/noetic/lib/python3/dist-packages')
	
except:
    pass
print('hello pytorch cv_bridge')

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值