上一篇教程: 使用 Creative Senz3D 和其他 Intel RealSense SDK 兼容深度传感器
| |
| 原始作者 | Kumataro |
| 兼容性 | OpenCV >= 4.10 |
| Ubuntu 24.04 |
目标
本教程是在 Ubuntu 24.04 中使用 Wayland highgui 后端。
Wayland highgui 后端是实验性实现。
设置
- 设置 Ubuntu 24.04。
sudo apt install build-essential git cmake 构建 OpenCV。
sudo apt install libwayland-dev wayland-protocols libxkbcommon-dev 启用 Wayland highgui 后端。
- (可选)
sudo apt install ninja-build(或删除 cmake 命令的 -GNinja 选项)。
- (可选)
sudo apt install libwayland-egl1 启用 Wayland EGL 库。
从 GitHub 获取 OpenCV
mkdir work
cd work
git clone --depth=1 https://github.com/opencv/opencv.git
- 注意
--depth=1 选项是限制下载提交。如果您想查看更多提交历史,请删除此选项。
使用 Wayland highgui 后端构建/安装 OpenCV
运行带有 -DWITH_WAYLAND=ON 选项的 cmake 来配置 OpenCV。
cmake -S opencv -B build4-main -DWITH_WAYLAND=ON -GNinja
如果成功,将显示 Wayland Client/Cursor/Protocols 和 Xkbcommon 版本。 Wayland EGL 是可选的。
--
-- GUI: Wayland
-- Wayland:(实验性)是
-- Wayland Client:是(版本 1.22.0)
-- Wayland Cursor:是(版本 1.22.0)
-- Wayland Protocols:是(版本 1.34)
-- Xkbcommon:是(版本 1.6.0)
-- Wayland EGL(Option):是(版本 18.1.0)
-- GTK+:否
-- VTK 支持:否
运行 cmake --build 进行构建,运行 sudo cmake --install 安装到您的系统。
cmake --build build4-main
sudo cmake --install build4-main
sudo ldconfig
简单的应用程序来尝试 Wayland highgui 后端
尝试这段代码,您可以查看 currentUIFrramework() 的名称和带有 Wayland highgui 后端的 OpenCV logo 窗口。
// g++ main.cpp -o a.out -I /usr/local/include/opencv4 -lopencv_core -lopencv_highgui -lopencv_imgcodecs
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
#include <string>
int main(void)
{
std::cout << "cv::currentUIFramework() returns " << cv::currentUIFramework() << std::endl;
cv::Mat src;
src = cv::imread("opencv-logo.png");
cv::namedWindow("src");
int key = 0;
do
{
cv::imshow("src", src );
key = cv::waitKey(50);
} while( key != 'q' );
return 0;
}
限制/已知问题