aardio调用AForge操作摄像头并实现镜像旋转功能
通过Aforge的免费开源库可以方便的实现摄像头的操作功能 , 然后利用gdi对图片的各种格式化, 就可以灵活的实现摄像头的各种骚操作.
得益于aardio对C#功能的大力改进, 现在可以非常方便的对c#程序集进行各种调用, 这就意味着c#创建的各种dll都可以被aardio所用.
下面我对AForge进行了简单的封装, 让我们在aardio中非常简单的使用摄像头操作.
当然, 别的帖子里我也提供了很多种办法来实现对摄像头的采集和镜像功能 , 这篇文章, 主要是对C#程序集调用的学习.
本文首发:https://aardio.com.cn/t/21369https://aardio.com.cn/t/21369
欢迎大家来踩, 程序打包文件也在那里.
AForgeVideo.aardio 库代码:
//AForge摄像头库
import dotNet
import System.Drawing;
import System.Windows.Forms;class AForgeVideo{ctor( winform ){this.pictureBox = ..System.Windows.Forms.CreateEmbed("PictureBox",winform); this.pictureBox.BackColor = ..System.Drawing.Color.Black;this.pictureBox.SizeMode = ..System.Windows.Forms.PictureBoxSizeMode.StretchImage;this.carema = ..dotNet.load("\res\AForge.dll");this.AForgeCamera = this.carema.import("AForge.Video");this.flip = 0;this.videoDevice = null;..table.gc(this,"stop");};getNameList = function(){var videoDevices = this.AForgeCamera.DirectShow.FilterInfoCollection(this.AForgeCamera.DirectShow.FilterCategory.VideoInputDevice);var retTab = {};if(videoDevices.Count>0){for(i=0;videoDevices.Count-1;1){//压入摄像头设备号名称列表 ..table.push(retTab , videoDevices.Item[i].MonikerString);}return retTab; }return null;}getVideoCapabilitiesList = function(deviceName){if(deviceName!=null){var videoDevice = this.AForgeCamera.DirectShow.VideoCaptureDevice(deviceName);var videoCapabilitiesEx = videoDevice.VideoCapabilities;var retTab = {};if(videoCapabilitiesEx.LongLength>0){for(i=0;videoCapabilitiesEx.LongLength-1;1){..table.push(retTab,{["Width"] = videoCapabilitiesEx.Item[i].FrameSize.Width,["Height"] = videoCapabilitiesEx.Item[i].FrameSize.Height,["FrameRate"] = videoCapabilitiesEx.Item[i].FrameRate,});}return retTab;}return null; }return null;}start = function(DeviceIndex=1,index=1){if(this.videoDevice){this.videoDevice.Stop();}var namelist = this.getNameList();if(DeviceIndex <= #namelist){name = namelist[DeviceIndex];}else {//超出摄像头数量,不开启return false;} //设定帧率和分辨率var VideoCapabilities = this.getVideoCapabilitiesList(name);this.videoDevice = this.AForgeCamera.DirectShow.VideoCaptureDevice(name);if(VideoCapabilities!=null){if(index>#VideoCapabilities){index = 1;}this.videoDevice.DesiredFrameRate = VideoCapabilities[index].FrameRate;this.videoDevice.DesiredFrameSize = ..System.Drawing.Size(VideoCapabilities[index].Width,VideoCapabilities[index].Height);this.videoDevice.DesiredSnapshotSize = ..System.Drawing.Size(VideoCapabilities[index].Width,VideoCapabilities[index].Height);}this.videoDevice.NewFrame = function(sender, NewFrameEventArgs){var temp = NewFrameEventArgs.Frame.Clone();select(this.flip) {case 0 {}case 1 {temp.RotateFlip(..System.Drawing.RotateFlipType.RotateNoneFlipX);}case 2 {temp.RotateFlip(..System.Drawing.RotateFlipType.RotateNoneFlipXY);}case 3 {temp.RotateFlip(..System.Drawing.RotateFlipType.RotateNoneFlipY);}else {}}if (this.pictureBox.Image != null){this.pictureBox.Image.Dispose();}this.pictureBox.Image = temp;}this.videoDevice.Start();return true;}stop = function(){if(this.videoDevice){this.videoDevice.Stop();this.videoDevice = null;}}flipLoop = function(){select(this.flip) {case 0 {this.flip=1;}case 1 {this.flip=2;}case 2 {this.flip=3;}case 3 {this.flip=0;}else {}}}
}//库代码由popdes发布/**intellisense()
AForgeVideo = AForge摄像头库
AForgeVideo(.(winform) = 创建 摄像头 界面
AForgeVideo() = !AVideo.
end intellisense**//**intellisense(!AVideo)
getNameList() = 获取摄像头设备硬件DeviceName名称列表
getVideoCapabilitiesList(.(DeviceName) = 获取指定设备的 分辨率和帧率 列表,如果不存在那么返回 null
start(.(DeviceIndex,CapabilitiesIndex) = 开启摄像头\n DeviceIndex:设备序号 , CapabilitiesIndex:分辨率和帧率表序号
stop() = 关闭摄像头
flipLoop() = 循环镜像图像,调用一次改变一次镜像方向
end intellisense**/
使用的时候非常简单, 如果你不需要设置其他的东西, 那么调用代码如下
下面是 打开两个摄像头并分别镜像的功能代码示例:
import win.ui;
/*DSG{{*/
mainForm = win.form(text="AForge 摄像头调用-aardio示例";right=1209;bottom=556)
mainForm.add(
button={cls="button";text="start";left=16;top=519;right=127;bottom=545;db=1;dl=1;z=2};
button2={cls="button";text="flip";left=142;top=519;right=254;bottom=545;db=1;dl=1;z=3};
button3={cls="button";text="stop";left=265;top=519;right=381;bottom=545;db=1;dl=1;z=4};
button4={cls="button";text="start";left=833;top=518;right=944;bottom=544;db=1;dr=1;z=6};
button5={cls="button";text="flip";left=959;top=518;right=1071;bottom=544;db=1;dr=1;z=7};
button6={cls="button";text="stop";left=1082;top=518;right=1198;bottom=544;db=1;dr=1;z=8};
custom={cls="custom";text="自定义控件";left=0;top=0;right=601;bottom=496;bgcolor=12639424;db=1;dl=1;dr=0.5;dt=1;z=1};
custom2={cls="custom";text="自定义控件";left=609;top=0;right=1210;bottom=496;bgcolor=12639424;db=1;dl=0.5;dr=1;dt=1;z=5}
)
/*}}*/import AForgeVideo;
var video = AForgeVideo(mainForm.custom);mainForm.button.oncommand = function(id,event){//默认开启序号1摄像头,分辨率为序号1的分辨率和帧率video.start();
}mainForm.button2.oncommand = function(id,event){//摄像头1镜像video.flipLoop();
}mainForm.button3.oncommand = function(id,event){//摄像头1停止video.stop();
}//定义2号摄像头
var video2 = AForgeVideo(mainForm.custom2);
mainForm.button4.oncommand = function(id,event){//开启序号2摄像头,分辨率为序号1的分辨率和帧率video2.start(2);
}mainForm.button5.oncommand = function(id,event){//摄像头2镜像video2.flipLoop();
}mainForm.button6.oncommand = function(id,event){//摄像头2停止video2.stop();
}mainForm.show();
return win.loopMessage();
aardio调用AForge操作摄像头并实现镜像旋转功能相关推荐
- vue调用电脑端摄像头实时拍照
vue调用电脑端摄像头实时拍照 需求描述 功能实现 效果展示 需求描述 点击照相机拍照,弹出照相机拍照弹窗,点击拍照按钮,截取录像的帧,点击保存,提交数据给后台. 功能实现 1.html模块 //点击 ...
- C# 调用AForge类库操作摄像头
如有雷同,不胜荣幸,若转载,请注明 最近做项目需要操作摄像头,在网上百度了很多资料,很多都是C#调用window API 发送SendMessage,实现操作摄像头,但是C#调用window API的 ...
- C# 利用Aforge调用本机摄像头完成拍照,录像
用C#做了一个简单的摄像头录像项目,记录一下. 实现功能 打开.关闭摄像头并显示相应画面 实现拍照功能 实现录像功能 实现保存图片.录像的功能 运行界面效果 winForm控件 首先安装NuGet程序 ...
- yunyang tensorflow-yolov3 Intel Realsense D435 (并发)调用两个摄像头运行识别程序并画框
只是一个测试,测试在并发运行下,同时开启两个摄像头获取视频流并调用识别函数的运行结果,以后在摄像头多的情况下,肯定不能这样,需要批量创建各种对象. 并发,指的是不在多线程的情况下,每个摄像头的视频流送 ...
- opencv镜像_DX200操作要领—PAM与镜像平移变换(三十八)
6.4 PAM功能 6.4.1 PAM功能 再现中的位置修改功能 (PAM 功能:Position Adjustment Manual) ,可在查看机器人动作状况的同时,在不停止机器人的情况下,通过简 ...
- JAVA使用摄像头录制_JavaCV开发详解之1:调用本机摄像头视频(建议使用javaCV最新版本)...
引入依赖 org.bytedeco javacv 1.5.3 org.bytedeco javacv-platform 1.5.3 代码实现 package com.java.mmzsblog; im ...
- vue实现PC端调用摄像头拍照人脸录入、移动端调用手机前置摄像头人脸录入、及图片旋转矫正、压缩上传base64格式/文件格式
PC端调用摄像头拍照上传base64格式到后台,这个没什么花里胡哨的骚操作,直接看代码 (canvas + video) <template><div><!--开启摄像头 ...
- java录制视频_javacv开发详解之1:调用本机摄像头视频(建议使用javaCV最新版本)...
javaCV系列文章: ' i# f% S' a# J9 X! w- g) wjavacv开发详解之1:调用本机摄像头视频 4 r' C, [4 ?' M7 Y; }javaCV开发详解之2:推流器实 ...
- Matlab 2020a 调用usb3.0摄像头实例
## Matlab 2020a 调用usb3.0摄像头实例 相机为大恒水星,型号为(MER-301-125U3C-L) 调用摄像头之前,先在命令行输入代码 imaqhwinfo 看电脑自身是否已下载该 ...
最新文章
- python创建mysql数据库_python 怎么创建create mysql的数据库
- 跨域解决方案一:使用CORS实现跨域
- [原创 - 尚学堂科技 - 马士兵老师]
- 移动服务安全现状分析!
- PHP能不能让一串代码现实,一段让你认清现实的Java代码.java
- 安装veket到移动硬盘NTFS分区
- 基于深度学习的磁环表面缺陷检测算法
- Let‘s Encrypt 免费Https证书
- Java面试之设计模式七大原则
- Android学习--写一个发送短信的apk,注意布局文件的处理过程!!!
- 2018-2019-1 20165320 《信息安全系统设计基础》第八周学习总结
- 从SVN检出项目下载到本地后出现错误
- 简洁实用jQuery进度条插件
- GMS Apps安装
- 图片怎么转换成文字?几个好用的方法快来查阅
- CF 1368G Shifting Dominoes
- 软件的生命周期及模型
- 新浪财经隆重推出四大千万级财经博客
- PHP 识别获取身份证号代表的信息
- 记一次息屏指纹解锁性能优化实现
热门文章
- 安装SQL Server2008 r2 提示SQL Server 2005 Express 工具失败和完全卸载SQL Server数据库操作流程
- EditPlus 3编辑文本部分字体颜色调整-代码
- Matlab2020a使用Simulink绘制bode图
- angular+TS实现搜索关键字高亮
- 示波器的采样率相关知识分享
- 计算机操作系统第五章测试题及答案
- Theory: While loop(理论:While循环)
- 生物信息学期刊与会议
- VS2022身份证号码信息验证器
- 小白必看,关于如何在Ubuntu16.04中安装ROS,以及安装过程遇到的错误怎么解决。