Capture and Crop a Document in Xamarin
source link: https://www.leadtools.com/blog/document-imaging/xamarin-document-live-capture-crop/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Capture and Crop a Document in Xamarin
LEADTOOLS Camera Control for Xamarin makes app development easier by managing device-specific nuances for you and giving you access to a buffer for frame-by-frame control. Using this powerful tool allows you to capture, edit, and save video, audio, and image data. Better yet, pass each frame to LEADTOOLS Barcode Recognition or OCR to discern the data the camera is recording.
In this post, we’ll show you how easy it is to scan a document using LEADTOOLS. Typically, a user has to take a very precise picture of the document, checking to make sure it’s not blurry and that all 4 corners are present in the image. With LEADTOOLS, users can take advantage of AutoCapture as well as various other image processing functions to automatically capture the best possible image of the document and crop to just the needed document area.
Below are C# and XML code samples that use the FrameReceived event, AutoCapture class, and PerspectiveDeskewCommand class together to capture the frame with the document in it and crop to the document.
C# Code
AutoCapture autoCapture = new AutoCapture();
public LiveCapturePage()
{
InitializeComponent();
leadCamera.CameraOptions.AutoRotateImage = true;
autoCapture.CaptureMethod = AutoCapture.AutoCaptureMethod.DocumentDetection;
leadCamera.FrameReceived += LeadCamera_FrameReceived;
}
private void LeadCamera_FrameReceived(Leadtools.Camera.Xamarin.FrameHandlerEventArgs e)
{
using (RasterImage img = e.Image.Clone())
{
if (autoCapture.CheckHoldStability(img))
{
leadCamera.FrameReceived -= LeadCamera_FrameReceived;
RasterImage image = e.Image.Clone();
PerspectiveDeskewCommand cmd = new PerspectiveDeskewCommand();
cmd.Run(image);
// Code here to pass to a DocumentViewer content page or to export to the mobile device.
}
}
}
<ContentPage.Content>
<StackLayout>
<!--main grid container for everything-->
<Grid x:Name="mainGrid" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<namespace:CameraView x:Name="leadCamera" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</Grid>
</StackLayout>
</ContentPage.Content>
For more information on the Xamarin Camera Control, check out our full tutorial!
See for yourself – Get a Free evaluation
Download the LEADTOOLS SDK for free. It’s fully-functional for 60 days and comes with free chat and email support.
Need Assistance? LEAD Is Here For You
Need help while you wait for more blogs and tutorials? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team via email or call us at 704-332-5532.
About Hadi
Developer Support Manager
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK