由于项目需要,进行过一段时间的 PariticalFilter 研究。主要的工作就是将网络上的Console代码和Mfc融合在一起,并且添加了Mfc端的控制功能。
程序还有不完善的地方,现将相关的函数发布出来,大家相互研究。程序运行界面
程序的核心为两个部分,一个是核心PF函数,一个是界面操作
核心函数
.
#.
#.
#.
#.
);
);
sd ); , histo );
s );
v );
cvSplit( imgs, h, s, v, NULL );
; r ; c ;
}
cvReleaseImage( , inv_sum;
; i . ; i );
cvCopy( frame, tmp, NULL );
cvResetImageROI( frame );
histos );
normalize_histogram( histos );
cvReleaseImage( ;
particles ;
y ;
; j .;
particles[k].width ;
}
;
;
y ;
particles[k].x0 .;
particles[k].width ;
i ) .
#.
#.
.
#.
#.0000
., MIN( (., x ) );
y ., MIN( (., y ) );
s . ) . ) .;
pn.s ., s );
pn.xp ;
;
; i . ;
;
;
}
IplImage matimg(matSrc);
IplImage, r , w, h ) );
tmp );
cvCopy( img, tmp, NULL );
cvResetImageROI( img );
histo );
cvReleaseImage( ;
; i ; i ;
; i ; j ];
exit. . ,,));
}
#.
#.
#.
#.
);
);
sd ); , histo );
s );
v );
cvSplit( imgs, h, s, v, NULL );
; r ; c ;
}
cvReleaseImage( , inv_sum;
; i . ; i );
cvCopy( frame, tmp, NULL );
cvResetImageROI( frame );
histos );
normalize_histogram( histos );
cvReleaseImage( ;
particles ;
y ;
; j .;
particles[k].width ;
}
;
;
y ;
particles[k].x0 .;
particles[k].width ;
i ) .
#.
#.
.
#.
#.0000
., MIN( (., x ) );
y ., MIN( (., y ) );
s . ) . ) .;
pn.s ., s );
pn.xp ;
;
; i . ;
;
;
}
IplImage matimg(matSrc);
IplImage, r , w, h ) );
tmp );
cvCopy( img, tmp, NULL );
cvResetImageROI( img );
histo );
cvReleaseImage( ;
; i ; i ;
; i ; j ];
exit. . ,,));
}
界面处理相关
void CGOMfcTemplate2Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rect_ctr;
(this->GetDlgItem(IDC_CAM))->GetWindowRect(&rect_ctr);//获取Picture控件相对屏幕左上角的坐标,
ScreenToClient(rect_ctr);//获取Picture控件相对对话框客户区左上角的坐标
instant_position.x = point.x;
instant_position.y = point.y;
picture_ordinate_x = point.x - rect_ctr.left;
picture_ordinate_y = point.y - rect_ctr.top;//point获取的是鼠标相对对话框客户区左上角的坐标,减去rect_ctr.left和rect_ctr.top后,即为鼠标相对Picture控件左上角的坐标
if ((nFlags == MK_LBUTTON) && Is_LeftButton_Down)
{
::SetCursor(cross);
CClientDC dc(this);
CBrush *OldBrush;
OldBrush=(CBrush*)dc.SelectStockObject(NULL_BRUSH);
dc.SetROP2(R2_NOT);
dc.Rectangle(CRect(chosen_position,instant_position));
dc.Rectangle(CRect(chosen_position,point));
dc.SelectObject(OldBrush);
instant_position=point;
}
else
::SetCursor(arrow);
CDialogEx::OnMouseMove(nFlags, point);
}
void CGOMfcTemplate2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
Is_LeftButton_Down = true;
::SetCursor(cross);
chosen_position = instant_position = point;
CDialogEx::OnLButtonDown(nFlags, point);
}
void CGOMfcTemplate2Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if (Is_LeftButton_Down)
{
Is_LeftButton_Down = false;
::SetCursor(arrow);
CClientDC dc(this);
CPen* pOldPen=(CPen*)dc.SelectObject(&pen);
dc.MoveTo(chosen_position);
dc.LineTo(chosen_position.x,instant_position.y);
dc.LineTo(instant_position);
dc.LineTo(instant_position.x,chosen_position.y);
dc.LineTo(chosen_position);
//写到rect_res中区
int rect_x = min(chosen_position.x,instant_position.x);
int rect_y = min(chosen_position.y,instant_position.y);
int rect_w = abs(chosen_position.x - instant_position.x);
int rect_h = abs(chosen_position.y - instant_position.y);
rectStart = Rect(rect_x,rect_y,rect_w,rect_h);
}
CDialogEx::OnLButtonUp(nFlags, point);
}
{
CRect rect_ctr;
(this->GetDlgItem(IDC_CAM))->GetWindowRect(&rect_ctr);//获取Picture控件相对屏幕左上角的坐标,
ScreenToClient(rect_ctr);//获取Picture控件相对对话框客户区左上角的坐标
instant_position.x = point.x;
instant_position.y = point.y;
picture_ordinate_x = point.x - rect_ctr.left;
picture_ordinate_y = point.y - rect_ctr.top;//point获取的是鼠标相对对话框客户区左上角的坐标,减去rect_ctr.left和rect_ctr.top后,即为鼠标相对Picture控件左上角的坐标
if ((nFlags == MK_LBUTTON) && Is_LeftButton_Down)
{
::SetCursor(cross);
CClientDC dc(this);
CBrush *OldBrush;
OldBrush=(CBrush*)dc.SelectStockObject(NULL_BRUSH);
dc.SetROP2(R2_NOT);
dc.Rectangle(CRect(chosen_position,instant_position));
dc.Rectangle(CRect(chosen_position,point));
dc.SelectObject(OldBrush);
instant_position=point;
}
else
::SetCursor(arrow);
CDialogEx::OnMouseMove(nFlags, point);
}
void CGOMfcTemplate2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
Is_LeftButton_Down = true;
::SetCursor(cross);
chosen_position = instant_position = point;
CDialogEx::OnLButtonDown(nFlags, point);
}
void CGOMfcTemplate2Dlg::OnLButtonUp(UINT nFlags, CPoint point)
{
if (Is_LeftButton_Down)
{
Is_LeftButton_Down = false;
::SetCursor(arrow);
CClientDC dc(this);
CPen* pOldPen=(CPen*)dc.SelectObject(&pen);
dc.MoveTo(chosen_position);
dc.LineTo(chosen_position.x,instant_position.y);
dc.LineTo(instant_position);
dc.LineTo(instant_position.x,chosen_position.y);
dc.LineTo(chosen_position);
//写到rect_res中区
int rect_x = min(chosen_position.x,instant_position.x);
int rect_y = min(chosen_position.y,instant_position.y);
int rect_w = abs(chosen_position.x - instant_position.x);
int rect_h = abs(chosen_position.y - instant_position.y);
rectStart = Rect(rect_x,rect_y,rect_w,rect_h);
}
CDialogEx::OnLButtonUp(nFlags, point);
}