?? mainfrm.cpp
字號(hào):
if(!theApp.curVideo)
{
AfxMessageBox("沒有打開視頻文件 !");
return;
}
// 創(chuàng)建線程
th = CreateThread(NULL,0,StaticDetectT,theApp.curVideo->doc,0,&pID);
}
/************************************************************************/
/* 動(dòng)止背景目標(biāo)檢測(cè) */
/************************************************************************/
DWORD WINAPI MotionDetectT(LPVOID data){
CVideoDemoDoc *doc = (CVideoDemoDoc*)theApp.curVideo->doc;
int frameLength = theApp.curVideo->ms->GetFrameCount();
MediaSource *avi = theApp.curVideo->ms;
unsigned char *frame = avi->GetSingleFrame(0);
int frameWidth = avi->GetFrameWidth();
int frameHeight = avi->GetFrameHeight();
// 色彩變換
ColorTrans ct;
int *threshold = (int*)data;
MotionDetectDiag diag;
//if(diag.DoModal()){
// threshold = diag.m_index;
//}
CStatsticDetect sd(frameWidth,frameHeight);
//CStaticDetect sd(frameWidth,frameHeight);
ChafenMul cm(frameWidth,frameHeight,*threshold);
// 輸出緩沖
unsigned char * outBuffer = new unsigned char[frameHeight * frameWidth * 3];
unsigned char * gray = new unsigned char[frameWidth * frameHeight * 3];
for(int i = 0; i < frameLength - 1; i++)
{
// 獲得一幀圖像
frame = avi->GetSingleFrame(i);
ct.RGB2Gray8(frame,gray,frameWidth,frameHeight);
// 準(zhǔn)備數(shù)據(jù)
cm.PrepareData(gray,frameWidth,frameHeight);
if(i % 4 == 0 && i != 0)
{
cm.process();
sd.DeNoise(cm.frame1,frameWidth,frameHeight);
ct.gray2RGB2(cm.frame1,outBuffer,frameWidth,frameHeight);
doc->id->data = outBuffer;
doc->RefreshView();
}
}
delete[] outBuffer;
return 0;
}
/************************************************************************/
/* 動(dòng)背景目標(biāo)檢測(cè) */
/************************************************************************/
void CMainFrame::OnMotionDd()
{
DWORD exitCode;
if(GetExitCodeThread(th,&exitCode)){
TerminateThread(th,exitCode);
}
if(theApp.curVideo == NULL)
AfxMessageBox("沒有打開視頻文件!");
DWORD pID;
//控制線程播放
int frameLength = theApp.curVideo->ms->GetFrameCount();
MediaSource *avi = theApp.curVideo->ms;
int threshold = 100;
MotionDetectDiag mdd;
if(mdd.DoModal())
{
threshold = mdd.m_index;
}
int * thre = (int*)malloc(sizeof(int));
*thre = threshold;
// 創(chuàng)建線程
th = CreateThread(NULL,0,MotionDetectT,thre,0,&pID);
}
/************************************************************************/
/* 動(dòng)止背景目標(biāo)檢測(cè) */
/************************************************************************/
DWORD WINAPI MSS(LPVOID data){
CVideoDemoDoc *doc = (CVideoDemoDoc*)theApp.curVideo->doc;//(CVideoDemoDoc*)data;
int frameLength = theApp.curVideo->ms->GetFrameCount();
MediaSource *avi = theApp.curVideo->ms;
unsigned char *frame = avi->GetSingleFrame(0);
int frameWidth = avi->GetFrameWidth();
int frameHeight = avi->GetFrameHeight();
MeanShiftSegger* mms = (MeanShiftSegger*)data;
// 輸出緩沖
unsigned char * outBuffer = new unsigned char[frameHeight * frameWidth * 3];
for(int i = 0; i < frameLength - 1; i++)
{
// 獲得一幀圖像
frame = avi->GetSingleFrame(i);
mms->MeanShiftTrackProcess(frame,i);
doc->id->data = frame;
doc->RefreshView();
}
delete[] outBuffer;
return 0;
}
/************************************************************************/
/* MeanShift跟蹤 */
/************************************************************************/
void CMainFrame::OnTracekMeanshift()
{
DWORD exitCode;
if(GetExitCodeThread(th,&exitCode)){
TerminateThread(th,exitCode);
}
DWORD pID;
if(theApp.curVideo == NULL){
AfxMessageBox("沒有打開視頻!");
return;
}
int x,y,width,height;
POSDiag pd;
if(pd.DoModal())
{
x= pd.m_x;
y= pd.m_y;
width = pd.m_width;
height = pd.m_height;
}
else
return;
mss = new MeanShiftSegger();
int frameLength = theApp.curVideo->ms->GetFrameCount();
MediaSource *avi = theApp.curVideo->ms;
unsigned char *frame = avi->GetSingleFrame(0);
int frameWidth = avi->GetFrameWidth();
int frameHeight = avi->GetFrameHeight();
mss->InitMeanShiftTracker(frame,frameWidth,frameHeight,x,y,width,height);
th = CreateThread(NULL,0,MSS,mss,0,&pID);
}
/************************************************************************/
/* 重心 法 跟蹤 */
/************************************************************************/
DWORD WINAPI GAV(LPVOID data){
int* threshold = (int*)data;
CVideoDemoDoc *doc = (CVideoDemoDoc*)theApp.curVideo->doc;
int frameLength = theApp.curVideo->ms->GetFrameCount();
MediaSource *avi = theApp.curVideo->ms;
unsigned char *frame = avi->GetSingleFrame(0);
int frameWidth = avi->GetFrameWidth();
int frameHeight = avi->GetFrameHeight();
// 輸出緩沖
unsigned char * outBuffer = new unsigned char[frameHeight * frameWidth * 3];
unsigned char * grayBuffer =new unsigned char[frameWidth * frameHeight];
ColorTrans ct;
CGravityCenter* m_gravitycenter;
TARGETPARA m_target;
for(int i = 0; i < frameLength - 1; i++)
{
// 獲得一幀圖像
frame = avi->GetSingleFrame(i);
ct.RGB2Gray8(frame,grayBuffer,frameWidth,frameHeight);
if(i == 0)
{
m_gravitycenter = new CGravityCenter(frameWidth,frameHeight);
m_gravitycenter->InitalObjectTracker(T_GRACENTER,*threshold);
m_gravitycenter->GravityCenter(i, frame);
}
else
{
m_gravitycenter->GravityCenter(i, frame);
}
m_target = m_gravitycenter->m_result;
/*
// 重心跟蹤
WININFO info = GravityTrack(grayBuffer,frameWidth,frameHeight,*threshold);
if(!info.flag)
{
for(int j = max(info.pt.y - info.h / 2,0);j <= min(info.pt.y + info.h / 2,frameHeight); j ++)
for(int i = max(info.pt.x - info.w / 2,0);i <= min(info.pt.x + info.w / 2,frameWidth); i ++)
{
frame[j * frameWidth * 3 + i * 3] = 255;
}
}*/
doc->id->data = frame;
doc->RefreshView();
}
delete[] grayBuffer;
delete[] outBuffer;
return 0;
}
/************************************************************************/
/* 重心法跟蹤 */
/************************************************************************/
void CMainFrame::OnTracekGav()
{
DWORD exitCode;
if(GetExitCodeThread(th,&exitCode)){
TerminateThread(th,exitCode);
}
DWORD pID;
if(theApp.curVideo == NULL){
AfxMessageBox("沒有打開視頻!");
return;
}
int threshold = 100;
MotionDetectDiag mdd;
if(mdd.DoModal())
{
threshold = mdd.m_index;
}
int * thre = (int*)malloc(sizeof(int));
*thre = threshold;
th = CreateThread(NULL,0,GAV,thre,0,&pID);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -