1.配置大华摄像机参数 检查RTSP端口号
修改分辨率,在这里我们主要设置【辅码流】 大华RTSP协议解释 访问主码流 rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=0 访问辅码流 rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1 2.opencvsharp引用:
3.opencvsharp代码示例:
获取视频流:
private void savestream() { VideoCapture cap = new VideoCapture(); cap.Open("rtsp://admin:[email protected]:554/cam/realmonitor?channel=1&subtype=1"); Mat Camera_GImg = new Mat(); string path = System.Environment.CurrentDirectory+"\\video\\666.avi"; OpenCvSharp.Size sz = new OpenCvSharp.Size(640,480); VideoWriter vw = new VideoWriter(path, FourCCCalcurator.Run('X', 'V', 'I', 'D'), cap.Fps, sz, true); while (true) { cap.Read(Camera_GImg); if (Camera_GImg.Empty()) { break; } else { vw.Write(Camera_GImg); } } }播放监控录像:
private void readvideo() { byte[] image_byte = new Byte[2048]; VideoCapture cap = new VideoCapture(); string path = System.Environment.CurrentDirectory + "\\video\\666.avi"; cap.Open(path); while (true) { Mat Camera_GImg = new Mat(); cap.Read(Camera_GImg); if (Camera_GImg.Empty()) { isopen = !isopen; break; } else { image_byte = Camera_GImg.ToBytes(); #region 图片嵌入picturebox MemoryStream ms = new MemoryStream(image_byte); ms.Position = 0; img = System.Drawing.Image.FromStream(ms); this.Invoke((EventHandler)delegate//将分线程对主线程的调用委托给主线程 { pictureBox1.BackgroundImage = img; pictureBox1.Refresh(); }); #endregion Camera_GImg.Release();//释放,别等到gc来回收,太占内存 } } }
标签:监控,GImg,cap,Camera,VideoCapture,opencvsharp,new,摄像头 From: https://www.cnblogs.com/xuexz/p/17904955.html