本文整理汇总了C#中OpenCvSharp.Mat.Empty方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.Empty方法的具体用法?C# Mat.Empty怎么用?C# Mat.Empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.Mat
的用法示例。
在下文中一共展示了Mat.Empty方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public void Run()
{
var capture = new VideoCapture();
capture.Set(CaptureProperty.FrameWidth, 640);
capture.Set(CaptureProperty.FrameHeight, 480);
capture.Open(-1);
if (!capture.IsOpened())
throw new Exception("capture initialization failed");
var fs = FrameSource.CreateCameraSource(-1);
var sr = SuperResolution.CreateBTVL1();
sr.SetInput(fs);
using (var normalWindow = new Window("normal"))
using (var srWindow = new Window("super resolution"))
{
var normalFrame = new Mat();
var srFrame = new Mat();
while (true)
{
capture.Read(normalFrame);
sr.NextFrame(srFrame);
if (normalFrame.Empty() || srFrame.Empty())
break;
normalWindow.ShowImage(normalFrame);
srWindow.ShowImage(srFrame);
Cv2.WaitKey(100);
}
}
}
示例2: Run
public void Run()
{
// Opens MP4 file (ffmpeg is probably needed)
var capture = new VideoCapture(FilePath.Movie.Bach);
int sleepTime = (int)Math.Round(1000 / capture.Fps);
using (var window = new Window("capture"))
{
// Frame image buffer
Mat image = new Mat();
// 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);
}
}
}
示例3: Run
public void Run()
{
const string OutVideoFile = "out.avi";
// Opens MP4 file (ffmpeg is probably needed)
VideoCapture capture = new VideoCapture(FilePath.Movie.Bach);
// Read movie frames and write them to VideoWriter
Size dsize = new Size(640, 480);
using (VideoWriter writer = new VideoWriter(OutVideoFile, -1, capture.Fps, dsize))
{
Console.WriteLine("Converting each movie frames...");
Mat frame = new Mat();
while(true)
{
// Read image
capture.Read(frame);
if(frame.Empty())
break;
Console.CursorLeft = 0;
Console.Write("{0} / {1}", capture.PosFrames, capture.FrameCount);
// grayscale -> canny -> resize
Mat gray = new Mat();
Mat canny = new Mat();
Mat dst = new Mat();
Cv2.CvtColor(frame, gray, ColorConversionCodes.BGR2GRAY);
Cv2.Canny(gray, canny, 100, 180);
Cv2.Resize(canny, dst, dsize, 0, 0, InterpolationFlags.Linear);
// Write mat to VideoWriter
writer.Write(dst);
}
Console.WriteLine();
}
// Watch result movie
using (VideoCapture capture2 = new VideoCapture(OutVideoFile))
using (Window window = new Window("result"))
{
int sleepTime = (int)(1000 / capture.Fps);
Mat frame = new Mat();
while (true)
{
capture2.Read(frame);
if(frame.Empty())
break;
window.ShowImage(frame);
Cv2.WaitKey(sleepTime);
}
}
}
示例4: Run
public void Run()
{
using (var capture = new VideoCapture(FilePath.Movie.Bach))
using (var mog = BackgroundSubtractorMOG.Create())
using (var windowSrc = new Window("src"))
using (var windowDst = new Window("dst"))
{
var frame = new Mat();
var fg = new Mat();
while (true)
{
capture.Read(frame);
if(frame.Empty())
break;
mog.Run(frame, fg, 0.01);
windowSrc.Image = frame;
windowDst.Image = fg;
Cv2.WaitKey(50);
}
}
}