[06] 目的ごとの整理(4)
動画の読み込みと表示
var capture = new VideoCapture(@“Path/To/MovieFile.xxx”);
using (var win = new Window(“capture”))
using (var mat = new Mat())
{
while (true)
{
capture.Read(mat);
// 読み込めるフレームがなくなったら終了
if (mat.Empty()) { break; }
win.ShowImage(mat);
Cv2.WaitKey(33);
}
}
動画ファイルの保存
// デフォルトのカメラをオープン
using (var capture = new VideoCapture(0))
using (var writer = new VideoWriter(“test.avi”, FourCC.Default, capture.Fps, new Size(capture.FrameWidth, capture.FrameHeight)))
using (var win = new Window(“capture”))
using (var mat = new Mat())
using (var dst = new Mat())
{
while (true)
{
capture.Read(mat);
Cv2.CvtColor(mat, dst, ColorConversionCodes.BGR2GRAY);
win.ShowImage(dst);
writer.Write(dst);
if (Cv2.WaitKey(30) >= 0) { break; }
}
}