Created
March 4, 2014 07:21
-
-
Save kamiyaowl/9341762 to your computer and use it in GitHub Desktop.
OpenCVSharp:でCvWindowたくさん作るのめんどくさい
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using OpenCvSharp; | |
using System; | |
using System.Collections.Generic; | |
namespace kamiya.util | |
{ | |
/// <summary> | |
/// 簡単に画像プレビューする仕組みを提供します | |
/// ex) | |
/// var prev = new CvPreview(); | |
/// prev["window title"].ShowImage(/* IplImage */); | |
/// </summary> | |
public class CvPreview : IDisposable | |
{ | |
private Dictionary<string, CvWindow> windows = new Dictionary<string, CvWindow>(); | |
public WindowMode DefaultFlags = WindowMode.AutoSize; | |
/// <summary> | |
/// CvWindowを取得します | |
/// </summary> | |
/// <param name="name">ウインドウタイトル</param> | |
/// <returns>指定されたCvWindow</returns> | |
public CvWindow this[string name] | |
{ | |
get | |
{ | |
return Get(name); | |
} | |
} | |
private CvWindow Get(string name) | |
{ | |
if (!windows.ContainsKey(name)) | |
{ | |
windows.Add(name, new CvWindow(name, DefaultFlags)); | |
} | |
return windows[name]; | |
} | |
/// <summary> | |
/// すべてのウインドウを消し去ります | |
/// </summary> | |
public void Clear() | |
{ | |
foreach (var w in windows) | |
{ | |
if (w.Value != null && !w.Value.IsDisposed) | |
{ | |
w.Value.Dispose(); | |
} | |
} | |
windows.Clear(); | |
} | |
public void Dispose() | |
{ | |
Clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment