?? chafenmul.cpp
字號(hào):
#include "StdAfx.h"
#include "ChafenMul.h"
/************************************************************************
* 函數(shù)名稱:
* ChafenMul
*
* 參數(shù):
* int width-幀寬度
* int height-幀高度
*
* 說明:
* 構(gòu)造函數(shù),并分配內(nèi)存空間,參數(shù)為幀的高度和寬度
************************************************************************/
ChafenMul::ChafenMul(int width,int height,int _targetThreshold):
targetThreshold(_targetThreshold),frameWidth(width),frameHeight(height),
frame1(NULL),frame2(NULL),frame3(NULL),frame4(NULL)
{
frame1 = new unsigned char[width * height];
frame2 = new unsigned char[width * height];
frame3 = new unsigned char[width * height];
frame4 = new unsigned char[width * height];
memset(frame1,0,sizeof(unsigned char) * width * height);
memset(frame2,0,sizeof(unsigned char) * width * height);
memset(frame3,0,sizeof(unsigned char) * width * height);
memset(frame4,0,sizeof(unsigned char) * width * height);
readyCount = 0;
}
/************************************************************************
* 函數(shù)名稱:
* ~ChafenMul
*
* 說明:
* 析構(gòu)函數(shù),釋放內(nèi)存空間
************************************************************************/
ChafenMul::~ChafenMul()
{
if(frame1 != NULL) delete[] frame1;
if(frame2 != NULL) delete[] frame2;
if(frame3 != NULL) delete[] frame3;
if(frame4 != NULL) delete[] frame4;
}
/************************************************************************
* 函數(shù)名稱:
* PrepareData
*
* 參數(shù):
* unsigned char *buffer-輸入圖像數(shù)據(jù)
* int width-幀寬度
* int height-幀高度
*
* 說明:
* 輸入幀圖像數(shù)據(jù),并分別將幀圖像數(shù)據(jù)拷貝至緩存中
************************************************************************/
void ChafenMul::PrepareData(unsigned char *buffer,int width,int height)
{
if(readyCount == 0)
memcpy(frame1,buffer,width * height * sizeof(unsigned char));
if(readyCount == 1)
memcpy(frame2,buffer,width * height * sizeof(unsigned char));
if(readyCount == 2)
memcpy(frame3,buffer,width * height * sizeof(unsigned char));
if(readyCount == 3)
memcpy(frame4,buffer,width * height * sizeof(unsigned char))
;
readyCount ++;
if(readyCount == 4)
readyCount = 0;
}
/************************************************************************
* 函數(shù)名稱:
* process
*
* 說明:
* 差分相乘法檢測目標(biāo)
************************************************************************/
void ChafenMul::process()
{
int * mul = new int[frameWidth * frameHeight];
for(int j = 0; j < frameHeight; j ++)
{
for(int i = 0; i < frameWidth; i ++)
{
frame1[j*frameWidth+i]=abs(frame3[j*frameWidth+i] - frame1[j * frameWidth + i]);
frame2[j*frameWidth+i]=abs(frame4[j*frameWidth+ i] - frame2[j * frameWidth + i]);
mul[j*frameWidth +i] = frame1[j * frameWidth + i] * frame2[j * frameWidth + i];
if(mul[j*frameWidth +i] > targetThreshold)
{
frame1[j * frameWidth + i] = 255;
}else
frame1[j * frameWidth + i] = 0;
}
}
//對frame1運(yùn)用靜態(tài)背景檢測的方法并計(jì)算目標(biāo)形心的位置
//釋放空間
delete[] mul;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -