Xamarin Forms with BlinkId OCR Image Result - xamarin

From the IDocumentFaceRecognizer result, it returns a face image as an imagesource, but I need it as a byte array or stream. How can I get a reference to the original source, so I can save the image locally to my device?
Thanks

We already answer it on the Github, but I will post it here to keep everyone in the loop:
The original source is platform dependent and does not always exist in form of byte array. You can see how SDK creates ImageSource object on Android and on iOS. You can change the source code of these functions to adapt to your needs for the platform you are targeting.
Best regards

Related

How does ImageSource return bytes to the application

I would like to implement my own subclass of ImageSource. Xamarin Forms has FileImageSource, UriImageSource and several other subclasses of ImageSource, but none of them meets my needs.
To see how to implement an ImageSource subclass, I looked at implementation of FileImageSource on github (https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Core/FileImageSource.cs)
I expected to find that the subclass would override one or more ImageSource methods to actually read the image file and provide the bytes from the file to the calling platform. But source code of FileImageSource contains no such thing! In fact, they use the File only to override ImageSource.IsEmpty. How can this be? If an image is contained in a file, you need to read the file to display this image, don't you?
What am I missing? And if I want to implement my own subclass of ImageSource, how can my sublass return image data to the platform?
Edit
Thank you to everyone who proposed solving the issue in a different way and inquiring why exactly existing ImageSource subclasses do not serve my needs.
Even if there is a different way to solve my immediate issue, from an educational perspective it is still interesting to know how Xamarin Forms displays an image file without reading the file. The source code for FileImageSource is quite short and does not appear to use the file, other than to implement IsEmpty. This will bug me until I know how this works.
[Resolve the issue using converters]
Instead of creating a new ImageSource, you could create a Converter (if you are working with bindings).
So if you have something like a byte array, and you want that to be shown as an image, you can do the conversion from byte array into a StreamImageSource
[EDIT: Knowing how it works]
If you want to know how it works internally and how it transforms the File into the actual Image, you will have to go deeper into the code, and check the platform implementations.
For example here you have the android renderers. You will find the IImageSourceHandler.cs and the FontImageSourceHandler and the FileImageSourceHandler and so on.

Corona SDK, Lua

HELLLPPPPP!!!!! I am programming in Corona SDK, and I am trying to insert a backround image, with the following code ---local backround = display.newImage("bluebackround.jpg")--- But it does not want to show up in the simulator. It keeps giving me the following message in the output, ---Failed to find image 'bluebackround.jpg'---. My image is saved in the project folder. I am using Microsoft Windows software. I have done another project using Corona, and I inserted images completely fine. Anyone know what's going on with my code and how to fix it? Thank you very much in advance.
_W = display.contentWidth;
_H = display.contentHeight;
local image = display.newImageRect(--[["Name", width, heigth]] "bluebackround.jpg",_W, _H)
image.x = _W/2;
image.y = _H/2;
The your image need to be in the same folder as main.lua in your case. On the same level. Moreover, I think you misspell name of your image. You write 'bluebackround' without letter g in middle. So check name of the file.
From Corona documentation
Image guildelines:
Corona supports PNG and JPG format,
Images should not contain an embedded ICC profile,
Avoid progressive JPG files since they will take much longer to load.

Get Image Path on KitKat

Im having problem in my code in KITKAT OS. I want to get/display an image from gallery and decode it if its a higher size and its working fine for API lower than 19. But when I tried my app in KITKAT, I always get a null pointer exception because it returned.
content://com.android.providers.media.documents/document/image:62
I already look for solutions and found this.
input = context.getContentResolver().openInputStream(selectedImage);
bmp = BitmapFactory.decodeStream(input);
Its displaying the image but I'm missing one more step, that is to decode it since i cant get the exact file path of the image.
Bitmap imgbitmap = BitmapFactory.decodeFile(filepath, options_for_not_toobig);
How would I get the exact address of the image in KITKAT or how other way in decoding an image.
thanks
Try this code if Android version is kitkat:
ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r");
FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor();
bitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor);
parcelFileDescriptor.close();
Go through this link - https://developer.android.com/guide/topics/providers/document-provider.html
I've posted a answer in another post where similar issue is lifted. There youll find the method for getting the path in KitKat.
File Upload in WebView

Auto-cropping image with detection of crop-lines

I am working on a project, which is Android app that uses camera to capture a photo of some ticket and does OCR recognition for only a part of it. I have no previous experience in image processing, but I know it must be some kind of tricky way, because Android applications have small RAM limits.
I have not enough reputation points to post images so I give URLs to it.
Below, I attach image before any processing:
My aim is to automatically detect these lines of (---) and crop it so that final image look like this one:
What's more - it's important to stay open-source and do it without sending photo to some external image processing service.
You can try using Hough Transform to find the lines. OpenCV has a implementation that is open source and works on Android.
HoughLineP is a very efficient Version of the HoughTransform to find Line Segments.
Olena is definitely the way to go!. It's a generic image processing library, but the interesting part is an module that's called Scribo.
Scribo will do document analysis on the picture to extract text and/or image regions, and optionally send text regions to tesseract for recognition.
Being feasible for Android or not is something that I couldn't tell. I've tried it on OSX and Linux systems and it shows great potential.

Rotating the image of a picturebox that only has an ImageLocation

I have a card game program that when a card gets discarded and is found to be a certain type of card, it goes into my DefeatedChars pile, which is just a PictureBox named DefeatedChars. Currently all my images are loaded during runtime using ImageLocation which is the string of some website that stores all the card images. I want to know how to load this string to the PictureBox's Image property so I can rotate it because trying to rotate gives me a null pointer exception because Image is nothing, at least I think that's why. I do know through debugging that when DefeatedChars.Image is nothing. My question is, is there a way to rotate the ImageLocation after it's been loaded or is there a way to move the image found at the ImageLocation into the image property. Ultimately, when I'm done with the game, I want the image found at the image location to be stored somewhere locally so that if the website changes, which it does, the cards will retain their images and properties, but that's a question for later down the road. Here is the code I am stuck at that gives me a null pointer exception. I'm coding in Visual Studio.
DefeatedChars.ImageLocation = tempCard.ImageLocation
DefeatedChars.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
I tried this...
DefeatedChars.Image = Image.FromFile(tempCard.ImageLocation)
But I ran into a "URI formats are not supported error". Then I found this little gem on the internet, which replaces the first line of code above.
DefeatedChars.Image = Image.FromStream(System.Net.HttpWebRequest.Create(tempCard.ImageLocation).GetResponse().GetResponseStream())
It turns the URL into a stream so it can be used by the Image property and it works like a charm.

Resources