Skip to content
shimat edited this page Jan 19, 2019 · 2 revisions

From camera device

public static void Main(string[] args)
{
    VideoCapture capture = new VideoCapture(0);
    using (Window window = new Window("Camera"))
    using (Mat image = new Mat()) // Frame image buffer
    {
        // When the movie playback reaches end, Mat.data becomes NULL.
	while (true)
	{
	    capture.Read(image); // same as cvQueryFrame
	    if (image.Empty())break;
            window.ShowImage(image);
	    Cv2.WaitKey(30);
	}
    }
}

From file

// Opens MP4 file (ffmpeg is probably needed)
VideoCapture capture = new VideoCapture("aaa.mp4");

int sleepTime = (int) Math.Round(1000 / capture.Fps);

using (Window window = new Window("capture"))
using (Mat image = new Mat()) // Frame image buffer
{
    // When the movie playback reaches end, Mat.data becomes NULL.
    while (true)
    {
        capture.Read(image); // same as cvQueryFrame
        if (image.Empty())
            break;

        window.ShowImage(image);
        Cv2.WaitKey(sleepTime);
    } 
}
Clone this wiki locally