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.


Look at this example your app will do function like this.

Turn on your Google vision library.



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.)

After turning on Google map library come back and make 2 moreblocks.
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
Code 2:-

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 

Code 3 :- 

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

Popular posts from this blog

Sketchware Generate Firebase Dynamic Link (Long Url To Short) | sketchware blocks explained

what is sketchware and history of sketchware

How to import local library in sketchware

Create HTML Dialog in Sketchware

Create Percentage loading bar in sketchware

how to import export custom blocks sketchware

Sketchware Generate Firebase Dynamic Link (Long Url To Short) | sketchware blocks explained

Android 10/11 Storage Permission sketchware | New blocks + method

Image filter moreblocks for making black and white imageview