GrabCut: object extraction by separating the foreground and background of an image
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhE577pbpWxaOujuKP4pnRiwzDabY7Fdg6VnUAX-srQN0usxWLLVizVzlC_7HVUVF3aktTk8z13TUl-Ci1wzdKqFZ0ye5o6FdONKgk4PnixFOLuAPmJx1xL9f4WX9yKLu71wLpJFRO19b0/s0/sample_image1.jpg)
GrabCut is an algorithm that is used to extract the foreground from an image. OpenCV has a python implementation of this algorithm which we can use for our purpose. GrabCut in OpenCV OpenCV provides the implementation of the GrabCut as a function cv2.grabCut() . The function takes seven parameters as arguments and returns three parameters. cv.grabCut(img, mask, rect, bgdModel, fgdModel, iterCount[, mode]) Parameters: img : take an image as input ( 8-bit 3-channel image). mask : input/output 8-bit single-channel mask. When we set parameter mode to cv2.GC_INIT_WITH_RECT , the mask will be initialized automatically. rect : coordinates of a rectangle or bounding box which includes the foreground object in the format (x, y, w, h) . The parameter is only used when the parameter mode==GC_INIT_WITH_RECT . bgdModel : temporary array for the background model and use it int