Needs["CV`"];
CVOpen[];
img=CVLoadImage["puzzle.png",CVLoadImageUnchanged];
s=CVGetSize[img];
edit=CVJImageEditor["puzzle",True];
CVJShowImage[edit,img];
rectList=CVJGetPixelRectangleList[edit];
rect=Floor[rectList[[1]]]
            
img2=CVCreateImage[s,IplDepth8U,3];
CVConvertScale[img,img2,1.0,0.0];
CVRectangle[img2,rect,{255,0,0},1];
            
Image[CVGetImageArray[img2,1,-1]]
hsv=CVCreateImage[s,IplDepth8U,3];
CVCvtColor[img,hsv,CVBGR2HSV];
hue = CVCreateImage[s,IplDepth8U,1];
sat = CVCreateImage[s,IplDepth8U,1];
val = CVCreateImage[s,IplDepth8U,1];
CVSplit[hsv,hue,sat,val,0];
            
CVSetImageROI[hue,rect];
CVSetImageROI[sat,rect];
            
histHS=CVCreateHist[{20,20},CVHistArray,{{0,180},{0,255}},1];
CVCalcHist[{hue,sat},histHS,0,0];
histImg=CVGetHueSatHistImage[histHS,10];
            
Image[CVGetImageArray[histImg,1,-1]]
minmax=CVGetMinMaxHistValue[histHS]
CVConvertHistScale[histHS,256.0/minmax[[2,1]],0.0];
CVResetImageROI[hue];
CVResetImageROI[sat];
back=CVCreateImage[s,IplDepth8U,1];
            
CVCalcBackProject[{hue,sat},back,histHS];
Image[CVGetImageArray[back,1,-1]]
CVClose[];
