資源簡介
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.xm
?????文件??????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.xm
?????文件??????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.xm
?????文件?????2081295??2019-03-21?16:02??IDCamera\bin\Release\OpenCvSharp.xm
?????文件????????4258??2019-07-16?14:20??IDCamera\Form_Main.cs
............此處省略35個文件信息
評論
共有 條評論