当前位置: 首页 > news >正文

C# OpenCvSharp 读取rtsp流

效果

 项目

 代码

using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;namespace OpenCvSharp_读取rtsp流
{public partial class Form1 : Form{public Form1(){InitializeComponent();}CancellationTokenSource cts;VideoCapture capture;private void button1_Click(object sender, EventArgs e){if (textBoxIP.Text == "" || textBoxPort.Text == "" ||textBoxUserName.Text == "" || textBoxPassword.Text == ""){MessageBox.Show("Please input IP, Port, User name and Password!");return;}String rtspUrl = string.Format("rtsp://{0}:{1}@{2}:{3}", textBoxUserName.Text, textBoxPassword.Text, textBoxIP.Text, textBoxPort.Text);button1.Enabled = false;button2.Enabled = true;cts = new CancellationTokenSource();Task task = new Task(() =>{capture.Open(rtspUrl, VideoCaptureAPIs.ANY);if (capture.IsOpened()){//var dsize = new System.Windows.Size(capture.FrameWidth, capture.FrameHeight);Mat frame = new Mat();while (true){Thread.Sleep(10);//判断是否被取消;if (cts.Token.IsCancellationRequested){pictureBox1.Image = null;return;}//Read imagecapture.Read(frame);if (frame.Empty())continue;if (pictureBox1.Image != null){pictureBox1.Image.Dispose();}pictureBox1.Image = BitmapConverter.ToBitmap(frame);}}}, cts.Token);task.Start();}private void Form1_Load(object sender, EventArgs e){capture = new VideoCapture();}private void button2_Click(object sender, EventArgs e){button2.Enabled = false;button1.Enabled = true;cts.Cancel();}private void Form1_FormClosing(object sender, FormClosingEventArgs e){if (capture != null){capture.Release();capture.Dispose();}}}
}

Demo下载

http://www.lryc.cn/news/120178.html

相关文章:

  • 每日后端面试5题 第七天
  • 计算机视觉的应用10-图片中的表格结构识别与提取实战
  • P4178 Tree (点分治)
  • Kubernetes 二进制搭建
  • QT QtXlsx安装使用
  • Java医院信息化HIS管理系统源码
  • 【Uni-App】uview 开发多端应用,密码显示隐藏功能不生效问题
  • 人工智能算法-SVM, KNN
  • 计算机网络—TCP
  • Oracle到DM实时数据同步实施方案
  • WebRTC | 音视频实时通信的本质
  • ApiPost的使用
  • 6、CCS 配置工程头文件批量添加路径的方法
  • Visual Studio配置PCL库
  • 数据分析 | 为什么Bagging算法的效果优于单个评估器
  • mysql架构介绍
  • EIK+Filebeat+Kafka
  • python安装xgboost报错
  • 语音芯片的型号有哪些?为什么强烈推荐使用flash型可擦写的
  • 【OpenCV常用函数:轮廓检测+外接矩形检测】cv2.findContours()+cv2.boundingRect()
  • opencv,opengl,osg,vulkan,webgL,opencL,cuda
  • golang拥有wireshark数据包解析能力
  • Redis_分片集群
  • 测试提升方向:你选测试开发?还是性能测试?
  • 无涯教程-Perl - print函数
  • python搜索文件夹内类似的文件名
  • [保研/考研机试] KY3 约数的个数 清华大学复试上机题 C++实现
  • cmake扩展(2)——windows下动态设置输出文件(dll/exe)版本
  • Python-OpenCV中的图像处理-颜色空间转换
  • yolov5目标检测多线程Qt界面