3. 安装sophon-mw

sophon-mw在不同的Linux发行版上提供不同类型的安装方式。请根据您的系统选择对应的方式,不要在一台机器上混用多种安装方式。 以下描述中“0.10.0”仅为示例,视当前实际安装版本会有变化。

下文中$arch $system根据实际架构进行配置:
  • 主机为x86 处理器的,$arch为amd64, $system为x86_64

  • 主机为arm64或飞腾处理器的,$arch为arm64, $system为aarch64

  • 主机为sg2042处理器的, $arch为riscv64, $system为riscv_64

如果使用Debian/Ubuntu系统:

sophon-mw安装包由四个文件构成:
  • sophon-mw-sophon-ffmpeg_0.10.0_$arch.deb

  • sophon-mw-sophon-ffmpeg-dev_0.10.0_$arch.deb

  • sophon-mw-sophon-opencv_0.10.0_$arch.deb

  • sophon-mw-sophon-opencv-dev_0.10.0_$arch.deb

如果使用CentOS系统:

sophon-mw安装包由四个文件构成:
  • sophon-mw-sophon-ffmpeg_0.10.0_$arch.rpm

  • sophon-mw-sophon-ffmpeg-dev_0.10.0_$arch.rpm

  • sophon-mw-sophon-opencv-abi0_0.10.0_$arch.rpm

  • sophon-mw-sophon-opencv-abi0-dev_0.10.0_$arch.rpm

如果使用Fedora系统:

sophon-mw安装包由四个文件构成:
  • sophon-mw-sophon-ffmpeg_0.10.0_$arch.rpm

  • sophon-mw-sophon-ffmpeg-dev_0.10.0_$arch.rpm

  • sophon-mw-sophon-opencv_0.10.0_$arch.rpm

  • sophon-mw-sophon-opencv-dev_0.10.0_$arch.rpm

其中:

sophon-ffmpeg/sophon-opencv包含了ffmpeg/opencv运行时环境(库文件、工具等);sophon-ffmpeg-dev/sophon-opencv-dev包含了开发环境(头文件、pkgconfig、cmake等)。如果只是在部署环境上安装,则不需要安装sophon-ffmpeg-dev/sophon-opencv-dev。

sophon-mw-sophon-ffmpeg依赖sophon-libsophon包,而sophon-mw-sophon-opencv依赖sophon-mw-sophon-ffmpeg,因此在安装次序上必须先安装libsophon,然后sophon-mw-sophon-ffmpeg,最后安装sophon-mw-sophon-opencv。

CentOS系统中使用的libstdc++库使用旧版本ABI接口,请使用sophon-mw-sophon-opencv-abi0_0.10.0_$arch.rpm安装sophon-mw-sophon-opencv。

安装步骤如下:

安装libsophon依赖库(参考《LIBSOPHON使用手册》)
安装sophon-mw

如果使用Debian/Ubuntu系统:

sudo dpkg -i sophon-mw-sophon-ffmpeg_0.10.0_$arch.deb sophon-mw-sophon-ffmpeg-dev_0.10.0_$arch.deb
sudo dpkg -i sophon-mw-sophon-opencv_0.10.0_$arch.deb sophon-mw-sophon-opencv-dev_0.10.0_$arch.deb

如果使用CentOS系统:

sudo rpm -ivh sophon-mw-sophon-ffmpeg_0.10.0_$arch.rpm sophon-mw-sophon-ffmpeg-dev_0.10.0_$arch.rpm
sudo rpm -ivh sophon-mw-sophon-opencv-abi0_0.10.0_$arch.rpm sophon-mw-sophon-opencv-abi0-dev_0.10.0_$arch.rpm

如果使用Fedora系统,请在安装之前卸载已安装的包:

已安装包目录可以通过此命令列举:
dnf list installed | grep sophon-ffmpeg

然后卸载:
sudo rpm -e sophon-mw-sophon-opencv-dev
sudo rpm -e sophon-mw-sophon-opencv
sudo rpm -e sophon-mw-sophon-ffmpeg-dev
sudo rpm -e sophon-mw-sophon-ffmpeg

再重新安装:
sudo rpm -ivh sophon-mw-sophon-ffmpeg_0.10.0_$arch.rpm sophon-mw-sophon-ffmpeg-dev_0.10.0_$arch.rpm
sudo rpm -ivh sophon-mw-sophon-opencv_0.10.0_$arch.rpm sophon-mw-sophon-opencv-dev_0.10.0_$arch.rpm

在终端执行如下命令,或者logout再login当前用户后即可使用安装的工具:
source /etc/profile

注意:位于SOC模式时,系统已经预装了:

  sophon-mw-soc-sophon-ffmpeg

  sophon-mw-soc-sophon-opencv

只需要按照上述步骤安装:

  sophon-mw-soc-sophon-ffmpeg-dev_0.10.0_arm64.deb

  sophon-mw-soc-sophon-opencv-dev_0.10.0_arm64.deb

安装位置为:

/opt/sophon/
├── libsophon-0.10.0
├── libsophon-current -> /opt/sophon/libsophon_|ver|
├── sophon-ffmpeg_|ver|
│   ├── bin
│   ├── data
│   ├── include
│   ├── lib
│   │   ├── cmake
│   │   └── pkgconfig
│   └── share
├── sophon-ffmpeg-latest -> /opt/sophon/sophon-ffmpeg_|ver|
├── sophon-opencv_|ver|
│   ├── bin
│   ├── data
│   ├── include
│   ├── lib
│   │   ├── cmake
│   │   │   └── opencv4
│   │   └── pkgconfig
│   ├── opencv-python
│   ├── share
│   └── test
└── sophon-opencv-latest -> /opt/sophon/sophon-opencv_|ver|

deb包安装方式并不允许您安装同一个包的多个不同版本,但您可能用其它方式在/opt/sophon下放置了若干不同版本。 在使用deb包安装时,/opt/sophon/sophon-ffmpeg-latest和/opt/sophon/sophon-opencv-latest会指向最后安装的那个版本。在卸载后,它会指向余下的最新版本(如果有的话)。

其中include和lib/cmake lib/pkgconfig目录,分别由sophon-mw-sophon-ffmpeg-dev和sophon-mw-sophon-opencv-dev包安装产生

卸载方式:

如果使用Debian/Ubuntu系统:

sudo apt remove sophon-mw-sophon-opencv-dev sophon-mw-sophon-opencv
sudo apt remove sophon-mw-sophon-ffmpeg-dev sophon-mw-sophon-ffmpeg
或者:
sudo dpkg -r sophon-mw-sophon-opencv-dev
sudo dpkg -r sophon-mw-sophon-opencv
sudo dpkg -r sophon-mw-sophon-ffmpeg-dev
sudo dpkg -r sophon-mw-sophon-ffmpeg

如果使用CentOS系统:

sudo rpm -e sophon-mw-sophon-opencv-abi0-dev
sudo rpm -e sophon-mw-sophon-opencv-abi0
sudo rpm -e sophon-mw-sophon-ffmpeg-dev
sudo rpm -e sophon-mw-sophon-ffmpeg

如果使用Fedora系统:

sudo rpm -e sophon-mw-sophon-opencv-dev
sudo rpm -e sophon-mw-sophon-opencv
sudo rpm -e sophon-mw-sophon-ffmpeg-dev
sudo rpm -e sophon-mw-sophon-ffmpeg

如果使用其它Linux系统:

安装包由一个文件构成:
  • sophon-mw_0.10.0_$system.tar.gz

可以通过如下步骤安装:

先按照《LIBSOPHON使用手册》安装好libsophon包,然后,

tar -xzvf sophon-mw_0.10.0_$system.tar.gz

sudo cp -r sophon-mw_0.10.0_$system/* /

sudo ln -s /opt/sophon/sophon-ffmpeg_0.10.0 /opt/sophon/sophon-ffmpeg-latest

sudo ln -s /opt/sophon/sophon-opencv_0.10.0 /opt/sophon/sophon-opencv-latest

sudo ln -s /opt/sophon/sophon-sample_0.10.0 /opt/sophon/sophon-sample-latest

sudo sed -i "s/usr\/local/opt\/sophon\/sophon-ffmpeg-latest/g"  /opt/sophon/sophon-ffmpeg-latest/lib/pkgconfig/*.pc
sudo sed -i "s/^prefix=.*$/prefix=\/opt\/sophon\/sophon-opencv-latest/g"  /opt/sophon/sophon-opencv-latest/lib/pkgconfig/opencv4.pc

注意:以上安装步骤的命令,如果直接粘贴存在问题,可以手动敲打。

最后,安装bz2 libc6 libgcc依赖库(这部分需要根据操作系统不同,选择对应的安装包,这里不统一介绍)

然后是一些配置工作:

添加库和可执行文件路径:
sudo cp /opt/sophon/sophon-ffmpeg-latest/data/01_sophon-ffmpeg.conf   /etc/ld.so.conf.d/
sudo cp /opt/sophon/sophon-opencv-latest/data/02_sophon-opencv.conf   /etc/ld.so.conf.d/
sudo ldconfig
sudo cp /opt/sophon/sophon-ffmpeg-latest/data/sophon-ffmpeg-autoconf.sh   /etc/profile.d/
sudo cp /opt/sophon/sophon-opencv-latest/data/sophon-opencv-autoconf.sh   /etc/profile.d/
sudo cp /opt/sophon/sophon-sample-latest/data/sophon-sample-autoconf.sh   /etc/profile.d/
source /etc/profile

卸载方式:

sudo rm -f /etc/ld.so.conf.d/01_sophon-ffmpeg.conf
sudo rm -f /etc/ld.so.conf.d/02_sophon-opencv.conf
sudo ldconfig
sudo rm -f /etc/profile.d/sophon-ffmpeg-autoconf.sh
sudo rm -f /etc/profile.d/sophon-opencv-autoconf.sh
sudo rm -f /etc/profile.d/sophon-sample-autoconf.sh
sudo rm -f /opt/sophon/sophon-ffmpeg-latest
sudo rm -f /opt/sophon/sophon-opencv-latest
sudo rm -f /opt/sophon/sophon-sample-latest
sudo rm -rf /opt/sophon/sophon-ffmpeg_0.10.0
sudo rm -rf /opt/sophon/sophon-opencv_0.10.0
sudo rm -rf /opt/sophon/sophon-sample_0.10.0
sudo rm -rf /opt/sophon/opencv-bmcpu_0.10.0
注意事项:
  • 如果需要用 sophon-opencv的python接口,手动设置环境变量:
    export PYTHONPATH=$PYTHONPATH:/opt/sophon/sophon-opencv-latest/opencv-python