C#引用AForge调取系统摄像头来拍摄
出于驿站的出库系统需求,经过3个月的各项技术摸索,才完成了这个项目
总系统包括 驿站面单+人脸自动拍照,底单处理,合并,水印存储。
驿站出库API接口 被官网关闭。
二、使用步骤
1.引入库
代码如下(示例):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using AForge;
using AForge.Video.DirectShow;
2.申明
代码如下(示例):
private bool auto;
private FilterInfoCollection videoDevices;//驱动列表
private VideoCaptureDevice video1;//视频资源
private VideoCaptureDevice video2;//视频资源
private jxBitmap jxBitmap = new jxBitmap();
private jxSound jxSound = new jxSound();
private jxTimer jxTimer = new jxTimer();
private string path = Environment.CurrentDirectory;//当前文件路径
private string pathData;//存储路径
private ini jxIni = new ini();//配置文件
private System.Media.SoundPlayer sp = new System.Media.SoundPlayer();//音频
private bool com2 = false;//采集通道数量 默认2
private int sleepZxing = 600;//识别单号速度
private int sleepLike = 3000;//启动识别之前的连接等待
private DataTable Table = new DataTable();//数据表格
private string dev1, dev2, devSize1, devSize2;
private bool up,upImage;//是否上传,是否上传图片
private string upType, upData;//上传的公司,上传的密钥
APIkuaibao ikuaibao = new APIkuaibao();
Thread thZ;
//Thread thShow;
private static ManualResetEvent _eventWorkList = new ManualResetEvent(false);
3.基本功能
代码如下(示例):
/// <summary>
/// 获取视频输入列表
/// </summary>
private void getc()
{
//FilterInfoCollection videoDevices;
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
}
/// <summary>
/// 连接摄像头
/// </summary>
private void like()
{
//GetAppSet();//配置文件
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);//列表
int selectedDeviceIndex = 0;//驱动
while (selectedDeviceIndex< videoDevices.Count)
{
if (videoDevices[selectedDeviceIndex].MonikerString == dev1)
{
videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
video1 = new VideoCaptureDevice(videoDevices[selectedDeviceIndex].MonikerString);//连接摄像头。
video1.VideoResolution = video1.VideoCapabilities[int.Parse(devSize1)];
videoSourcePlayer1.VideoSource = video1;
videoSourcePlayer1.Start();
}