23. Formが表示されたらTimerをスタートさせる
namespace CVTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
}
private void Form1_Shown(object sender, EventArgs e)
{
timer1.Start(); //タイマーの動作を開始
}
}
}
①Form1_Shownが追加される
②自分で追加
24. Webカメラの画像を取得
using OpenCvSharp; //OpenCvSharpの機能をインポート
using OpenCvSharp.Extensions;
namespace CVTest
{
public partial class Form1 : Form
{
VideoCapture video = new VideoCapture(0); //Videoキャプチャ
Mat bgr; //カラー画像を扱うクラス
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
}
/*****以下省略*****/
25. Webカメラの画像を取得
VideoCapture video = new VideoCapture(0);;
Mat bgr;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
bgr = video.RetrieveMat(); //カメラから画像を取得しbgrに記録
pictureBox1.BackgroundImage = bgr.ToBitmap();
bgr.Release(); //画像を記録したメモリを開放
}
private void Form1_Shown(object sender, EventArgs e)
{
timer1.Start();
}