OpenCV 5.0.0
Open Source Computer Vision
読み込み中...
検索中...
見つかりません
🤖 AIによる機械翻訳(非公式) — これは OpenCV 5.0.0 公式リファレンス(英語)を AI (Claude) で自動翻訳したものです。訳に誤りを含む場合があります。正確な情報は 公式英語版(原文) を参照してください。
Vizの起動

次のチュートリアル: ウィジェットの姿勢

目的

このチュートリアルでは、次のことを学ぶ

  • 可視化ウィンドウを開く。
  • 名前でウィンドウにアクセスする。
  • イベントループを開始する。
  • 指定した時間だけイベントループを開始する。

コード

コードは こちら からダウンロードできる。

#include <opencv2/viz.hpp>
#include <iostream>
using namespace cv;
using namespace std;
static void help()
{
cout
<< "--------------------------------------------------------------------------" << endl
<< "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. "
<< "You can access the same window via its name. You can run event loop for a given period of time. " << endl
<< "Usage:" << endl
<< "./launching_viz" << endl
<< endl;
}
int main()
{
help();
viz::Viz3d myWindow("Viz Demo");
myWindow.spin();
cout << "First event loop is over" << endl;
viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
sameWindow.spin();
cout << "Second event loop is over" << endl;
sameWindow.spinOnce(1, true);
while(!sameWindow.wasStopped())
{
sameWindow.spinOnce(1, true);
}
cout << "Last event loop is over" << endl;
return 0;
}
The Viz3d class represents a 3D visualizer window. This class is implicitly shared.
Definition viz3d.hpp:68
void spin()
The window renders and starts the event loop.
void spinOnce(int time=1, bool force_redraw=false)
Starts the event loop for a given time.
bool wasStopped() const
Returns whether the event loop has been stopped.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
Definition core.hpp:107
STL namespace.

解説

プログラムの全体的な構造を以下に示す。

  • ウィンドウを作成する。
    viz::Viz3d myWindow("Viz Demo");
  • イベントループを開始する。このイベントループはユーザーが e, E, q, Q を押して終了させるまで実行される。
    myWindow.spin();
  • 同じウィンドウに名前でアクセスする。ウィンドウは暗黙的に共有されるため、sameWindowmyWindow とまったく同じである。名前が存在しない場合は、新しいウィンドウが作成される。
    viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");
  • 制御されたイベントループを開始する。開始されると、wasStopped はfalseに設定される。whileループの内側で、各反復において spinOnce が呼び出され、イベントループが完全に停止するのを防ぐ。whileループの内側では、ユーザーはウィンドウと相互作用するものを含め、他の文を実行できる。
    sameWindow.spinOnce(1, true);
    while(!sameWindow.wasStopped())
    {
    sameWindow.spinOnce(1, true);
    }

結果

これがプログラムの実行結果である。