admin 管理员组

文章数量: 1184232

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);
            }
        }

本文标签: 摄像头 构建实用 摄像头的