资源简介

OpenCvSharp打开摄像头,VideoCapture,OpenCv,Mat,相机,Camera。内有编译好的程序,可以直接运行

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System.Threading;
using System.IO;

namespace IDCamera
{
    public partial class Form_Main : Form
    {
        private static VideoCapture m_vCapture;
        private static bool bPlayflag = false;//摄像头打开关闭状态
        private static bool bTakePicture = false;//拍照
        Thread ThreadCam;  //摄像头播放线程          
        private static string AppPath;//程序当前目录
        private static string PicSavePath;  //拍照保存路径

        public Form_Main()
        {
            InitializeComponent();
        }

        private void btn_play_Click(object sender EventArgs e)
        {
            if (!bPlayflag)
            {
                m_vCapture = new VideoCapture(CaptureDevice.Any);
                if (!m_vCapture.IsOpened())
                {
                    MessageBox.Show(“摄像头打不开“ “摄像头故障“ MessageBoxButtons.OK MessageBoxIcon.Error);
                    return;
                }
                m_vCapture.Set(CaptureProperty.frameWidth 640);//宽度
                m_vCapture.Set(CaptureProperty.frameHeight 480);//高度

                bPlayflag = true;
                ThreadCam = new Thread(Play_Camera);
                ThreadCam.Start();

                pic_cam.Image = null;
                btn_play.Text = “关闭摄像头“;
            }
            else
            {
                bPlayflag = false;
                ThreadCam.Abort();
                m_vCapture.Release();
                btn_play.Text = “打开摄像头“;
            }
        }

        //多线程设置PictureBox的图像
        private void SetPictureBoxImage(PictureBox control Bitmap value)
        {
            control.Invoke(new Action((ct v) => { ct.Image = v; }) new object[] { control value });
        }

        private void Play_Camera()
        {
            while (bPlayflag)
            {
                //Thread.Sleep(40);
                Mat cframe = new Mat();
                m_vCapture.Read(cframe);
                int sleepTime = (int)Math.Round(1000 / m_vCapture.Fps);
                Cv2.WaitKey(sleepTime);

                if (cframe.Empty())
                {
                    continue;
                }
                Cv2.Flip(cframe cframe OpenCvSharp.FlipMode.Y);
                Rect cMaxrect = new Rect(170 90 300 300);
                if (bTakePicture)//拍照,截取指定区域
                {                    
                    Mat cHead = new Mat(cframe cMaxrect);
                    Cv2.ImWrite(PicSavePath cHead);
                    SetPictureBoxImage(pic_head cHead.ToBitmap());
                    cHead.Release();
                    bTakePicture = false;
                }
                //绘制指定区域(人脸框)
         

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         184  2019-07-16 11:41  IDCamera\App.config
     目录           0  2019-07-16 09:22  IDCamera\bin\
     目录           0  2019-07-16 09:22  IDCamera\bin\Debug\
     目录           0  2019-07-16 14:19  IDCamera\bin\Release\
     文件       22312  2019-07-16 14:11  IDCamera\bin\Release\Capture.jpg
     目录           0  2019-07-16 14:01  IDCamera\bin\Release\dll\
     目录           0  2019-07-16 14:01  IDCamera\bin\Release\dll\x64\
     文件    18652160  2019-03-21 16:02  IDCamera\bin\Release\dll\x64\opencv_ffmpeg400_64.dll
     文件    51385344  2019-03-21 16:02  IDCamera\bin\Release\dll\x64\OpenCvSharpExtern.dll
     目录           0  2019-07-16 14:01  IDCamera\bin\Release\dll\x86\
     文件    17654272  2019-03-21 16:02  IDCamera\bin\Release\dll\x86\opencv_ffmpeg400.dll
     文件    33373696  2019-03-21 16:02  IDCamera\bin\Release\dll\x86\OpenCvSharpExtern.dll
     文件       24576  2019-07-16 14:20  IDCamera\bin\Release\IDCamera.exe
     文件         184  2019-07-16 11:41  IDCamera\bin\Release\IDCamera.exe.config
     文件       26112  2019-07-16 14:20  IDCamera\bin\Release\IDCamera.pdb
     文件       22656  2019-07-16 11:41  IDCamera\bin\Release\IDCamera.vshost.exe
     文件         184  2019-07-16 11:41  IDCamera\bin\Release\IDCamera.vshost.exe.config
     文件         490  2018-04-12 07:35  IDCamera\bin\Release\IDCamera.vshost.exe.manifest
     文件       39424  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.Blob.dll
     文件       15292  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.Blob.pdb
     文件       55857  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.Blob.xml
     文件      839168  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.dll
     文件       25088  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.Extensions.dll
     文件       10720  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.Extensions.pdb
     文件       13964  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.Extensions.xml
     文件      306956  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.pdb
     文件       12800  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.UserInterface.dll
     文件        3224  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.UserInterface.pdb
     文件        8968  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.UserInterface.xml
     文件     2081295  2019-03-21 16:02  IDCamera\bin\Release\OpenCvSharp.xml
     文件        4258  2019-07-16 14:20  IDCamera\Form_Main.cs
............此处省略35个文件信息

评论

共有 条评论