前のチュートリアル: Creative Senz3DおよびIntel RealSense SDK対応のその他の深度センサーを使う
| |
| 原著者 | Kumataro |
| 互換性 | OpenCV >= 4.10 |
| Ubuntu 24.04 |
目的
このチュートリアルでは、Ubuntu 24.04でWayland highgui-backendを使う。
Wayland highgui-backendは実験的な実装である。
セットアップ
- Ubuntu 24.04をセットアップする。
- OpenCVをビルドするために
sudo apt install build-essential git cmake を実行する。
- Wayland highgui-backendを有効にするために
sudo apt install libwayland-dev wayland-protocols libxkbcommon-dev を実行する。
- (オプション)
sudo apt install ninja-build(または、cmakeコマンドの -GNinja オプションを削除する)。
- (オプション)Wayland EGLライブラリを有効にするために
sudo apt install libwayland-egl1 を実行する。
GitHubからOpenCVを取得する
mkdir work
cd work
git clone --depth=1 https://github.com/opencv/opencv.git
- 覚え書き
--depth=1 オプションはダウンロードするコミットを制限するためのものである。より多くのコミット履歴を見たい場合は、このオプションを削除すること。
Wayland highgui-backend付きでOpenCVをビルド/インストールする
OpenCVを構成するために -DWITH_WAYLAND=ON オプションを付けて cmake を実行する。
cmake -S opencv -B build4-main -DWITH_WAYLAND=ON -GNinja
成功すると、Wayland Client/Cursor/ProtocolsとXkbcommonのバージョンが表示される。Wayland EGLはオプションである。
--
-- GUI: Wayland
-- Wayland: (Experimental) YES
-- Wayland Client: YES (ver 1.22.0)
-- Wayland Cursor: YES (ver 1.22.0)
-- Wayland Protocols: YES (ver 1.34)
-- Xkbcommon: YES (ver 1.6.0)
-- Wayland EGL(Option): YES (ver 18.1.0)
-- GTK+: NO
-- VTK support: NO
ビルドするために cmake --build を実行し、システムにインストールするために sudo cmake --install を実行する。
cmake --build build4-main
sudo cmake --install build4-main
sudo ldconfig
Wayland highgui-backendを試す簡単なアプリケーション
このコードを試すと、currentUIFrramework() の名前と、Wayland highgui-backendによるOpenCVロゴのウィンドウを見ることができる。
// 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;
}
制限事項/既知の問題