【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)

这篇具有很好参考价值的文章主要介绍了【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)

一、WSL 安装

直接在 Windows Store 里搜索最新的 Ubuntu版本 22.04 版本进行安装;

二、编译安装 OpenCV

Powershell 里输入 wsl进入环境,

sudo apt install build-essential
sudo apt install cmake git libgtk2.0-dev pkg-config 
sudo apt install libavcodec-dev libavformat-dev
sudo apt install libjpeg-dev libswscale-dev libtiff5-dev
sudo apt install python-dev python-numpy libtbb2 libtbb-dev libpng-dev libjasper-dev libdc1394-22-dev

无法安装 libjasper-devlibdc1394-22-dev

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package libjasper-dev
E: Unable to locate package libdc1394-22-dev

解决一:
sudo vim /etc/apt/sources.list
最后一行加入如下内容并保存退出:
deb http://security.ubuntu.com/ubuntu xenial-security main

再执行:
sudo apt-get update


解决二:

sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

但是可能会出现问题如下:

Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [99.8 kB]
Hit:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy InRelease
Hit:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-updates InRelease
Hit:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-backports InRelease
Hit:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu jammy-security InRelease
Err:2 http://security.ubuntu.com/ubuntu xenial-security InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
Reading package lists... Done
W: GPG error: http://security.ubuntu.com/ubuntu xenial-security InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 40976EAF437D05B5 NO_PUBKEY 3B4FE6ACC0B21F32
E: The repository 'http://security.ubuntu.com/ubuntu xenial-security InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

解决方法如下

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys  3B4FE6ACC0B21F32
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.zW1sustAL5/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
gpg: key 3B4FE6ACC0B21F32: public key "Ubuntu Archive Automatic Signing Key (2012) <ftpmaster@ubuntu.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
sudo apt update && sudo apt upgrade

参考: https://blog.csdn.net/wm9028/article/details/122982116

无法安装 libdc1394-22-dev

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package libdc1394-22-dev

问题解答

The libdc1394-22-dev package was removed in Debian and Ubuntu after 21.10. This is because the source package it was from - libdc1394-22 - was superseded by a different package.

The package was orphaned and removed with Debian Bug #963924 because the package libdc1394 has superseded libdc1394-22.

It has its own dev package - libdc1394-dev - which will probably get you what you want/need. So install that package instead of the package you were trying to install.

安装 libdc1394-dev即可。

sudo apt install libdc1394-dev

(一)下载 OpenCV

进入 OpenCV 官网 下载对应版本,我这里用的是 4.5.4;

(二)编译安装

将下载的源码拷贝到 WSL 系统里的 /home 目录下,并解压。

cd opencv-4.5.4
mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_GENERATE_PKGCONFIG=ON ..
make -j
sudo make install   # 安装

可能出现的问题1:找不到ippcv

ippcv资源百度盘 提取码: 8888

将下载的文件替换到 .cache 目录下,并将文件名替换为下载的文件名。 重新编译。

参考: https://blog.csdn.net/qq_43478260/article/details/109458079

可能出现的问题2:找不到ade

OpenCV的gapi模块的编译依赖ADE,在OpenCV的build过程中会自动下载ADE,因为被墙了,所以下载失败,所以要手动下载并修改相关文件;

ade资源百度盘 提取码:8888

通过命令查看ade的md5值,并根据值修改相关文件;

md5sum ade.zip

修改文件 DownloadADE.cmake (modules/gapi/cmake/DownloadADE.cmake) 里

set(ade_md5 ... 里面的md5值替换成刚才的值,

修改 "https://github.com/opencv/ade/archive/" 为文件路径 file///home/usrname/opencv3rd/

ocv_download(FILENAME ${ade_filename}
HASH a d e m d 5 U R L " {ade_md5} URL " ademd5URL"{OPENCV_ADE_URL}"
“$ENV{OPENCV_ADE_URL}”
“https://github.com/opencv/ade/archive/”
DESTINATION_DIR ${ade_src_dir}
ID ADE
STATUS res
UNPACK RELATIVE_URL)

修改完后,重新编译。

参考: https://blog.csdn.net/wzw_2008/article/details/106944407

可能出现的问题3:内存不足

C++: fatal error: Killed signal terminated program cc1plus的问题解决

编译过程中,过度占用了宿主机的CPU和内存,可以减少编译线程;

make -j4 # 之前是 make -j 需修改为 make -j4, 可能编译会慢很多,但是稳

参考:

  1. https://blog.csdn.net/Undefinedefity/article/details/106180033
  2. https://www.zhihu.com/question/340599582/answer/1371691742

(三)环境变量配置与验证

sudo vim /etc/ld.so.conf

在最后加上一行 /usr/loacal/lib, 完成后 ESC再输入 :wq保存退出。

运行

sudo ldconfig

然后修改 bash.bashrc文件

sudo vim /etc/bash.bashrc

在文件末尾加入:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

然后进行 souce,更新环境变量

source /etc/bash.bashrc

验证是否安装成功

pkg-config --modversion opencv4

输出 4.5.4代表安装成功。

三、安装Xserver, 图形化显示

wsl 里安装 xfce4

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install xfce4
sudo apt install xfce4-session

配置环境变量

在wsl里

sudo vim ~/.bashrc

末尾添加

export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0

使配置生效

source ~/.bashrc

运行命令:

startxfce4

遇到如下错误

xfce4-panel: Failed to connect to session manager: Failed to connect to the session manager: IO error occured opening connection

link

this error occurs with permission issues, try: sudo -u youruser startxfce4

如果要在Windows上查看系统,需要安装一个Xserver,可以安装VcXsrv,链接:https://sourceforge.net/projects/vcxsrv/

Windows上启动 XLaunch

Display settings: One large window
How to start clients: Start no client
Disable access control: Yes:

【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)

【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)
【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)

【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)

保存完成后,下次直接点开保存的文件即可打开。

【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)

至此已经可以在Windows11下可以看到 WSL里的Ubuntu2204系统和文件了。

参考

  1. https://blog.csdn.net/weixin_44501390/article/details/121291442
  2. https://blog.csdn.net/m0_51984869/article/details/127538531
  3. https://blog.csdn.net/Undefinedefity/article/details/106180033

四、验证是否显示OpenCV

进入到OpenCV的samples目录下

cd ~/opencv-4.5.4/samples/cpp/example_cmake/
cmake .
make 
./opencv_example

【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)

至此,终于可以在Windows11的WSL上使用Ubuntu2204愉快的玩耍OpenCV了。


五、其他

  1. wsl 使用了Windows里的环境变量,想要去掉

/etc/wsl.conf 里插入如下代码可以不使用Windows的环境变量:

[interop]
appendWindowsPath = false

echo $PATH 可以查看环境变量是否已经发生了变化;

如果wsl要重新启用Windows的环境变量,那么就删除该段代码

参考
https://www.cnblogs.com/newber/p/14167430.html
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configure-per-distro-launch-settings-with-wslconf

  1. 重启 WSL

右键 Powershell 管理员身份打开,输入下面命令

#停止LxssManager服务
net stop LxssManager  
 
#启动LxssManager服务
net start LxssManager 

参考链接

https://blog.csdn.net/wm9028/article/details/122982116
https://www.cnblogs.com/newber/p/14167430.html
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configure-per-distro-launch-settings-with-wslconf
https://askubuntu.com/questions/1407580/unable-to-locate-package-libdc1394-22-dev
https://blog.csdn.net/qq_43478260/article/details/109458079
https://blog.csdn.net/Undefinedefity/article/details/106180033
https://www.zhihu.com/question/340599582/answer/1371691742
https://blog.csdn.net/weixin_44501390/article/details/121291442
https://blog.csdn.net/m0_51984869/article/details/127538531文章来源地址https://www.toymoban.com/news/detail-450906.html

到了这里,关于【环境配置】Windows 11 的 WSL(Ubuntu2204) 安装OpenCV 4.5.4 (亲测有效)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 【2023最新版】Win11: WSL(Ubuntu22.04)使用docker远程容器教程(Windows的Docker Desktop下载安装、迁移到非系统盘、配置国内镜像源、设置 WSL2)

    目录 一、准备工作 1. 安装WSL(适用于 Linux 的 Windows 子系统) 2. docker简介——来源chatGPT 二、Windows安装 Docker Desktop 1. 官网链接 2. 安装过程 3. 迁移到非系统盘 4. 配置国内镜像源 国内镜像 方法1——通过Docker-Desktop配置 方法2——找打daemon.json文件进行配置 三、在适用于 Wind

    2024年02月12日
    浏览(61)
  • Win10安装Linux子系统WSL(ubuntu2204)及图形桌面xfce4

    什么是 WSL ? 在计算机上使用 Linux 系统通常有两种方式:使用虚拟机或安装 Linux 系统。使用虚拟机时开销较大,直接使用 Linux 系统虽然可以带来流畅体验,但与 Windows 之间来回切换比较麻烦。为此,微软开发了适用于 Linux 的 Windows 子系统,简称 WSL。 WSL 可以让开发人员可以

    2024年02月13日
    浏览(36)
  • windows11使用wsl2环境安装svox2

    1. wsl --install -d ubuntu-22.04 输入用户名和密码 2. 用以下命令将系统迁移到d盘: wsl --export ubuntu-22.04 d:ubuntuwslubuntu22.04.tar(导出) wsl --import ubuntu d:ubuntuwsl d:ubuntuwslubuntu22.04.tar(导入) wsl --unregister ubuntu-22.04(删除原系统) wsl进入新系统 3.安装miniconda. 4.安装svox2 下载:sxyu/

    2024年02月06日
    浏览(38)
  • 【环境配置】Windows下WSL将ubuntu挪位置-系统盘清理

    最近 C 盘空间暴涨,用工具 WinDirStat -强烈推荐的工具 查看发现 WSL 子系统占用了 6个多 G 的空间,遂想办法挪个位置; 【】将 Windows 里的子系统挪到非系统盘 D 盘; 打开 WSL 控制台 导出 注销 重新导入 清理 WPS 垃圾 路径为: C:UsersxxxAppDataRoamingkingsoftwpsaddonspool

    2024年02月15日
    浏览(28)
  • Windows 11 上从零开始基于 wsl-ubuntu 搭建 AI 学习环境及部署多种私有 ChatGPT

    今天(2023/6/2)刚刚换了 1 块 4TB 的硬盘,在 Windows 11 上从零开始,基于 Windows Subsystem for Linux 搭建一套 AI 学习环境。 其中包括,安装 Python、安装 Miniconda3、安装 CUDA Toolkit、安装 git lfs、配置 Hugging Face 的缓存路径、本地部署 ChatGLM-6B、本地部署 VisualGLM-6B等等内容。 安装 Ubuntu-

    2024年02月07日
    浏览(44)
  • Windows通过WSL安装Ubuntu以及深度学习配置

    三种方式: 虚拟机如VM-WARE、VITRUAL-BOX--不稳定,使用gpu不方便 双系统--分配内存,与windows界面分离,只能单独使用linux WSL(Windows Subsystem for Linux)---适用于Linux的windows子系统 同时使用windows与linux 还可以在linux中使用windows上的gpu 可以很方便的分配在一个合适的硬盘内存中,不需

    2024年02月21日
    浏览(33)
  • WSL2安装Ubuntu,配置机器学习环境

    WSL全称Windows Subsystem for Linux,适用于Linux的Windows子系统,WSL有WSL1和WSL2两个版本,最新的wsl2已可媲美真实操作系统。 WSL2拥有完整的Linux内核。对于跨OS文件系统的性能,微软也给出了解决办法:可通过将项目文件存储在与处理项目时运行的工具相同的操作系统上进行处理,并

    2024年02月12日
    浏览(31)
  • ubuntu 下 opencv的安装以及配置(亲测有效)

    当在Ubuntu上安装OpenCV时,可以按照以下详细步骤进行操作: 这将更新系统的包列表,确保可以获取到最新的软件包信息。 这些命令将安装构建OpenCV所需的各种依赖项,包括编译工具、图像处理库、视频处理库、GUI库等。 使用 git clone 命令克隆OpenCV的源码库,并使用 cd 命令切

    2024年02月15日
    浏览(34)
  • 【环境配置】ubuntu2204-cudnn GPG key 错误

    问题: cudnn GPG error 找到 /var 目录下对应的 cudnn* 文件夹,然后执行如下命令 W: GPG error: cudnn GPG key 错误

    2024年02月12日
    浏览(32)
  • Windows 10 安装配置WSL2(ubuntu20.04)教程 超详细

    超详细windows安装配置WSL2(ubuntu20.04)步骤 Windows上快速安装WSL2教程 windows wsl2安装 Windows Subsystem for Linux(简称WSL),Windows下的Linux子系统,是一个在Windows 10上能够运行原生Linux二进制可执行文件(ELF格式)的兼容层。它是由微软与Canonical公司合作开发,其目标是使纯正的Ubu

    2024年02月12日
    浏览(67)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包