本文整理汇总了C#中OpenCvSharp.Mat.SubMat方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.SubMat方法的具体用法?C# Mat.SubMat怎么用?C# Mat.SubMat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenCvSharp.Mat
的用法示例。
在下文中一共展示了Mat.SubMat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartCaptureLoop
/// <summary>
/// キャプチャループスレッド作成
/// </summary>
/// <param name="ms">キャプチャ間隔</param>
private void StartCaptureLoop(double ms = 50)
{
//Parallel.Invoke(() =>
m_Task = Task.Run(() =>
{
var capCnt = 0;
var sw = new Stopwatch();
var mat = new Mat(m_DstSize.Height, m_DstSize.Width, MatType.CV_8UC4, m_Bits);
var mat_xor = new Mat();
var mat_diff = new Mat();
var segRect = new Rectangle(0, 0, m_DstSize.Width / CaptureDivisionNum, m_DstSize.Height / CaptureDivisionNum);
var cData = new CaptureData()
{
captureData = m_Bits,
captureSize = m_DstSize,
isIntraFrame = true,
};
m_IntraFrameMat = new Mat(m_DstSize.Height, m_DstSize.Width, MatType.CV_8UC4);
sw.Start();
while (m_IsCapturing)
{
//Win32.BitBlt(hdc, 0, 0, dstSize.Height, dstSize.Width, m_ProcessDC, 0, 0, Win32.SRCCOPY);
Win32.StretchBlt(m_Hdc, 0, m_DstSize.Height, m_DstSize.Width, -m_DstSize.Height, m_ProcessDC,
m_SrcRect.X, m_SrcRect.Y, m_SrcRect.Width, m_SrcRect.Height, Win32.SRCCOPY);
Captured(this, cData);
try
{
Cv2.BitwiseXor(mat, m_IntraFrameMat, mat_xor);
Cv2.CvtColor(mat_xor, mat_diff, ColorConversionCodes.RGBA2GRAY);
}
catch
{
continue;
}
for (int y = 0; y < CaptureDivisionNum; y++)
{
for (int x = 0; x < CaptureDivisionNum; x++)
{
var segIdx = y * CaptureDivisionNum + x;
segRect.X = segRect.Width * x;
segRect.Y = segRect.Height * y;
var sRect = new Rect(segRect.X, segRect.Y, segRect.Width, segRect.Height);
var segDiff = mat_diff.SubMat(sRect);
var nonZero = segDiff.CountNonZero();
if (nonZero != 0)
{
var segCapture = mat.SubMat(sRect);
var img_buffer = segCapture.ImEncode(EncodeFormatExtension, m_EncodingParam);
var sData = new SegmentCaptureData()
{
segmentIdx = segIdx,
rect = segRect,
encodedFrameBuffer = img_buffer,
};
SegmentCaptured(this, sData);
var segIntra = m_IntraFrameMat.SubMat(sRect);
segCapture.CopyTo(segIntra);
}
}
}
var sleepMs = (ms * capCnt) - sw.Elapsed.TotalMilliseconds;
if (sleepMs > 0) Thread.Sleep((int)sleepMs);
capCnt++;
//Debug.Log(""+capCnt);
//GC.Collect();
//File.WriteAllBytes("dump/"+capCnt+".jpg", mat.ImEncode(EncodeFormatExtension, m_EncodingParam));
}
sw.Stop();
//Win32.SelectObject(hdc, hbmpPrev);
});
}