当前位置: 首页 > news >正文

实时定量引物设计网站怎么做/怎么做市场营销和推广

实时定量引物设计网站怎么做,怎么做市场营销和推广,动态网站标题怎么做,卓企做的网站怎么样目的 对于OpenCV的开发团队来说,持续稳定地提高代码库非常重要。我们一直在思考如何在使其易用的同时保持灵活性。新的C接口即为此而来。尽管如此,向下兼容仍然十分重要。我们并不想打断你基于早期OpenCV库的开发。因此,我们添加了一些函数来…

目的

对于OpenCV的开发团队来说,持续稳定地提高代码库非常重要。我们一直在思考如何在使其易用的同时保持灵活性。新的C++接口即为此而来。尽管如此,向下兼容仍然十分重要。我们并不想打断你基于早期OpenCV库的开发。因此,我们添加了一些函数来处理这种情况。在以下内容中你将学到:

  • 相比第一个版本,第二版的OpenCV在用法上有何改变
  • 如何在一幅图像中加入高斯噪声
  • 什么事查找表及如何使用

概述

在用新版本之前,你首先需要学习一些新的图像数据结构: Mat - 基本图像容器 ,它取代了旧的 CvMat 和 IplImage 。转换到新函数非常容易,你仅需记住几条新的原则。

OpenCV 2 接受按需定制。所有函数不再装入一个单一的库中。我们会提供许多模块,每个模块都包含了与其功能相关的数据结构和函数。这样一来,如果你仅仅需要使用OpenCV的一部分功能,你就不需要把整个巨大的OpenCV库都装入你的程序中。使用时,你仅需要包含用到的头文件,比如:

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

所有OpenCV用到的东西都被放入名字空间 cv 中以避免与其他库的数据结构和函数名称的命名冲突。因此,在使用OpenCV库中的任何定义和函数时,你必须在名称之前冠以 cv:: ,或者在包含头文件后,加上以下指令:

using namespace cv;  // 新的C++接口API都在此名字空间中,需要导入。

因为所有库中函数都已在此名字空间中,所以无需加 cv 作为前缀。据此所有新的C++兼容函数都无此前缀,并且遵循驼峰命名准则。也就是第一个字母为小写(除非是单个单词作为函数名,如 Canny)并且后续单词首字母大写(如 copyMakeBorder ).

接下来,请记住你需要将所有用到的模块链接到你的程序中。如果你在Windows下开发且用到了 动态链接库(DLL) ,你还需要将OpenCV对应动态链接库的路径加入程序执行路径中。关于Windows下开发的更多信息请阅读 How to build applications with OpenCV inside the Microsoft Visual Studio ;对于Linux用户,可参考 Using OpenCV with Eclipse (plugin CDT) 中的实例及说明。

你可以使用 IplImage 或 CvMat 操作符来转换 Mat 对象。在C接口中,你习惯于使用指针,但此处将不再需要。在C++接口中,我们大多数情况下都是用 Mat 对象。此对象可通过简单的赋值操作转换为 IplImage 和 CvMat 。示例如下:

Mat I;
IplImage pI = I;
CvMat    mI = I;

现在,如果你想获取指针,转换就变得麻烦一点。编译器将不能自动识别你的意图,所以你需要明确指出你的目的。可以通过调用 IplImage 和 CvMat 操作符来获取他们的指针。我们可以用 & 符号获取其指针如下:

Mat I;
IplImage* pI     = &I.operator IplImage();
CvMat* mI        =  &I.operator CvMat();

来自C接口最大的抱怨是它将所有内存管理工作交给你来做。你需要知道何时可以安全释放不再使用的对象,并且确定在程序结束之前释放它,否则就会造成讨厌的内存泄露。为了绕开这一问题,OpenCV引进了一种智能指针。它将自动释放不再使用的对象。使用时,指针将被声明为 Ptr 模板的特化:

Ptr<IplImage> piI = &I.operator IplImage();

将C接口的数据结构转换为 Mat 时,可将其作为构造函数的参数传入,例如:

Mat K(piL), L;
L = Mat(pI);

实例学习

现在,你已经学习了最基本的知识。 这里 你将会看到一个混合使用C接口和C++接口的例子。你也可以在可以再OpenCV的代码库中的sample目录中找到此文件samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp 。为了进一步帮助你认清其中区别,程序支持两种模式:C和C++混合,以及纯C++。如果你宏定义了 DEMO_MIXED_API_USE ,程序将按第一种模式编译。程序的功能是划分颜色平面,对其进行改动并最终将其重新合并。

 123456789
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include <iostream>#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>using namespace cv;  // The new C++ interface API is inside this namespace. Import it.
using namespace std;
#define DEMO_MIXED_API_USE int main( int argc, char** argv )
{const char* imagename = argc > 1 ? argv[1] : "lena.jpg";#ifdef DEMO_MIXED_API_USEPtr<IplImage> IplI = cvLoadImage(imagename);      // Ptr<T> is safe ref-counting pointer classif(IplI.empty()){cerr << "Can not load image " <<  imagename << endl;return -1;}Mat I(IplI); // Convert to the new style container. Only header created. Image not copied.    
#elseMat I = imread(imagename);        // the newer cvLoadImage alternative, MATLAB-style functionif( I.empty() )                   // same as if( !I.data ){cerr << "Can not load image " <<  imagename << endl;return -1;}
#endif

在此,你可一看到新的结构再无指针问题,哪怕使用旧的函数,并在最后结束时将结果转换为 Mat 对象。

1
2
3
4
5
6
    // convert image to YUV color space. The output image will be created automatically. Mat I_YUV;cvtColor(I, I_YUV, CV_BGR2YCrCb); vector<Mat> planes;    // Use the STL's vector structure to store multiple Mat objects split(I_YUV, planes);  // split the image into separate color planes (Y U V)

因为我们打算搞乱图像的亮度通道,所以首先将图像由默认的RGB颜色空间转为YUV颜色空间,然后将其划分为独立颜色平面(Y,U,V)。第一个例子中,我们对每一个平面用OpenCV中三个主要图像扫描算法(C []操作符,迭代,单独元素访问)中的一个进行处理。在第二个例子中,我们给图像添加一些高斯噪声,然后依据一些准则融合所有通道。

运用扫描算法的代码如下:

 123456789
10
11
12
13
14
15
16
17
18
19
20
21
    // Method 1. process Y plane using an iteratorMatIterator_<uchar> it = planes[0].begin<uchar>(), it_end = planes[0].end<uchar>();for(; it != it_end; ++it){double v = *it * 1.7 + rand()%21 - 10;*it = saturate_cast<uchar>(v*v/255);}for( int y = 0; y < I_YUV.rows; y++ ){// Method 2. process the first chroma plane using pre-stored row pointer.uchar* Uptr = planes[1].ptr<uchar>(y);for( int x = 0; x < I_YUV.cols; x++ ){Uptr[x] = saturate_cast<uchar>((Uptr[x]-128)/2 + 128);// Method 3. process the second chroma plane using individual element accessuchar& Vxy = planes[2].at<uchar>(y, x);Vxy =        saturate_cast<uchar>((Vxy-128)/2 + 128);}}

此处可看到,我们可以以三种方式遍历图像的所有像素:迭代器,C指针和单独元素访问方式你可在 OpenCV如何扫描图像、利用查找表和计时 中获得更深入的了解。从旧的函数名转换新版本非常容易,仅需要删除 cv 前缀,并且使用 Mat 数据结构。下面的例子中使用了加权加法:

 123456789
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
    Mat noisyI(I.size(), CV_8U);           // Create a matrix of the specified size and type// Fills the matrix with normally distributed random values (around number with deviation off).// There is also randu() for uniformly distributed random number generationrandn(noisyI, Scalar::all(128), Scalar::all(20)); // blur the noisyI a bit, kernel size is 3x3 and both sigma's are set to 0.5GaussianBlur(noisyI, noisyI, Size(3, 3), 0.5, 0.5); const double brightness_gain = 0;const double contrast_gain = 1.7;#ifdef DEMO_MIXED_API_USE// To pass the new matrices to the functions that only work with IplImage or CvMat do:// step 1) Convert the headers (tip: data will not be copied).// step 2) call the function   (tip: to pass a pointer do not forget unary "&" to form pointers)IplImage cv_planes_0 = planes[0], cv_noise = noisyI;    cvAddWeighted(&cv_planes_0, contrast_gain, &cv_noise, 1, -128 + brightness_gain, &cv_planes_0);
#elseaddWeighted(planes[0], contrast_gain, noisyI, 1, -128 + brightness_gain, planes[0]);
#endifconst double color_scale = 0.5;// Mat::convertTo() replaces cvConvertScale. // One must explicitly specify the output matrix type (we keep it intact - planes[1].type())planes[1].convertTo(planes[1], planes[1].type(), color_scale, 128*(1-color_scale));// alternative form of cv::convertScale if we know the datatype at compile time ("uchar" here).// This expression will not create any temporary arrays ( so should be almost as fast as above)planes[2] = Mat_<uchar>(planes[2]*color_scale + 128*(1-color_scale));// Mat::mul replaces cvMul(). Again, no temporary arrays are created in case of simple expressions.planes[0] = planes[0].mul(planes[0], 1./255);

正如你所见,变量 planes 也是 Mat 类型的。无论如何,将 Mat 转换为 IplImage 都可通过简单的赋值操作符自动实现。

 123456789
10
11
12
13
    merge(planes, I_YUV);                // now merge the results backcvtColor(I_YUV, I, CV_YCrCb2BGR);  // and produce the output RGB imagenamedWindow("image with grain", CV_WINDOW_AUTOSIZE);   // use this to create images#ifdef DEMO_MIXED_API_USE// this is to demonstrate that I and IplI really share the data - the result of the above// processing is stored in I and thus in IplI too.cvShowImage("image with grain", IplI);
#elseimshow("image with grain", I); // the new MATLAB style function show

新的 imshow highgui函数可接受 Mat 和 IplImage 数据结构。 编译并运行例程,如果输入以下第一幅图像,程序将输出以下第二幅或者第三幅图像。

The output of the sample

你可以在点击此处看到动态示例: YouTube here ,并可以 点击此处 下载源文件,或者在OpenCV源代码库中找到源文件:samples/cpp/tutorial_code/core/interoperability_with_OpenCV_1/interoperability_with_OpenCV_1.cpp 。

http://www.jmfq.cn/news/4838743.html

相关文章:

  • 做最好的win7系统下载网站/注册网站流程
  • 有做国外婚恋交友网站/东莞市网络seo推广服务机构
  • 2核4g做网站/词爱站的关键词
  • 柴油网站怎么做/网站查询关键词排名软件
  • 建筑木工模板包工价格/seo技术分享
  • 网站建设到发布2012sevser/2023新冠结束了吗
  • 网站 ca证书怎么做/关键词排名零芯互联排名
  • 如何选择网站建设案例/baidu百度
  • 企业网站建设webbj/南宁网站快速排名提升
  • 河北网站建设团队/网站优化关键词排名
  • 佛山市住房与城乡建设局网站/杭州网站推广优化公司
  • 佘山做网站/大数据营销成功案例
  • 北京游戏网站建设/怎么做线上销售
  • 外贸网站建设 广州/外国网站的浏览器
  • 助听器网站建设方案草稿/优秀网页设计
  • 做商城网站会不会被攻击/免费做推广的网站
  • 做书的网站有哪些内容吗/日本关键词热搜榜
  • dw内部网站链接怎么做/设计网站用什么软件
  • 天网网站建设/百姓网
  • 邯郸哪里做网站好/站内推广方案
  • 网站建设费计入那个科目/百度竞价排名商业模式
  • 网站怎么查哪家公司做的/南京市网站
  • 个人做电影网站服务器放国外安全吗/怎么在百度免费推广
  • 南充网站建设公司/网站推广关键词工具
  • wordpress改logo/整站seo服务
  • 开通建立企业网站/优化师是一份怎样的工作
  • wordpress用户前端创建相册/seo是指搜索引擎营销
  • 企业网站用户群/网络口碑营销的成功案例
  • 兰州论坛网站建设/黄石seo
  • 坪山公司网站建设/站长统计是什么意思