经过N多调研,最终选择了OpenCV(Emgu CV)

** 至于DirectShow, OpenCV等等其他大家可以百度,在这里我就不再赘述

环境:vs2010 vs2012 vs2013均可

OpenCV官方网站为:Emgu CV

也可以去我的百度网盘下载安装包:libemgucv-windows-universal-cuda-2.4.10.1940

然后就可以自己想怎么玩,怎么玩了。

安装好后:

我的一个Demo,用来打开摄像头:

下载地址:c#调用摄像头

代码结构:

运行效果:

核心代码解释:

namespace CameraCapture
{
public partial class CameraCapture : Form
{
private readonly Capture _capture;
private bool _captureInProgress; public CameraCapture()//构造函数
{
InitializeComponent();
try
{
_capture = new Capture();//构造一个摄像头实例
_capture.ImageGrabbed += ProcessFrame;//图像捕捉事件
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
} private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> frame = _capture.RetrieveBgrFrame();//获取视频帧 Image<Gray, Byte> grayFrame = frame.Convert<Gray, Byte>();
Image<Gray, Byte> smallGrayFrame = grayFrame.PyrDown();
Image<Gray, Byte> smoothedGrayFrame = smallGrayFrame.PyrUp();
Image<Gray, Byte> cannyFrame = smoothedGrayFrame.Canny(, ); captureImageBox.Image = frame;
grayscaleImageBox.Image = grayFrame;
smoothedGrayscaleImageBox.Image = smoothedGrayFrame;
cannyImageBox.Image = cannyFrame; //转成图片并显示在主界面上
} private void CaptureButtonClick(object sender, EventArgs e)
{
if (_capture != null)
{
if (_captureInProgress)
{
//stop the capture
captureButton.Text = "Start Capture";
_capture.Pause();
}
else
{
//start the capture
captureButton.Text = "Stop";
_capture.Start();
} _captureInProgress = !_captureInProgress;
}
} private void ReleaseData()//释放资源
{
if (_capture != null)
_capture.Dispose();
} private void FlipHorizontalButtonClick(object sender, EventArgs e)
{
if (_capture != null) _capture.FlipHorizontal = !_capture.FlipHorizontal;
} private void FlipVerticalButtonClick(object sender, EventArgs e)
{
if (_capture != null) _capture.FlipVertical = !_capture.FlipVertical;
}
}
}

扩展

emgucv不仅可以控制摄像头,而且可以直接播放本地视频,但是需要一些配置

        public CameraCapture()
{
InitializeComponent();
try
{
//_capture = new Capture();
var fileName = "文件地址";
_capture = new Capture(fileName);
_capture.ImageGrabbed += ProcessFrame;
}
catch (NullReferenceException excpt)
{
MessageBox.Show(excpt.Message);
}
}

需要下载两个第三方文件:

opencv_ffmpeg.dll

opencv_ffmpeg_64.dll

三方插件可以去 github opencv  下载 三方控件,我的百度网盘:opencv_ffmpeg

这两个文件需要再重新改下名字(因为加进去报错,始终用不起,谷歌了好半天):

opencv_ffmpeg.dll opencv_ffmpegVersion.dll -> opencv_ffmpeg_64.dll

opencv_ffmpeg_64.dll opencv_ffmpegVersion_64.dll -> opencv_ffmpeg_64.dll

最后复制加到bin目录下的 x86,x64 下就可以播放本地视频了

效果如下:

有问题可以站内信

最新文章

  1. Hadoop学习笔记—10.Shuffle过程那点事儿
  2. 如何通过ShadowSocket自动更新Chrome
  3. 使用Quicktime 实现视频直播(Live video using Quicktime) (转)
  4. SPL--Serializable
  5. js中退出语句break,continue和return 比较 (转载)
  6. WinForm 批量设置指定控件中的控件状态
  7. 结合setTimeout和clearTimeout,实现“返回顶部”的功能
  8. Ubuntu环境下手动配置ant
  9. struts2 获取前台表单的值?? 原理??
  10. TCP/IP协议简单介绍
  11. Nullable问题
  12. combo下拉列表选择
  13. 使用rowid和rownum获取记录时要注意的问题
  14. mongodb集群【】
  15. 记录一次DataTable排序的问题
  16. spring + mybatis配置及网络异常设置
  17. [leetcode.com]算法题目 - Symmetric Tree
  18. How Vmware snapshots works
  19. layui——上传图片,并实现放大预览
  20. ios6:新特征介绍

热门文章

  1. [Spice-devel] usbredir for Windows Client
  2. 纯CSS完美实现垂直水平居中的6种方式
  3. thinkPHP配置项
  4. jquery 延迟加载代码
  5. HBase 和 MongoDB在设计上的区别
  6. cocos2d-x Sprite
  7. 关于Mysql Can&#39;t connect to mysql server on localhost(10061)的问题解决
  8. PS自定义对象二_PSCustomObject
  9. [VirtualBox] Install Ubuntu 14.10 error 5 Input/output error
  10. pomelo 服务器开发常用术语