I used the pygame version to make one simple tutorial about pallete functions :
>>> print pygame.version.ver
1.9.2b1
The result of my tutorial is this:

Is a blog about python programming language. You can see my work with python programming language, tutorials and news.
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
ret, img = cap.read()
#img = cv2.imread('test002.jpg')
mask = np.zeros(img.shape[:2],np.uint8)
bgdModel = np.zeros((1,65),np.float64)
fgdModel = np.zeros((1,65),np.float64)
rect = (50,50,450,290)
cv2.grabCut(img,mask,rect,bgdModel,fgdModel,5,cv2.GC_INIT_WITH_RECT)
mask2 = np.where((mask==2)|(mask==0),0,1).astype('uint8')
img = img*mask2[:,:,np.newaxis]
cv2.imshow('frame',img)
if 0xFF & cv2.waitKey(5) == 27:
break
cap.release()
cv2.destroyAllWindows()
The end result will be something like: