Sub ProcessImage
Dim edge As OCVMat
Dim contours As List
Dim hierarchy As OCVMat
Dim offset As OCVPoint
Dim i As Int
Dim p As Double, a As Double
srcMat.copyTo( tmpMat) ' Clone source
dstBitmap.InitializeMutable(tmpMat.size.width,tmpMat.size.height)
mImgProc.cvtColor1(tmpMat,tmpMat,mImgProc.COLOR_RGBA2GRAY)
mImgProc.Canny3(tmpMat,edge,50,150)
offset.Initialize(0, 0)
contours.Initialize
mImgProc.findContours(edge, contours, hierarchy, mImgProc.RETR_EXTERNAL, mImgProc.CHAIN_APPROX_NONE, offset)
Dim myColorScalar As OCVScalar
myColorScalar.Initialize3(255,0,255)
For i=0 To contours.Size-1
Dim mat As OCVMatOfPoint = contours.Get(i)
Dim pnt() As OCVPoint = mat.toArray
Dim mat2 As OCVMatOfPoint2f
mat2.Initialize3(pnt)
p = mImgProc.arcLength(mat2, False)
a = mImgProc.contourArea(contours.Get(i), False)
Log("area: " & a & " perimeter: " & p)
If Abs(1-p*p/(4*3.1413*a))<0.2 Then
mImgProc.drawContours1(srcMat, contours, i, myColorScalar, 2)
End If
Next
mUtils.matToBitmap1(srcMat,dstBitmap)
dstIV.Bitmap = dstBitmap
End Sub