This is a shortcut wrap for this Github project. It will scan a "document" and bring back a bitmap of the scanned "document" to the B4A project via event xxx_scan_result. You need to download the 2 x jar, 1 x xml, and 1x aar from the following link and copy them to your additional library folder:
https://drive.google.com/drive/folders/1Xr7EW7gANjwzP5urGkmvneokKHvXH1fw
Attached the following:
1. The zipped B4A project - b4aLiveEdgeDetection.zip
2. LibRes.zip - extract it and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project
3. openCVres.zip - extract it and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project
4. resource.zip - extract it and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project
What does it do?
1. It detects the edges of a "document" if the background is sufficiently dark
2. It will guide you (while the scanner is active) to position the camera correctly
3. It will automatically take a picture of the "document" once it is satisfied with the orientation/background/distance
4. Once the pic has been taken, you can crop the image - use the handles
5. When you click on the "tick mark" it will return the bitmap to your B4A project. You need to handle the bitmap from here onwards (eg save it to a png file)
It was quite challenging to get this lib compiled and to be able to "kick start" it from within B4A. The ConstraintLayout kept me busy for some time...
Sample B4A code:
B4A Manifest:
Library:
LiveEdgeDetection
Author: Github: Aditya Arora, Wrapped by: Johan Schoeman
Version: 1
Hope I have posted all that will be required....
https://drive.google.com/drive/folders/1Xr7EW7gANjwzP5urGkmvneokKHvXH1fw
Attached the following:
1. The zipped B4A project - b4aLiveEdgeDetection.zip
2. LibRes.zip - extract it and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project
3. openCVres.zip - extract it and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project
4. resource.zip - extract it and copy the folder with its contents to be on the same folder level as that of the /Files and /Objects folders of the B4A project
What does it do?
1. It detects the edges of a "document" if the background is sufficiently dark
2. It will guide you (while the scanner is active) to position the camera correctly
3. It will automatically take a picture of the "document" once it is satisfied with the orientation/background/distance
4. Once the pic has been taken, you can crop the image - use the handles
5. When you click on the "tick mark" it will return the bitmap to your B4A project. You need to handle the bitmap from here onwards (eg save it to a png file)
It was quite challenging to get this lib compiled and to be able to "kick start" it from within B4A. The ConstraintLayout kept me busy for some time...
Sample B4A code:
B4X:
#Region Project Attributes
#ApplicationLabel: b4aLiveEdgeDetection
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#AdditionalRes: ..\resource
#AdditionalRes: ..\openCVres
#AdditionalRes: ..\LibRes
#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.
Private Button1 As Button
Private led As LiveEdgeDetection
Private ImageView1 As ImageView
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("main")
led.Initialize("led")
ImageView1.Visible = False
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
led.startDetection
End Sub
Sub led_scan_result(result As Object)
Dim mb As Bitmap = result
ImageView1.Bitmap = mb
ImageView1.Visible = True
End Sub
B4A Manifest:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<activity android:name="com.adityaarora.liveedgedetection.activity.ScanActivity">
</activity>)
'End of default text.
Library:
LiveEdgeDetection
Author: Github: Aditya Arora, Wrapped by: Johan Schoeman
Version: 1
- LiveEdgeDetection
Events:- scan_result (image As Object)
- startDetection As void
- IsInitialized As boolean
- Initialize (paramBA As anywheresoftware.b4a.BA, paramString As java.lang.String) As void
- android.hardware.camera
- android.permission.CAMERA
- android.permission.READ_EXTERNAL_STORAGE
- android.permission.WRITE_EXTERNAL_STORAGE
Hope I have posted all that will be required....
Attachments
Last edited: