这里举出三个案例:

#include <cv.h>
#include <highgui.h> void image_smooth(IplImage * image)
{
cvNamedWindow("#1image input");
cvShowImage("#1image input", image); /* create 8 bit 3 channel image*/
IplImage *out_image = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 3);
/* smooth 3*3 around every point */
cvSmooth(image, out_image, CV_GAUSSIAN, 3, 3);
cvNamedWindow("#1image output");
cvShowImage("#1image output", out_image); cvReleaseImage(&out_image);
cvWaitKey(0); cvDestroyWindow("#1image input");
cvDestroyWindow("#1image output");
} IplImage *doPyrDown(IplImage *in)
{
IplImage *out = cvCreateImage(cvSize(in->width/2, in->height/2) ,in->depth, in->nChannels);
cvPyrDown(in, out);
return out;
} IplImage *doCanny(IplImage *in, double lowTh, double highTh, double aperture)
{
//3 channel is ok
printf("channels = %d\n", in->nChannels);
//if(1 != in->nChannels)
// return NULL;
printf("start processing...\n");
IplImage *out = cvCreateImage(cvGetSize(in), IPL_DEPTH_8U, 1);
cvCanny(in, out, lowTh, highTh, aperture);
return out;
} int main(int argc,char **argv)
{ printf("this is image transforming\n");
IplImage *image;
/* todo:how to judge load fail?*/
image = cvLoadImage(argv[1]); if(argc != 2)
{
std::cout << "No image data\n";
return -1;
} /*
image_smooth(image);
*/ cvNamedWindow("image input");
cvNamedWindow("image output");
//IplImage *img1 = doPyrDown(image);//#1
IplImage *img1 = doCanny(image, 10, 100, 3);//#2 cvShowImage("image input", image);
cvShowImage("image output", img1);
cvReleaseImage(&image);
cvReleaseImage(&img1);
cvWaitKey(0);
cvDestroyWindow("image input");
cvDestroyWindow("image output"); return 0;
}

其中,

image_smooth

是将图像平滑处理。

其中关键的一行是

	cvSmooth(image, out_image, CV_GAUSSIAN, 3, 3);

效果如下:

这样处理后,图片变模糊了。

doPyrDown

是图像变成原来的0.25倍,它调用的

cvPyrDown

函数对于传入参数有较严格的要求,传入的两个图像要接近0.25倍,详情看官方文档.

doCanny

是进行边缘检测,虽然书中不支持三通道的,但是代码里面是支持的,所以我直接传了张一般的图片进去。。

效果如下(女神 奥黛丽·赫本):

Opencv step by step - 图像变换的更多相关文章

  1. Step by step Dynamics CRM 2011升级到Dynamics CRM 2013

    原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...

  2. Step by Step 创建一个新的Dynamics CRM Organization

    原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...

  3. Step by step Install a Local Report Server and Remote Report Server Database

    原创地址:http://www.cnblogs.com/jfzhu/p/4012097.html 转载请注明出处 前面的文章<Step by step SQL Server 2012的安装 &g ...

  4. Step by step Dynamics CRM 2013安装

    原创地址:http://www.cnblogs.com/jfzhu/p/4008391.html 转载请注明出处   SQL Server可以与CRM装在同一台计算机上,也可安装在不同的计算机上.演示 ...

  5. Step by step 活动目录中添加一个子域

    原创地址:http://www.cnblogs.com/jfzhu/p/4006545.html 转载请注明出处 前面介绍过如何创建一个域,下面再介绍一下如何在该父域中添加一个子域. 活动目录中的森林 ...

  6. SQL Server 维护计划实现数据库备份(Step by Step)(转)

    SQL Server 维护计划实现数据库备份(Step by Step) 一.前言 SQL Server 备份和还原全攻略,里面包括了通过SSMS操作还原各种备份文件的图形指导,SQL Server  ...

  7. 转:eclipse以及step into step over step return的区别

    首先来讲一下step into step over step return的区别: step into就是单步执行,遇到子函数就进入并且继续单步执行:(F5) step over是在单步执行时,在函数 ...

  8. [转]Bootstrap 3.0.0 with ASP.NET Web Forms – Step by Step – Without NuGet Package

    本文转自:http://www.mytecbits.com/microsoft/dot-net/bootstrap-3-0-0-with-asp-net-web-forms In my earlier ...

  9. EF框架step by step(7)—Code First DataAnnotations(2)

    上一篇EF框架step by step(7)—Code First DataAnnotations(1)描述了实体内部的采用数据特性描述与表的关系.这一篇将用DataAnnotations描述一下实体 ...

  10. EF框架step by step(6)—处理实体complex属性

    上一篇的中介绍过了对于EF4.1框架中,实体的简单属性的处理 这一篇介绍一下Code First方法中,实体Complex属性的处理.Complex属性是将一个对象做为另一个对象的属性.映射到数据库中 ...

随机推荐

  1. 最近开始研究PMD(一款采用BSD协议发布的Java程序代码检查工具)

    PMD是一款采用BSD协议发布的Java程序代码检查工具.该工具可以做到检查Java代码中是否含有未使用的变量.是否含有空的抓取块.是否含有不必要的对象等.该软件功能强大,扫描效率高,是Java程序员 ...

  2. openstack kilo compute更新后报错IncompatibleObjectVersion: Version 1.2 of PciDeviceList is not supported

    前几天在compute节点更新openstack的包后,发现报错IncompatibleObjectVersion: Version 1.2 of PciDeviceList is not suppo ...

  3. Effective Java 64 Strive for failure atomicity

    Principle Failure atomic - A failed method invocation should leave the object in the state that it w ...

  4. cxf构建webservice的两种方式

    一.简介 对于基于soap传输协议的webservice有两种开发模式,代码优先和契约优先的模式.代码优先的模式是通过编写服务器端的代码,使用代码生成wsdl:契约优先模式首先编写wsdl,再通过ws ...

  5. CentOS6.5(Python-2.7.12)安装Pip

    1.安装setuptools(下载链接可从https://pypi.python.org/pypi/setuptools#code-of-conduct寻找) #Download setuptools ...

  6. Solr与HBase架构设计

    摘要:本篇是本人在做一个大数据项目时,对于系统架构的一点总结,如何在保证存储量的情况下,又能保证数据的检索速度. 前提:      Solr.SolrCloud提供了一整套的数据检索方案,HBase提 ...

  7. 关于统计变换(CT/MCT/RMCT)算法的学习和实现

    原文地址http://blog.sina.com.cn/s/blog_684c8d630100turx.html 刚开会每周的例会,最讨厌开会了,不过为了能顺利毕业,只能忍了.闲话不多说了,下面把上周 ...

  8. Proc-fs 编程

    一.简介 Proc文件系统是Linux系统上的一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更 ...

  9. 【对比分析八】null和undefined的区别

    (1).  null是一个表示"无"的对象,转为数值时为0  undefined是一个表示"无"的原始值,转为数值时为NaN (2).  当声明的变量还未被初始 ...

  10. FZU 2150 Fire Game --两点同步搜索

    枚举两点,然后同步BFS,看代码吧,很容易懂的. 代码: #include <iostream> #include <cstdio> #include <cstring& ...