作为研究计算机视觉的一员,大家肯定对Intel大名鼎鼎的openCV系列计算机视觉库耳熟能详,对于很多人来说openCV甚至已经成为其项目研究不可缺少的一部分。但是,由于项目兼容性的要求、openCV的GUI功能不够丰富等原因很多人希望能够在C#环境中使用openCV。
在目前针对c#的计算机视觉库主要有两种,EmguCV和openCVSharp。
Emgucv的优势在于不仅仅提供了计算机视觉函数接口并且提供了一系列界面控件接口,但目前只支持openCV1的书写风格。
openCVSharp提供了openCV和openCV2两种书写风格,并且和openCV的imagewatch一样,提供了一种简单有效的调试工具Debugger Visualizer,具体使用可见一下网址
https://github.com/shimat/opencvsharp/wiki/Debugger-Visualizer。
在这里我的推荐是使用openCVSharp,在这里主要考虑的是协议方面的问题。opencv的协议是BSD协议,这是对开发者来说是相当友好的协议;网上常见的免费版EmguCV则是GUN协议,任何发表都需要至少公布你的源代码;openCVSharp则是相对温和多的LGUN协议,这个协议和QT是差不多相同的,甚至当你不使用自带的DLL时,和openCV一样是BSD协议(如果你对协议感兴趣的话可以自行百度)。
具体配置方法可以自行百度,简单来说就是添加相应的com组件(注意有一个com组件右键添加,只能手动放在相应的exe目录下),然后添加相应的命名空间。
下面分别是c和c++风格的代码,获取相应位置像素值,速度由慢向快排列。

//c风格代码
//方案一
IplImage img = new IplImage("baz.png", LoadMode.Color);

for (int y = 0; y < img.Height; y++) {
for (int x = 0; x < img.Width; x++) {
CvColor c = img[y, x];
img[y, x] = new CvColor() {
B = (byte)Math.Round(c.B * 0.7 + 10),
G = (byte)Math.Round(c.G * 1.0),
R = (byte)Math.Round(c.R * 0.0),
};
}
}

//方案二
IplImage img = new IplImage("baz.png", LoadMode.Color);

unsafe {
byte* ptr = (byte*)img.ImageData;
for (int y = 0; y < img.Height; y++) {
for (int x = 0; x < img.Width; x++) {
int offset = (img.WidthStep * y) + (x * 3);
byte b = ptr[offset + 0]; // B
byte g = ptr[offset + 1]; // G
byte r = ptr[offset + 2]; // R
ptr[offset + 0] = r;
ptr[offset + 1] = g;
ptr[offset + 2] = b;
}
}
}

方案三
IplImage img = new IplImage("baz.png", LoadMode.Color);
IntPtr ptr = img.ImageData;

for (int x = 0; x < image.Width; x++) {
for (int y = 0; y < image.Height; y++) {
int offset = (image.WidthStep * y) + (x * 3);
byte b = Marshal.ReadByte(ptr, offset + 0); // B
byte g = Marshal.ReadByte(ptr, offset + 1); // G
byte r = Marshal.ReadByte(ptr, offset + 2); // R
Marshal.WriteByte(ptr, offset, r);
Marshal.WriteByte(ptr, offset, g);
Marshal.WriteByte(ptr, offset, b);
}
}

//c++风格代码
//方案一
Mat mat = new Mat("lenna.png", LoadMode.Color);

for (int y = 0; y < mat.Height; y++)
{
for (int x = 0; x < mat.Width; x++)
{
Vec3b color = mat.Get<Vec3b>(y, x);
byte temp = color.Item0;
color.Item0 = color.Item2; // B <- R
color.Item2 = temp; // R <- B
mat.Set<Vec3b>(y, x, color);
}
}
GenericIndexer (reasonably fast)

//方案二
Mat mat = new Mat("lenna.png", LoadMode.Color);

var indexer = mat.GetGenericIndexer<Vec3b>();
for (int y = 0; y < mat.Height; y++)
{
for (int x = 0; x < mat.Width; x++)
{
Vec3b color = indexer[y, x];
byte temp = color.Item0;
color.Item0 = color.Item2; // B <- R
color.Item2 = temp; // R <- B
indexer[y, x] = color;
}
}

方案三
Mat mat = new Mat("lenna.png", LoadMode.Color);

MatOfByte3 mat3 = new MatOfByte3(mat); // cv::Mat_<cv::Vec3b>
var indexer = mat3.GetIndexer();

for (int y = 0; y < mat.Height; y++)
{
for (int x = 0; x < mat.Width; x++)
{
Vec3b color = indexer[y, x];
byte temp = color.Item0;
color.Item0 = color.Item2; // B <- R
color.Item2 = temp; // R <- B
indexer[y, x] = color;
}
}

最后,openCVSharp下载地址为https://github.com/shimat/opencvsharp/releases。如果,无法下载私信我,我可以提供2.4.10、3.1和3.2三种版本。
---------------------
作者:小立1991
来源:CSDN
原文:https://blog.csdn.net/qq_21400315/article/details/52451941
版权声明:本文为博主原创文章,转载请附上博文链接!

c#计算机视觉库openCVSharp的更多相关文章

  1. 介绍n款计算机视觉库/人脸识别开源库/软件

    计算机视觉库 OpenCV OpenCV是Intel®开源计算机视觉库.它由一系列 C 函数和少量 C++ 类构成,实现了图像处理和计算机视觉方面的很多通用算法. OpenCV 拥有包括 300 多个 ...

  2. AR、美颜、机器人:计算机视觉库几乎无所不在

    最近日本推出的反美颜应用Primo可能让感到不胜惶恐.其实,这样反人类的应用,你也能写出,不过必须了解的一些技术,就是计算机视觉.目前,计算机视觉库包括FastCV.OpenCV.JavaCV等. 相 ...

  3. 计算机视觉库 SimpleCV

    SimpleCV首页.文档和下载 - 计算机视觉库 - 开源中国社区     计算机视觉库 SimpleCV 编辑/纠错    分享到     新浪微博腾讯微博    已用    +0    收藏 + ...

  4. 64位Win7下编译Python3的计算机视觉库:OpenCV

    注:本文全原创,作者:Noah Zhang  (http://www.cnblogs.com/noahzn/) OpenCV目前最新版是3.0.0 rc1,官方给出了编译好的Python2可以直接使用 ...

  5. OpenCV(Open Source Computer Vision Library)计算机视觉库

    OpenCV(最基本的滤波到高级的物体检测皆有涵盖) 简介: OpenCV 是跨平台的,可以在  Windows.Linux.Mac OS.Android.iOS 等操作系统上运行. OpenCV 的 ...

  6. 值得推荐的C/C++框架和库

    值得推荐的C/C++框架和库 [本文系外部转贴,原文地址:http://coolshell.info/c/c++/2014/12/13/c-open-project.htm]留作存档 下次造轮子前先看 ...

  7. [转载]C/C++框架和库

    C/C++框架和库 装载自:http://blog.csdn.net/xiaoxiaoyeyaya/article/details/42541419 值得学习的C语言开源项目 Webbench Web ...

  8. python常用库

    本文由 伯乐在线 - 艾凌风 翻译,Namco 校稿.未经许可,禁止转载!英文出处:vinta.欢迎加入翻译组. Awesome Python ,这又是一个 Awesome XXX 系列的资源整理,由 ...

  9. 1.值得推荐的C/C++框架和库 (转)

    值得学习的C语言开源项目 - 1. Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我们设定的URL,测试网站在压力下工作的 ...

随机推荐

  1. matlab安装 macos

    http://pan.baidu.com/s/1o6qKdxo内附安装说明Matlab R2014A Mac & Linux 破解版 readme文件有流程!可以安装

  2. C# CreateParams的使用(解决闪屏问题)

    <转载自:https://blog.csdn.net/xpwang/article/details/53427479> 窗体和控件的属性CreateParams(这真的是一个属性)很神奇, ...

  3. Edge-assisted Traffic Engineering and applications in the IoT

    物联网中边缘辅助的流量工程和应用 本文为SIGCOMM 2018 Workshop (Mobile Edge Communications, MECOMM)论文. 笔者翻译了该论文.由于时间仓促,且笔 ...

  4. 1.9 From Native to HTML5

    The mobile technology has become more and more mature, and it has evolved from a ridiculous situatio ...

  5. Dubbo+zookeeper构建高可用分布式集群(二)-集群部署

    在Dubbo+zookeeper构建高可用分布式集群(一)-单机部署中我们讲了如何单机部署.但没有将如何配置微服务.下面分别介绍单机与集群微服务如何配置注册中心. Zookeeper单机配置:方式一. ...

  6. Java synchronized和 Lock 的区别与用法

    在分布式开发中,锁是线程控制的重要途径.Java为此也提供了2种锁机制,synchronized和lock.做为Java爱好者,自然少不了对比一下这2种机制,也能从中学到些分布式开发需要注意的地方.  ...

  7. JDK 8 之 Stream sorted() 示例

    原文链接:http://www.concretepage.com/java/jdk-8/java-8-stream-sorted-example 国外对Java8一系列总结的不错, 翻译过来给大家共享 ...

  8. [Swift]LeetCode220. 存在重复元素 III | Contains Duplicate III

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  9. [Swift]LeetCode645. 错误的集合 | Set Mismatch

    The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of ...

  10. [Swift]LeetCode951. 翻转等价二叉树 | Flip Equivalent Binary Trees

    For a binary tree T, we can define a flip operation as follows: choose any node, and swap the left a ...