1.新建C#项目
2.在项目上右键选择管理Nuget程序包,如下安装OpenCcSharp3-AnyCPU.
using OpenCvSharp;
using OpenCvSharp.Blob;
using OpenCvSharp.UserInterface;
using OpenCvSharp.Extensions;
private void CaptureCameraCallback()
{
Mat frame = new Mat();
//videocapture后面参数为0表示获取电脑本机摄像头的内容
//如果输入rtsp地址就是获取网络摄像头的拍摄内容,rtsp地址可由摄像头厂家提供
//已大华为例 rtsp://用户名:密码@ip:port
capture = new VideoCapture(this.textBoxUrl.Text.Trim());
int sleeptime = (int)Math.Round(1000 / capture.Fps);
while (isCameraRunning)
{
capture.Read(frame);
if (frame.Empty())
{
break;
}
Bitmap image = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(frame);
if (pictureBox1.Image != null)
{
pictureBox1.Image.Dispose();
}
pictureBox1.Image = image;
Cv2.WaitKey(sleeptime);
}
}

本文介绍了如何在C#项目中通过Nuget管理器安装OpenCcSharp3-AnyCPU库,从而实现打开和操作摄像头的功能,特别是对于RTSP流的支持。
最低0.47元/天 解锁文章
290

被折叠的 条评论
为什么被折叠?



