⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 postprocess.cpp

📁 动态场景中运动目标检测提取与跟踪 对新手很有用
💻 CPP
字号:
#include "postProcess.h"
#include "math.h"
#include "cv.h"
#include "StdAfx.h"
#include "IplImageProcess.h"
#include <fstream.h>
#include "GMM.h"


void meanFilter(IplImage* source)//, IplImage* destination)
{
	ASSERT(source!=NULL);


	int height=source->height;
	int width=source->width;
	IplImage* destination=cvCreateImage(cvSize(width,height), IPL_DEPTH_8U,3);

	for(int x=1;x<width-1;x++)
		for(int y=1;y<height-1;y++)
		{
			int red=0;
			int green=0;
			int blue=0;
			for(int n=-1;n<=1;n++)
				for(int m=-1;m<=1;m++)
				{
					red+=iplGetPixelRed(source,x+n,y+m);
					green+=iplGetPixelGreen(source,x+n,y+m);
					blue+=iplGetPixelBlue(source,x+n,y+m);
				}
				red=(int)(red/9.0);
				green=(int)(green/9.0);
				blue=(int)(blue/9.0);
				iplSetPixelColor(destination,x,y,getRGB(red,green,blue));
		}
		for(x=0;x<width;x++)
		{
			iplSetPixelColor(destination,x,0,iplGetPixelColor(source,x,0));
			iplSetPixelColor(destination,x,height-1,iplGetPixelColor(source,x,height-1));
		}
		for(int y=0;y<height;y++)
		{
			iplSetPixelColor(destination,0,y,iplGetPixelColor(source,0,y));
			iplSetPixelColor(destination,width-1,y,iplGetPixelColor(source,width-1,y));
		}

	
		//iplSetAllPixel(source,(unsigned char*)destination->imageData);
		memcpy(source->imageData,destination->imageData,source->widthStep*height);

		cvReleaseImage(&destination);
}

void SmoothFilter(IplImage* source)
{
	ASSERT(source!=NULL);

	int width=source->width;
	int height=source->height;
	IplImage* destination=cvCreateImage(cvSize(width,height), IPL_DEPTH_8U,3);


	for(int x=0;x<width;x++)
		for(int y=0;y<2;y++)
		{
			iplSetPixelColor(destination,x,y,iplGetPixelColor(source,x,y));
			iplSetPixelColor(destination,x,height-1-y,iplGetPixelColor(source,x,height-1-y));
		}
	for(int y=0;y<height;y++)
		for(int x=0;x<2;x++)
		{
			iplSetPixelColor(destination,x,y,iplGetPixelColor(source,x,y));
			iplSetPixelColor(destination,width-1-x,y,iplGetPixelColor(source,width-1-x,y));
		}
	int num=0;

    //ofstream output("pixel.txt",ios::ate);
	
	for(int i=2;i<height-2;i++)
		for(int j=2;j<width-2;j++)
		{
			//output<<iplGetPixelColor(source,j,i)<<endl;
			
			//	System.out.println(jipimage.getPixel(j,i));
			if(iplGetPixelColor(source,j,i)!=0xff000000)
			{

				for(int m=i-2;m<=i+2;m++)
					for(int n=j-2;n<=j+2;n++)
					{
						if(iplGetPixelColor(source,n,m)!=0xff000000)
							num++;
					}
					iplSetPixelColor(destination,j,i,num>13 ? iplGetPixelColor(source,j,i):0xff000000);
					num=0;
			}
			else
			{
				iplSetPixelColor(destination,j,i,0xff000000);	
			}
			
		}
	//iplSetAllPixel(source,(unsigned char*)destination->imageData);	
	memcpy(source->imageData,destination->imageData,source->widthStep*height);
	cvReleaseImage(&destination);
}

bool shadowElimination(IplImage* orig, IplImage* back, IplImage* bina)
{
	ASSERT(orig!=NULL && back!=NULL && bina!=NULL && orig->imageSize==back->imageSize &&
		back->imageSize==bina->imageSize);
	for(int x=0;x<bina->width;x++)
		for(int y=0;y<bina->height;y++)
		{
			if(iplGetPixelColor(bina,x,y)!=0xff000000)
			{
				int red1=iplGetPixelRed(back,x,y);
				int green1=iplGetPixelGreen(back,x,y);
				int blue1=iplGetPixelBlue(back,x,y);
					
				int red2=iplGetPixelRed(orig,x,y);
				int green2=iplGetPixelGreen(orig,x,y);
				int blue2=iplGetPixelBlue(orig,x,y);
					
				if(abs(red1-red2)/(double)(red1)<ALPHA_RGB && 
					abs(green1-green2)/(double)(green1)<ALPHA_RGB &&
					abs(blue1-blue2)/(double)(blue1)<ALPHA_RGB)
				{
					iplSetPixelColor(bina,x,y,0xff000000);
				}
				else
				{
					iplSetPixelColor(bina,x,y,0xffffffff);
				} 

			}

		}
		return true;



}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -