EmguCV取rtsp流为什么会停在_capture.Retrieve(_frame, 0)这里?

struggleº 2019-01-26 11:48:26
从Emgu官网下载了3.2.0,运行了C:\Emgu\emgucv-windesktop 3.2.0.2682\Emgu.CV.Example\CameraCapture里的模板程序。发现程序经常会在_capture.Retrieve(_frame, 0)停住。这是为什么,求大佬解答。
下面是模板程序
public partial class CameraCapture : Form
{
private VideoCapture _capture = null;
private bool _captureInProgress;
private Mat _frame;
private Mat _grayFrame;
private Mat _smallGrayFrame;
private Mat _smoothedGrayFrame;
private Mat _cannyFrame;

public CameraCapture()
{
InitializeComponent();
CvInvoke.UseOpenCL = false;
try
{
_capture = new VideoCapture("rtsp://192.168.79.110:8553/main");
_capture.ImageGrabbed += ProcessFrame;
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
_frame = new Mat();
_grayFrame = new Mat();
_smallGrayFrame = new Mat();
_smoothedGrayFrame = new Mat();
_cannyFrame = new Mat();
}

private void ProcessFrame(object sender, EventArgs arg)
{
if (_capture != null && _capture.Ptr != IntPtr.Zero)
{
_capture.Retrieve(_frame, 0);

CvInvoke.CvtColor(_frame, _grayFrame, ColorConversion.Bgr2Gray);

CvInvoke.PyrDown(_grayFrame, _smallGrayFrame);

CvInvoke.PyrUp(_smallGrayFrame, _smoothedGrayFrame);

CvInvoke.Canny(_smoothedGrayFrame, _cannyFrame, 100, 60);

captureImageBox.Image = _frame;
grayscaleImageBox.Image = _grayFrame;
smoothedGrayscaleImageBox.Image = _smoothedGrayFrame;
cannyImageBox.Image = _cannyFrame;
}
}

private void captureButtonClick(object sender, EventArgs e)
{
if (_capture != null)
{
if (_captureInProgress)
{ //stop the capture
captureButton.Text = "Start Capture";
_capture.Pause();
}
else
{
//start the capture
captureButton.Text = "Stop";
_capture.Start();
}

_captureInProgress = !_captureInProgress;
}
}

private void ReleaseData()
{
if (_capture != null)
_capture.Dispose();
}

private void FlipHorizontalButtonClick(object sender, EventArgs e)
{
if (_capture != null) _capture.FlipHorizontal = !_capture.FlipHorizontal;
}

private void FlipVerticalButtonClick(object sender, EventArgs e)
{
if (_capture != null) _capture.FlipVertical = !_capture.FlipVertical;
}
...全文
395 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧