【发布时间】:2016-06-19 02:17:04
【问题描述】:
我正在尝试使用 mog2 在 OpenCV 2.4.10 中实现背景减法。我的目标是使用背景减法来分割手部。不幸的是,用作前景的第一帧似乎在从网络摄像头实时捕获期间卡住了。这是我用于这个简单项目的代码
#include "stdafx.h"
#include <opencv2\opencv.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\video\video.hpp>
#include <opencv2\core\core.hpp>
#include <iostream>
#include <sstream>
#include <string.h>
using namespace cv;
int main()
{
Mat frame, mask, gray;
BackgroundSubtractorMOG2 mog2;
VideoCapture cap(0);
if (cap.isOpened()){
while (true)
{
if (cap.read(frame))
{
imshow("frame", frame);
cvtColor(frame, gray, cv::COLOR_RGB2GRAY);
imshow("gray", gray);
mog2(gray, mask, 0.0);// 0.1 is learning rate
imshow("Background Subtraction", mask);
if (waitKey(30) >= 0)
break;
}
}
}
cap.release();
return 0;
}
这是输出
【问题讨论】:
标签: c++ c opencv image-processing computer-vision