void CMFCworkDlg::OnBnClickedButton14()
{
// TODO: 在此添加控件通知处理程序代码
Mat greyimg;
Mat foreground, foreground2;
Ptr<BackgroundSubtractorKNN> ptrKNN = createBackgroundSubtractorKNN(100, 400, true);
Ptr<BackgroundSubtractorMOG2> mog2 = createBackgroundSubtractorMOG2(100, 25, true);
namedWindow("Extracted Foreground");
VideoCapture pCapture;
Mat pframe;
pCapture = VideoCapture("pets2001.avi");
while (1)
{
pCapture >> pframe;
if (pframe.data == NULL)
return;
cvtColor(pframe, greyimg, CV_BGR2GRAY);
long long t = getTickCount();
ptrKNN->apply(pframe, foreground, 0.01);
long long t1 = getTickCount();
mog2->apply(greyimg, foreground2, -1);
long long t2 = getTickCount();
_cprintf("t1 = %f t2 = %f\n", (t1 - t) / getTickFrequency(), (t2 - t1) / getTickFrequency());
imshow("Extracted Foreground", foreground);
imshow("Extracted Foreground2", foreground2);
imshow("video", pframe);
waitKey(10);
}
waitKey();
}
视频附件
链接:https://pan.baidu.com/s/19WhNu3WY1Q4PWr4LIGyKKg
提取码:dcoi