mohmmad mustaf
New Member
Hello, I am looking for someone to help me
I designed an application to read the exam paper for the student, which consists of multiple-choice questions, so that the student shades the symbol for the correct answer in the form of a circle, as in Picture No. (1). When applying the attached code, several problems appear.
1- It does not read all the shaded circles. What are the best variables to make it read all?
2- When drawing the circles that were selected from the application, they do not appear on the screen, but rather appear as if they were drawn on a thumbnail as in the second image (see the white dots in the left corner from the top)
Please Help
I designed an application to read the exam paper for the student, which consists of multiple-choice questions, so that the student shades the symbol for the correct answer in the form of a circle, as in Picture No. (1). When applying the attached code, several problems appear.
1- It does not read all the shaded circles. What are the best variables to make it read all?
2- When drawing the circles that were selected from the application, they do not appear on the screen, but rather appear as if they were drawn on a thumbnail as in the second image (see the white dots in the left corner from the top)
Please Help
main:
#Region Project Attributes
#ApplicationLabel: Ellipse Detection
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ocl As OCVOpenCVLoader
Dim const MaxImageCount = 1
Dim srcIV(MaxImageCount),dstIV As ImageView
Dim srcBitmap(MaxImageCount),dstBitmap As Bitmap
Dim srcMat,tmpMat,dstMat As OCVMat
Dim selectedIndex As Int=0 'by default, select first picture
Dim mCore As OCVCore
Dim mUtils As OCVUtils
Dim mImgProc As OCVImgproc
Dim mCvType As OCVCvType
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
'--------------------------------------
'Prepare layout
'--------------------------------------
'Load our test pics
Dim k As Int
For k=0 To MaxImageCount -1
srcBitmap(k).Initialize(File.DirAssets,"test0.jpg") 'Image source: https://wallpaperbrowse.com/media/images/Images-3.jpg
srcIV(k).Initialize("srcIV")
srcIV(k).Gravity=Gravity.FILL
srcIV(k).Tag=k
Activity.AddView(srcIV(k),k*(120dip+10dip),0,100dip,100dip)
srcIV(k).Bitmap=srcBitmap(k)
Next
dstIV.Initialize("")
dstIV.Gravity=Gravity.FILL
Activity.AddView(dstIV, 0,100dip,300dip, 500dip ) 'keep aspect ratio.
mUtils.bitmapToMat1(srcBitmap(0),srcMat)
End Sub
Sub srcIV_Click
Dim IV As ImageView=Sender
Dim index As Int = IV.Tag
If index>=0 And index<=1 Then
selectedIndex = index
mUtils.bitmapToMat1(srcBitmap(selectedIndex),srcMat)
' CallSubDelayed(Me,"ProcessImage")
CallSubDelayed(Me,"processcircle")
End If
End Sub
Sub processcircle()
Dim edge As OCVMat
Dim circles As OCVMat
srcMat.copyTo(tmpMat)
dstBitmap.InitializeMutable(tmpMat.size.width, tmpMat.size.height)
mImgProc.cvtColor1(tmpMat, tmpMat, mImgProc.COLOR_RGBA2GRAY)
mImgProc.medianBlur(tmpMat, edge, 5)
circles.Initialize
' Detect circles
mImgProc.HoughCircles(edge, circles, mImgProc.HOUGH_GRADIENT, 1, edge.rows / 16, 80, 30, 0, 30)
Log(circles.rows & " " & circles.cols & " " & circles.depth)
Dim myColorScalar As OCVScalar
myColorScalar.Initialize3(255, 0, 0)
For i = 0 To circles.cols - 1
Try
Dim circleData() As Double
circleData = circles.get5(0, i)
' Extract circle information
Dim centerX As Double = circleData(0)
Dim centerY As Double = circleData(1)
Dim radius As Double = circleData(2)
' Adjust the center coordinates if needed based on the coordinate system
Dim adjustedCenterX As Double = centerX
Dim adjustedCenterY As Double =centerY' tmpMat.size.height - centerY ' Invert Y-axis if necessary
Dim P1 As OCVPoint
P1.Initialize(adjustedCenterX, adjustedCenterY)
mImgProc.circle(srcMat, P1, radius, myColorScalar, -1, 1, 2)
Log("Circle " & i & ": CenterX=" & adjustedCenterX & ", CenterY=" & adjustedCenterY & ", Radius=" & radius)
Catch
Log(LastException)
End Try
Next
mUtils.matToBitmap1(srcMat, dstBitmap)
dstIV.Bitmap = dstBitmap
End Sub
Sub Activity_Resume
processcircle
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub