Opencv step by step - 图像变换
这里举出三个案例:
#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 - 图像变换的更多相关文章
- Step by step Dynamics CRM 2011升级到Dynamics CRM 2013
原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...
- Step by Step 创建一个新的Dynamics CRM Organization
原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...
- 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 ...
- Step by step Dynamics CRM 2013安装
原创地址:http://www.cnblogs.com/jfzhu/p/4008391.html 转载请注明出处 SQL Server可以与CRM装在同一台计算机上,也可安装在不同的计算机上.演示 ...
- Step by step 活动目录中添加一个子域
原创地址:http://www.cnblogs.com/jfzhu/p/4006545.html 转载请注明出处 前面介绍过如何创建一个域,下面再介绍一下如何在该父域中添加一个子域. 活动目录中的森林 ...
- SQL Server 维护计划实现数据库备份(Step by Step)(转)
SQL Server 维护计划实现数据库备份(Step by Step) 一.前言 SQL Server 备份和还原全攻略,里面包括了通过SSMS操作还原各种备份文件的图形指导,SQL Server ...
- 转:eclipse以及step into step over step return的区别
首先来讲一下step into step over step return的区别: step into就是单步执行,遇到子函数就进入并且继续单步执行:(F5) step over是在单步执行时,在函数 ...
- [转]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 ...
- EF框架step by step(7)—Code First DataAnnotations(2)
上一篇EF框架step by step(7)—Code First DataAnnotations(1)描述了实体内部的采用数据特性描述与表的关系.这一篇将用DataAnnotations描述一下实体 ...
- EF框架step by step(6)—处理实体complex属性
上一篇的中介绍过了对于EF4.1框架中,实体的简单属性的处理 这一篇介绍一下Code First方法中,实体Complex属性的处理.Complex属性是将一个对象做为另一个对象的属性.映射到数据库中 ...
随机推荐
- Hadoop Eclipse开发环境搭建
This document is from my evernote, when I was still at baidu, I have a complete hadoop developme ...
- Merge Two Sorted Lists
Merge Two Sorted Lists https://leetcode.com/problems/merge-two-sorted-lists/ Merge two sorted linked ...
- 小心sae的jvm异常导致的Error 404 – Not Found.No context on this server matched or handled this request.
本来用着sae好好的,结果第二天部署的应用突然不好使了,各种Error 404 – Not Found.No context on this server matched or handled thi ...
- Mongodb--gridfs与分片实验
1.放置一个大文件到gridfs,查看fs.chunks和fs.files的情况. Step1.开启一台mongod服务. ./mongod --dbpath dbs/master 登录mon ...
- 边工作边刷题:70天一遍leetcode: day 89
Word Break I/II 现在看都是小case题了,一遍过了.注意这题不是np complete,dp解的time complexity可以是O(n^2) or O(nm) (取决于inner ...
- 翻译《Writing Idiomatic Python》(二):函数、异常
原书参考:http://www.jeffknupp.com/blog/2012/10/04/writing-idiomatic-python/ 上一篇:翻译<Writing Idiomatic ...
- 利用python爬取海量疾病名称百度搜索词条目数的爬虫实现
实验原因: 目前有一个医疗百科检索项目,该项目中对关键词进行检索后,返回的结果很多,可惜结果的排序很不好,影响用户体验.简单来说,搜索出来的所有符合疾病中,有可能是最不常见的疾病是排在第一个的,而最有 ...
- HDU 4460 Friend Chains --BFS
题意:问给定的一张图中,相距最远的两个点的距离为多少.解法:跟求树的直径差不多,从1 开始bfs,得到一个最远的点,然后再从该点bfs一遍,得到的最长距离即为答案. 代码: #include < ...
- SGU 180 Inversions
题意:求逆序数对数量. 思路一:暴力,O(N^2),超时. 思路二:虽然Ai很大,但是n比较小,可以离散化,得到每个Ai排序后的位置Wi,然后按照输入的顺序,每个Ai对答案的贡献是Wi-Sum(Wi- ...
- Renderer.materials
修改方法 meshBody.renderer.materials[].mainTexture= clothes[]; meshBody.renderer.materials[]=maters[]; 以 ...