#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;
}
GrabCut算法提取前景物体
最新推荐文章于 2024-06-12 15:10:54 发布