GrabCut算法提取前程物体
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; }