运动模糊实现(VC++)

news/2024/6/29 9:31:31 标签: vc++, float, delete, 存储
bool MotionBlur(IplImage* src)
{
// 指向目标图像的指针
unsigned char * LPsrc;


//图象的宽度和高度
int   Width = src->width;
int   Height= src->height;


int   LineBytes=src->width*src->nChannels;



int iColumn, jRow;//循环变量


int temp,m;//临时变量

double p,q;// 临时变量


int nTotTime, nTotLen, nTime;


nTotTime = 10;//总的运动时间10s
nTotLen = 10;// 总的运动距离10个象素点


double B;// 摄像机的暴光系数
B = 0.1;



int *nImageDegener;//用来存储源图象和变换核的时域数据


nImageDegener = new int [Height*LineBytes];// 为时域和频域的数组分配空间


// 将数据存入时域数组
for (jRow = 0; jRow < Height; jRow++)
{
for(iColumn = 0; iColumn < LineBytes; iColumn++)
{
temp=0;


// 指向源图像倒数第jRow行,第iColumn个象素的指针
LPsrc = (unsigned char *)src->imageData + LineBytes * jRow + iColumn;


// 象素点的象素值积累
for ( nTime = 0; nTime < nTotTime; nTime++ )
{
p = (float)iColumn - (float)(nTotLen)*nTime/nTotTime;


if (p > 0)
{
q = p - floor((double)p);


if(q >= 0.5)
m = (int)ceil((double)p);
else
m = (int)floor((double)p);


// 累加
LPsrc = (unsigned char *)src->imageData + LineBytes * jRow + m;
temp = temp + *LPsrc;
}
}


// 乘以摄像机的暴光系数
temp = B * temp;
temp=(int)ceil((double)temp);


// 使得temp的取值符合取值范围
if(temp<0)
temp=0;


if(temp>255)
temp=255;


nImageDegener[LineBytes*jRow + iColumn] = temp;
}
}


//转换为图像
for (jRow = 0;jRow < Height ;jRow++)
{
for(iColumn = 0;iColumn < LineBytes ;iColumn++)
{
// 指向源图像倒数第jRow行,第iColumn个象素的指针
LPsrc = (unsigned char *)src->imageData + LineBytes * jRow + iColumn;


*LPsrc = nImageDegener[LineBytes*jRow + iColumn];
}
}


//释放存储空间
delete[] nImageDegener;


// 返回
return true;
}

http://www.niftyadmin.cn/n/790721.html

相关文章

OpenCV实现傅里叶变换

#include <stdio.h> #include <cv.h> #include <cxcore.h> #include <highgui.h>/************************************************************************** //傅里叶变换 //src IPL_DEPTH_8U //dst IPL_DEPTH_64F /****************************…

【Visual C++】关于无法打开包括文件:“StdAfx.h”或者意外结尾的错误解决方案

最近有朋友在编译我提供的【Visual C】游戏开发某一节笔记的源代码的时候&#xff0c;提到出现 “fatal error C1083: 无法打开包括文件:“StdAfx.h”这个错误。这里我专门找了点资料&#xff0c;然后部分修改&#xff0c;写成了一篇博文发出来&#xff0c;希望能对出现这个问…

openCV平滑函数----cvSmooth

openCV平滑函数 [cpp] view plaincopyprint? void cvSmooth( const CvArr* src, CvArr* dst, int smooth CV_GAUSSIAN, int param1 3, int param2 0, int param3 0, int param4 0 ); 注解&#xff1a; (1)可能大家啊对CvA…

C++预编译头文件讲解

为什么所有的 cpp 都必须 #include "stdafx.h" 也许请教了别的高手之后&#xff0c;他们会告诉你&#xff0c;这是预编译头&#xff0c;必须包含。可是&#xff0c;这到底是为什么呢&#xff1f;预编译头有什么用呢&#xff1f; 这得从头文件的编译原理讲起。其实头文…

防止头文件重复包含引起的变量重复定义

test-1.0使用#ifndef只是防止了头文件被重复包含(其实本例中只有一个头件&#xff0c;不会存在重复包含的问题)&#xff0c;但是无法防止变量被重复定义。 # vi test.c-------------------------------#include <stdio.h>#include "test.h"extern i;extern voi…

C++函数对象与函数指针不同之处

在C编程语言中&#xff0c;有很多功能都与C语言相通&#xff0c;比如指针的应用等等。在这里我们介绍的则是一种类似于函数指针的C函数对象的相关介绍。C函数对象不是函数指针。但是&#xff0c;在程序代码中&#xff0c;它的调用方式与函数指针一样&#xff0c;后面加个括号就…

开闭架构

在《不过时的经典层架构》里&#xff0c;有朋友留言关于Manager和Engine的概念&#xff0c;虽然朋友留言把概念解释清楚了。为了避免其他人有同样的疑问&#xff0c;这里我还是再解释一下。 以上是经典的四层架构&#xff0c;在这个架构中&#xff0c;Manager和Engine(引擎)都是…

计算机视觉、图像处理学习资料汇总

一、研究群体 http://www-2.cs.cmu.edu/~cil/vision.html 这是卡奈基梅隆大学的计算机视觉研究组的主页&#xff0c;上面提供很全的资料&#xff0c;从发表文章的下载到演示程序、测试图像、常用链接、相关软硬件&#xff0c;甚至还有一个搜索引擎。 http://www.cmis.csiro.a…