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

📄 preprocess.cpp

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

#define RATIO  2

bool getDCImage(IplImage* src, IplImage* des)
{
	if(src==NULL || des==NULL || des->height!=(int)(src->height/RATIO) || 
		des->width!=(int)(src->width/RATIO))
	{
		AfxMessageBox("in getDCImage(),the papameter is wrong!");
		return false;
	}
	for(int x=0;x<des->width;x++)
		for(int y=0;y<des->height;y++)
		{
			int meanR=0;
			int meanG=0;
			int meanB=0;
			for(int i=0;i<RATIO;i++)
			{
				meanR+=iplGetPixelRed(src,x*RATIO+i,y*RATIO+i);
				meanG+=iplGetPixelGreen(src,x*RATIO+i,y*RATIO+i);
				meanB+=iplGetPixelBlue(src,x*RATIO+i,y*RATIO+i);
			}
			iplSetPixelRed(des,x,y,(int)(meanR/RATIO));
			iplSetPixelGreen(des,x,y,(int)(meanG/RATIO));
			iplSetPixelBlue(des,x,y,(int)(meanB/RATIO));
		}

		return true;

}

bool getHistogram1D(IplImage* src, int hist[256])
{
	ASSERT(src!=NULL && hist!=NULL);
	memset(hist,0,256);

	for(int x=0;x<src->width;x++)
		for(int y=0;y<src->height;y++)
		{
			hist[iplGetPixelGray(src,x,y)]++;
		}

	return true;


}

bool getHistogram3D(IplImage* src, int hist[3][256])
{
	ASSERT(src!=NULL && hist!=NULL);
	for(int i=0;i<3;i++)
	{
		memset(hist[i],0,256);
	}	

	for(int x=0;x<src->width;x++)
		for(int y=0;y<src->height;y++)
		{
			hist[0][iplGetPixelRed(src,x,y)]++;
			hist[1][iplGetPixelGreen(src,x,y)]++;
			hist[2][iplGetPixelBlue(src,x,y)]++;
		}

	return true;

}

⌨️ 快捷键说明

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