Question about a simple OCR App with surface view component as preview

Good morning everyone,

I am starting to create a simple app that, at the moment, should at least save the image that I try to take with my camera to the download folder. The code I’m posting is this:

When I press the button, I see a slight flicker on the screen but then it doesn’t save anything. What am I doing wrong?

Check app permissions…

try the PictureCreated event and use the Surface_View1 component directly

unknown

Taifun

1 Like

I tried what you suggested Taifun:

but nothing. In short, this is the screen of the app I created:

When I click the “Take Photo” button, it seems like something happens, but when I go into a file manager, I don’t see anything in the “Download” folder. I would expect to find the photo I just took. The app is set up correctly, but the photo is not being taken. I am testing in “Kompanion” mode through qr code, but I also tried building the app into an APK to see if, as user Professional suggested, it was a permissions issue. However, it is not a permissions issue because, when I open the app for the first time, Android asks if I want to grant read and write permissions. Any other ideas? In the meantime, I am trying to read the documentation for the Surface View component, which seems quite sparse, honestly. Is it just me who dont know how to read documentation?

Anyway thank you for your replies. I’m waiting for more suggestions :grinning:

Okay, I finally managed to do it, it was nothing more than this:

1

I hadn’t realized that the image was being saved in this specific path. In the end, I don’t care much because now comes the trickier part. I should take that same image and convert the text present in the image into textual format. So, I’m using the OCR component. I tried messing around with it a bit, the text file gets saved but inside the text file there isn’t the converted text but instead there’s this error written:

{"OCRExitCode":3,"IsErroredOnProcessing":true,"ErrorMessage":["Not a valid base64 image. The accepted base64 image format is 'data:<content_type>;base64,<base64_image_content>'. Where 'content_type' like 'image/png' or 'image/jpg' or 'application/pdf' or any other supported type."],"ErrorDetails":"Not a valid base64 image. The accepted base64 image format is 'data:<content_type>;base64,<base64_image_content>'. Where 'content_type' like 'image/png' or 'image/jpg' or 'application/pdf' or any other supported type.","ProcessingTimeInMilliseconds":"0"}

This is my new block:

What am I doing wrong this time?

Why don’t you use the image from here?

Your path works only in the companion app

What is the response content?
Display it in a labrl to find it out

Taifun

I have made the changes you requested to make the code dynamic; I would have made them anyway later on. Initially, I had statically placed those values to test the code. I have also added the labels you asked for and found that as soon as it enters the OCR1.GotResponse block, it throws an error and the labels are not created. This is the new code:

And this is the app running:

Note that the value of the label is fixed at the second-to-last block; the last block is not even taken into consideration. Also, note that there is another error at the bottom where I can’t understand because the text is truncated.

Any idea of what could be?

you can mention someone by “@” @Luky_Lillo

and you can customize the screen error by screen error block
2aa3fea48b7de0a1048ee726e711d9d0b26bd5db

You can’t use the file component to read an image

As test display the response content in the label

Taifun

To respond to @Professional, at first I tried with @ but the message informed me that my level is too low to use that function. Nevertheless, I inserted the block you advised, but there are no errors or alerts, the only thing that happens after about ten seconds is that the application crashes. As for @Taifun, I modified the code as you told me, but when I try to take a photo, the label shows nothing. I am trying in every way to solve the situation, but I can’t understand where the problem lies. I even thought that it was the API that I hadn’t inserted, but the API key is included. There’s some piece I’m missing and I can’t figure it out.

The new code:

Oh and i tried to put the label even inside the if but nothing happen. The label still remain empty.

@Luky_Lillo Do you check that the file component scope is set to legacy/shared folder?

You are calling to check the OCR server status without checking the response… what about using the Got Server Status event and if the server is available, then continue with your logic?

Also if something is not working you should debug your blocks… for example display the image from the Picture Created event in another label as test

Taifun

Hello @Taifun and @Professional. I’m trying to interpret the test results but first, the screenshot of the test:

first of all, the image is generated, but I already knew this because I found the image in the path I mentioned earlier. As for the server response, I’m not sure how to interpret the result. What does begin 0, end -1, length 4514 mean? I imagine it means that the server has given a response and that it has generated the result in OCR? In any case, the situation remains the same. Regarding the scope for the component file, it is on legacy. As shown in the screenshot:

I remind you that I believe I am missing some steps that are currently escaping me. I am reading and re-reading the OCR documentation, but something is not clear to me; maybe I am missing something that could be obvious to a professional but not to someone who, like me, is still a beginner.

This is the new code:

The suggestion was

If free = UP
then continue with your logic, i.e. to upload your image

From the documentation https://docs.kodular.io/components/media/ocr/?h=ocr#got-response

Got Server Status

You will find here the server status from the ocr provider. Possible results are ‘UP’ or ‘DOWN’. ‘pro Usa1’ = Usa, East Coast. ‘pro Usa2’ = Usa, West Coast.

I’m not familiar with that component, but it looks like it is not working amymore?

Try an alternative? For example an extension… search the extensions directory App Inventor Extensions | Pura Vida Apps

Taifun

@Taifun you were right. The component OCR does not work anymore. I solved using another extension as you advised. And finally the working code:

The object “parsedText” got the result text to the end.
The other problem was that the image needed to be compressed because the camera was generating an image larger than 2MB, which is not allowed in the FREE version of ocr.space. I solved this issue in this way because I need to photograph the text from very close up. The compression plugin I added works very well, but it compresses the image too much, making it very, very grainy. It’s not over, though. Now I have to move on to the next step. If I have any other problems, I’ll contact you. Naturally, I thank you for all the help you have given me. You have been invaluable. I hope to see your messages in the future for other problems I might have. Thanks to all of you.