Auto Get text from camera || OCR in sketchware || free project | Sketchware pro tutorial
Hey fellow sketchware coders,
I know many of you are working on some projects which requires ocr (optical character recognition) But not getting success in ocr. So Today I am here to present sketchware ocr project and tutorial.
Note: All files and links are provided below this article.
Some examples of app where you can use ocr
• Questions search app
• Tanslator app
• Also you can modify it for extracting text from pictures
In this project only realtime ocr is made. If you want text from pictures ocr. Then comment below this post.
To start,
Make a project in sketchware
You need to have google vision library. If you don't have then please download it and if you have then enable it.
After that you need to make your app design
You'll need
1. A linear for making of camera layout
2. A textview for getting text.
Look at my example
In this example linear1 is main layout. Linear2 is camera layout. and textview1 is textview for getting text. Other linears are just for other use.
Turning on essential library
You need to turn on Google map library ( no need of Google map api key.)
First with name locate_vrb
Second with name process
In first moreblock locate_vrb add a asd with code
Code:-
}
com.google.android.gms.vision.CameraSource cameraSource;
SurfaceView cameraView;
{
In second moreblock process add this asd code
com.google.android.gms.vision.text.TextRecognizer textRecognizer = new com.google.android.gms.vision.text.TextRecognizer.Builder(getApplicationContext()).build();
if (!textRecognizer.isOperational()) {
android.util.Log.w("MainActivity", "Detector dependencies are not yet available");
} else {
cameraSource = new com.google.android.gms.vision.CameraSource.Builder(getApplicationContext(), textRecognizer)
.setFacing(com.google.android.gms.vision.CameraSource.CAMERA_FACING_BACK)
.setRequestedPreviewSize(1280, 1024)
.setRequestedFps(2.0f)
.setAutoFocusEnabled(true)
.build();
}
cameraView.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder surfaceHolder) {
try {
cameraSource.start(cameraView.getHolder());
} catch (java.io.IOException e) {
e.printStackTrace();
}
}
@Override
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i1, int i2) {}
@Override
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
cameraSource.stop();
}
});
textRecognizer.setProcessor(new com.google.android.gms.vision.Detector.Processor<com.google.android.gms.vision.text.TextBlock>() {
@Override
public void release() {
}
@Override
public void receiveDetections(com.google.android.gms.vision.Detector.Detections<com.google.android.gms.vision.text.TextBlock> detections) {
final SparseArray<com.google.android.gms.vision.text.TextBlock> items = detections.getDetectedItems();
if(items.size() != 0)
{
textview1.post(new Runnable() {
@Override
public void run() {
StringBuilder stringBuilder = new StringBuilder();
for(int i =0;i<items.size();++i)
{
com.google.android.gms.vision.text.TextBlock item = items.valueAt(i);
stringBuilder.append(item.getValue());
stringBuilder.append("\n");
}
textview1.setText(stringBuilder.toString());
}
});
}
}
});
//Change textview1 with your TextView Id
In oncreate event add a asd code
cameraView = new SurfaceView(this);
linear2.addView(cameraView);
Here linear2 is view containing camera you can change it.
Also add process moreblock in it.
Final step:-
Add a camera component for camera permissions.
After that run this project and now you have a working ocr app in sketchware.
If you got any error, then comment below this post. I'll surely reply to comment
Comments