Needs["CV`"];
CVOpen[];
            
img=CVLoadImage["CIMG3181.jpg",CVLoadImageGrayScale];
s=CVGetSize[img];
            
Image[CVGetImageArray[img,1,1]]
noyau=CVCreateMat[3,3,CV32F,1];
CVSetArray[noyau,1,N[{{1/9,1/9,1/9},{1/9,1/9,1/9},{1/9,1/9,1/9}}]]
img2=CVCreateImage[s,IplDepth8U,1];
CVFilter2D[img,img2,noyau];
            
Image[CVGetImageArray[img2,1,1]]
noyau=CVCreateMat[3,3,CV32F,1];
CVSetArray[noyau,1,N[{{1,0,-1},{1,0,-1},{1,0,-1}}]]
            
img3=CVCreateImage[s,IplDepth16S,1];
CVFilter2D[img,img3,noyau]
            
minmax=CVMinMaxLoc[img3]
img4=CVCreateImage[s,IplDepth8U,1];
CVConvertScale[img3,img4,0.5,127.0];
            
Image[CVGetImageArray[img4,1,1]]
img5=CVCreateImage[s,IplDepth16S,1];
CVLaplace[img,img5,3];
                
minmax=CVMinMaxLoc[img5]
img6=CVCreateImage[s,IplDepth8U,1];
range=minmax[[1,2]]-minmax[[1,1]];
CVConvertScale[img5,img6,255.0/range,-255.0*minmax[[1,1]]/range];
            
Image[CVGetImageArray[img6,1,1]]
img7=CVCreateImage[s,IplDepth16S,1];
xorder=1; yorder=1;
CVSobel[img,img7,xorder,yorder,3];
minmax=CVMinMaxLoc[img7];
img8=CVCreateImage[s,IplDepth8U,1];
range=minmax[[1,2]]-minmax[[1,1]];
CVConvertScale[img7,img8,255.0/range,-255.0*minmax[[1,1]]/range];
                
Image[CVGetImageArray[img8,1,1]]
img9=CVCreateImage[s,IplDepth8U,1];
seuilHaut=120.0;
seuilBas=60.0;
CVCanny[img,img9,seuilBas,seuilHaut,3];
            
Image[CVGetImageArray[img9,1,1]]
edit=CVJImageEditor["formes",True];
CVJShowImage[edit,img];
rectList = CVJGetPixelRectangleList[edit];
rect = Floor[rectList[[1]]]
            
img10=CVCreateImage[s,IplDepth8U,1];
CVConvertScale[img,img10,1.0,0.0];
CVRectangle[img10,rect,{0,0,0},1];
CVSetImageROI[img10,rect];
CVSmooth[img10,img10,CVGaussian,5,5,0.0];
CVResetImageROI[img10];
            
Image[CVGetImageArray[img10,1,1]]
CVClose[];
