aforge java_C#:视频与图像抓取(二)AForge.NET + WPF | 春小麦
同系列文章:
功能说明
基于AForge.NET实现视频与图像抓取
开发工具
Visual Studio v2015
.NET Framework 4 Client Profile
WPF与WinForm控件交互
要实现视频功能,需要使用AForge.Controls命名空间中的VideoSourcePlayer控件。这是一个WinForm控件,要在WPF程序中使用,我们需要做如下4步:
添加引用:
在.NET选项卡中选择WindowsFormsIntegration
在浏览选项卡中添加3个AForge.NET类库
AForge.Controls.dll
AForge.Video.dll
AForge.Video.DirectShow.dll
在XAML中添加System.Windows.Forms.Integration命名空间
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
在XAML中添加AForge.Controls命名空间
xmlns:aforge ="clr-namespace:AForge.Controls;assembly=AForge.Controls"
在XAML中加入VideoSourcePlayer可视控件
演示程序界面
源代码下载
源代码
MainWindow.xaml
xmlns:wfi ="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:aforge ="clr-namespace:AForge.Controls;assembly=AForge.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:Splash;assembly=FingerPictureBox"
Title="FaceCapture-AForgeNET-WPF" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="480" d:DesignWidth="902" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" AllowDrop="True" Closing="Window_Closing">
MainWindow.xaml.cs
/* ----------------------------------------------------------
文件名称:MainWindow.xaml.cs
作者:秦建辉
微信:splashcn
博客:http://www.firstsolver.com/wordpress/
开发环境:
Visual Studio V2015
.NET Framework 4 Client Profile
AForge.NET 2.2.5
版本历史:
V1.02016年11月01日
基于AForge.NET实现视频与图像抓取
参考资料:
http://www.aforgenet.com/framework/
------------------------------------------------------------ */
using AForge.Video.DirectShow;
using System;
using System.Windows;
using System.Windows.Media.Imaging;
namespace Splash
{
///
/// MainWindow.xaml 的交互逻辑
///
public partial class MainWindow : Window
{
BitmapSource ImagePlay;
BitmapSource ImageStop;
public MainWindow()
{
InitializeComponent();
// 设置窗体图标
this.Icon = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(
Properties.Resources.FingerPictureBox.Handle,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
// 图像源初始化
ImagePlay = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Properties.Resources.Button_Play_icon2.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
ImageStop = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Properties.Resources.Button_Stop_icon.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
// 设置按钮图像
image_Play.Source = ImagePlay;
image_Capture.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Properties.Resources.capture.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
// 设置窗体装载后事件处理器
this.Loaded += new RoutedEventHandler(MainWindow_Loaded);
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{ // 设定初始视频设备
comboBoxVideoDevices.ItemsSource = new FilterInfoCollection(FilterCategory.VideoInputDevice);
comboBoxVideoDevices.DisplayMemberPath = "Name";
if(comboBoxVideoDevices.Items.Count > 0)
{
comboBoxVideoDevices.SelectedIndex = 0;
if (comboBoxVideoDevices.Items.Count == 1) comboBoxVideoDevices.IsEnabled = false;
}
else
{
button_Play.IsEnabled = false;
button_Capture.IsEnabled = false;
}
// 设置图片框初始图像
BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
Properties.Resources.noimage.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
fingerPictureBox1.InitialImage = bs;
fingerPictureBox2.InitialImage = bs;
fingerPictureBox3.InitialImage = bs;
fingerPictureBox4.InitialImage = bs;
}
private void button_Play_Click(object sender, RoutedEventArgs e)
{
if (image_Play.Source == ImagePlay)
{
if (comboBoxVideoDevices.SelectedIndex != -1)
{ // 开启视频
vsp.VideoSource = new VideoCaptureDevice(((FilterInfo)comboBoxVideoDevices.SelectedItem).MonikerString);
vsp.Start();
if (vsp.IsRunning)
{ // 改变按钮为“停止”状态
image_Play.Source = ImageStop;
label_Play.Content = "停止";
// 允许拍照
button_Capture.IsEnabled = true;
}
}
}
else
{
if (vsp.IsRunning)
{ // 停止视频
vsp.SignalToStop();
vsp.WaitForStop();
// 改变按钮为“开始”状态
image_Play.Source = ImagePlay;
label_Play.Content = "开启视频"; ;
// 关闭拍照
button_Capture.IsEnabled = false;
}
}
}
private void button_Capture_Click(object sender, RoutedEventArgs e)
{
// 判断视频设备是否开启
if (vsp.IsRunning)
{ // 进行拍照
for (Int32 i = 1; i <= 4; i++)
{
object box = this.FindName("fingerPictureBox" + i);
if (box is FingerPictureBox)
{
if ((box as FingerPictureBox).ActiveImage == (box as FingerPictureBox).InitialImage)
{ // 更新图像
(box as FingerPictureBox).ActiveImage = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
vsp.GetCurrentVideoFrame().GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
break;
}
}
}
}
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (vsp.IsRunning)
{ // 停止视频
vsp.SignalToStop();
vsp.WaitForStop();
}
}
}
}
aforge java_C#:视频与图像抓取(二)AForge.NET + WPF | 春小麦相关推荐
- Wireshark抓包原理(ARP劫持、MAC泛洪)及数据流追踪和图像抓取(二)
[网络安全自学篇] 十三.Wireshark抓包原理(ARP劫持.MAC泛洪)及数据流追踪和图像抓取(二) 2019年09月22日 21:55:44 Eastmount 阅读数 3515 文章标签: ...
- 短视频评论的抓取及分析
短视频评论的抓取及分析 一.设计背景 目前,短视频已经成为大多数人娱乐消遣的主要方式.用户在观看视频内容的同时,也同样关注视频评论,并且很多时候评论带给人们的乐趣远远超过视频本身.但是各短视频平台都没 ...
- SEO网站视频链接批量抓取
网站视频SEO也包含在我们的网站优化当中,这是因为视频越来越具有吸引力,可以帮助用户在我们的网站上停留更长时间,不需要过多的思考就可以获得直观的感受,如何获取热门的短视频是我们视频SEO的关键. 通过 ...
- idm抓取网页视频原理 idm抓取网页视频后怎么提取
对于网页视频的下载,我们可以使用windows端多线程下载工具--Internet Download Manager,通过Internet Download Manager我们可以直接抓取网页视频,i ...
- 【转】 asp.net从视频文件中抓取一桢并生成图像文件的方法 实现多语言本地化应用程序 自动返回上次请求页面...
asp.net从视频文件中抓取一桢并生成图像文件的方法 http://www.bianceng.cn/webkf/aspx/201012/21428.htm WebUIValidation.js ht ...
- b站视频详情数据抓取,自动打包并发送到指定邮箱(单个或者群发)
BiLiBiLi Time: 2020年11月6日19:44:58 Author: Yblackd BiLiBiLi BiLiBiLi 介绍 软件架构 安装教程 使用说明 源码下载 BiLiBiLi ...
- [网络安全自学篇] 十三.Wireshark抓包原理(ARP劫持、MAC泛洪)及数据流追踪和图像抓取(二)
这是作者的系列网络安全自学教程,主要是关于网安工具和实践操作的在线笔记,特分享出来与博友共勉,希望您们喜欢,一起进步.前文分享了Wireshark安装入门和一个抓取网站用户名和密码的案例,本篇文章将继 ...
- 基于Emgu CV+百度人脸识别,实现视频动态 人脸抓取与识别
背景 目前AI 处于风口浪尖,作为 公司的CTO,也作为自己的技术专研,开始了AI之旅,在朋友圈中也咨询 一些大牛对于AI 机器学习框架的看法,目前自己的研究方向主要开源的 AI 库,如:Emgu C ...
- 微博--图片,视频,评论抓取
抓取思路: .手动搜索要抓取的人的主页,进去,浏览器调试找到数据接口 通过curl工具,自动成成请求代码 编辑器请求代码,获取json 解析json,得到发微博人的id,本条微博的id等基础信息,将本 ...
- 微信视频号的抓取记录
微信视频号的数据采集,已成功! 测试阶段 数据采集 是否分享开源 测试阶段 通过老旧版本的测试,发现安卓/苹果/PC抓包这些方法被Pass: 通过截取网络数据包失败: 通过HOOK方式成功: 数据采集 ...
最新文章
- Xshell远程登录Ubuntu
- java xml文件内容替换_java读取xml文件并转换成对象,并进行修改
- agx 安装ros opencv_怎样在ROS下实现基于YOLO的px4无人机目标检测?
- VTK:Math之VectorDot
- 基于360搜图爬取图片
- 分布式监控系统开发【day38】:监控trigger表结构设计(一)
- Castle 整合.NET Remoting
- glassfish 初次使用 (介绍・目录结构・注意点・基本命令・控制台・eclipse插件安装)
- 无法使用闩锁类型 sh 读取并闩锁页_InnoDB数据锁第2.5部分“锁”(深入研究)...
- 离散数学 计算机应用,计算机应用融入离散数学的思考
- xshell评估过期解决办法
- linux 命令行修改分辨率,Linux命令行(console)屏幕分辨率调整
- Jenkins File Matrix 对于label设置环境变量
- DLL的远程注入技术
- linux非连续内存,(转)linux高端内存管理之非连续内存区(分配和释放)
- 变量之间的相关性度量
- apk反编译(6)用ProGuard 混淆、压缩代码,压缩资源。
- Linux中断子系统(二)中断控制器GIC驱动分析
- 间歇性需求预测之Croston‘s method
- java新手入门学习指南
热门文章
- java面试erp项目经验_ERP项目经验总结
- Aladdin HASP SRM(AES-128)加密狗破解经验分享
- Git问题解决:warning: Pulling without specifying how to reconcile divergent branches is discouraged. You
- 网易云数据库架构设计实践
- html不存在模板,模板文件不存在,无法解析文档的解决方法
- 关灯游戏 Lights out (二)(首行枚举+位运算,搜索全部解)
- 2020计算机组成原理课程设计(桂电)
- Java突击学习 Day2 Part1
- 声网 X Yalla:面对面不如线上见,中东年轻人最偏爱的语聊房是怎样“炼”成的?
- 路由与交换技术(笔记)