GrabCut算法提取前景物体

#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<imgproc/imgproc.hpp>
#include<iostream>
 
using namespace std;
using namespace cv;

int main()
{
	Mat image=imread("d:/test/opencv/group.jpg");
	namedWindow("Image");
	imshow("Image",image);
	Rect rectangle(10,100,380,180);
	Mat result;
	Mat bgModel,fgModel;
	grabCut(image,result,rectangle,bgModel,fgModel,5,GC_INIT_WITH_RECT);
	compare(result,GC_PR_FGD,result,CMP_EQ);
	Mat foreground(image.size(),CV_8UC3,Scalar(255,255,255));
	image.copyTo(foreground,result);
	namedWindow("Foreground");
	imshow("Foreground",foreground);
	waitKey();
	return 0;
}

posted @ 2014-05-23 21:43  mengfanrong  阅读(576)  评论(0)    收藏  举报
众安尊享e升2025版 - 底部横幅广告
尊享e升 2025版
🚀 全新升级
百万医疗险全面升级 守护健康人生
✓ 一般医疗300万
✓ 重疾600万
✓ 6年保证续保
✓ 1万免赔额
600万
最高保障
首月特惠价
低至1元起
🛡️ 立即投保