OpenCVSharp4でwebカメラを使ってみた

はじめに

OpenCVを使ってwebカメラをとりあえず使ってみたかった

using System;  
using OpenCvSharp;  
using OpenCvSharp.Extensions;  

namespace カメラテスト {  
    class Program {  
        static void Main(string[] args) {  
            var capture = new VideoCapture(0);  
            int fps = 30;  
            int sleepTime = (int)Math.Round((decimal)1000 / fps);  

            using(var window = new Window("capture")) {  
                Mat img = new Mat();  

                while(true) {  
                    capture.Read(img);  

                    if(img.Empty()) break;  

                    window.ShowImage(img);  
                    Cv2.WaitKey(sleepTime);  
                }  
            }  
        }  
    }  
}  

参考

https://github.com/shimat/opencvsharp_samples/