OpenCV 4.12.0
開源計算機視覺
載入中...
搜尋中...
無匹配項
在 Ubuntu 中使用 Wayland highgui 後端

上一篇教程: 使用 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;
}

限制/已知問題