Needs["CV`"];
CVOpen[];
            
img=CVLoadImage["formes1.png",CVLoadImageGrayScale];
s=CVGetSize[img];
            
bin=CVCreateImage[s,IplDepth8U,1];
CVThreshold[img,bin,200.0,255.0,CVThreshBinaryInv];
            
Image[CVGetImageArray[bin,1,1]]
mem = CVCreateMemStorage[0];
cont1=CVFindContours[bin,mem,CVRetrExternal,CVChainApproxNone,{0,0}];
c1=CVGetContour[cont1];
p=CVContourPerimeter[cont1]
cont2=CVGetSeqHNext[cont1];
c2=CVGetContour[cont2];
            
liste={};
cont=cont1;
While[cont!=0,
        c=CVGetContour[cont];
        c=CVFlipY[s,c];
        liste=Append[liste,c];
        cont = CVGetSeqHNext[cont];
      ];
            
ListPlot[liste,PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
cont=CVFindContours[bin,mem,CVRetrList,CVChainApproxNone,{0,0}];
liste={}
While[cont!=0,
        c=CVFlipY[s,CVGetContour[cont]];
        liste=Append[liste,c];
        cont = CVGetSeqHNext[cont];
      ];
            
ListPlot[liste,PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
cont=CVFindContours[bin,mem,CVRetrCcomp,CVChainApproxNone,{0,0}];
c=CVFlipY[s,CVGetContour[cont]];
            
ListPlot[c,PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
cont=CVGetSeqHNext[cont];
c=CVFlipY[s,CVGetContour[cont]];
            
ListPlot[c,PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
vnext=CVGetSeqVNext[cont]
c=CVFlipY[s,CVGetContour[vnext]];
            
ListPlot[c,PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
img=CVLoadImage["formes2.png",CVLoadImageGrayScale];
s=CVGetSize[img];
bin=CVCreateImage[s,IplDepth8U,1];
CVThreshold[img,bin,100.0,255.0,CVThreshBinary];
                
Image[CVGetImageArray[bin,1,1]]
cont1=CVFindContours[bin,mem,CVRetrTree,CVChainApproxNone,{0,0}];
c1=CVFlipY[s,CVGetContour[cont1]];
cont2=CVGetSeqVNext[cont1];
c2=CVFlipY[s,CVGetContour[cont2]];
                
ListPlot[{c1,c2},PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
cont3=CVGetSeqVNext[cont2];
c3=CVFlipY[s,CVGetContour[cont3]];
cont4=CVGetSeqVNext[cont3];
c4=CVFlipY[s,CVGetContour[cont4]];
cont5=CVGetSeqHNext[cont3];
c5=CVFlipY[s,CVGetContour[cont5]];
cont6=CVGetSeqVNext[cont5];
c6=CVFlipY[s,CVGetContour[cont6]];
                
ListPlot[{c3,c4,c5,c6},PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
cont7=CVGetSeqVNext[cont4];
c7=CVFlipY[s,CVGetContour[cont7]];
cont8=CVGetSeqVNext[cont7];
c8=CVFlipY[s,CVGetContour[cont8]];
cont9=CVGetSeqHNext[cont7];
c9=CVFlipY[s,CVGetContour[cont9]];
cont10=CVGetSeqVNext[cont9];
c10=CVFlipY[s,CVGetContour[cont10]];
                
ListPlot[{c7,c8,c9,c10},PlotRange->{{0,s[[1]]},{0,s[[2]]}},AspectRatio->1]
rect=CVMinAreaRect2[cont7]
ellipse=CVFitEllipse2[cont1];
CVClose[];
