基本信息
源码名称:WinForm实现摄像头调用源码
源码大小:0.02M
文件格式:.zip
开发语言:C#
更新时间:2019-03-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
使用VFW进行摄像头调用,可以完成基本功能,可调用电脑内置摄像头,实现视频监控,C#语言编写的,适合人脸身份采集和安防工程。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Net.Sockets;
using SevenZ.WebCamera;
using SevenZ.ImageProcessing;
namespace SevenZ.WebCam
{
public partial class FormMain : Form
{
int time = 0;
bool bRunning = false;
WebCameraDevice camDevice;
public FormMain()
{
InitializeComponent();
WebCameraDeviceManager camManager = new WebCameraDeviceManager();
cmbDevices.Items.AddRange(camManager.Devices);
cmbDevices.SelectedIndex = 0;
}
void camDevice_OnCameraFrame(object sender, WebCameraEventArgs e)
{
// img processing: 20-30 ms
ImageProcessing.Filters.Flip(e.Frame, false, true);
camDevice.Set();
pictureBox.Image = chkGrayScale.Checked ?
ImageProcessing.Filters.ToGrayScale(e.Frame) :
e.Frame;
this.Text = "FPS: " (1000 / (Environment.TickCount - time)).ToString();
time = Environment.TickCount;
}
private void btnStart_Click(object sender, EventArgs e)
{
if (bRunning = !bRunning)
{
camDevice = new WebCameraDevice(320, 200, 25, cmbDevices.SelectedIndex, this.Handle.ToInt32());
camDevice.OnCameraFrame = new WebCameraFrameDelegate(camDevice_OnCameraFrame);
Thread.CurrentThread.Priority = ThreadPriority.Highest;
camDevice.Start();
btnDeviceProperties.Enabled = true;
btnStart.Text = "Stop";
}
else
{
camDevice.Stop();
btnDeviceProperties.Enabled = false;
btnStart.Text = "Start";
}
}
private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
{
if(camDevice != null)
camDevice.Stop();
}
private void btnDevice_Click(object sender, EventArgs e)
{
camDevice.ShowVideoDialog();
}
}
}