检测和作物文件移动设备——Xamarin的c#

本教程展示了如何捕捉文件和汽车作物他们生活在移动设备上查看c#使用LEADTOOLS SDK Xamarin的应用程序。

概述
总结 本教程介绍了如何访问现场捕获视频帧检测文档和汽车作物在c# Xamarin的应用程序。
完成时间 30分钟
Visual Studio项目 下载教程项目(510 KB)
平台 c# Xamarin的跨平台的应用程序
IDE Visual Studio 2019中,2017年
开发许可 下载LEADTOOLS

所需的知识

熟悉的基本步骤,创建一个项目并实施现场捕获通过审查添加引用和设置一个许可证住捕获与Xamarin的相机控制集成教程,在工作之前检测和作物文件移动设备——Xamarin的c#教程。

创建项目并添加LEADTOOLS引用

在Visual Studio中,创建一个新的c# Xamarin的项目,并添加以下必要LEADTOOLS引用。

的引用需要取决于项目的目的。对于这个项目,还需要以下NuGet包:

设置许可文件

许可解锁项目需要的特性。它必须设置工具箱函数被调用之前。详情,包括教程为不同的平台,请参考设置一个运行时许可

有两种类型的运行时许可证:

请注意

添加LEADTOOLS NuGet引用和设置许可中会详细介绍添加引用和设置一个许可证教程。

调整生活捕捉代码

与项目创建、添加引用,许可,可以开始编码。

解决方案资源管理器,打开LiveCapturePage.xaml。编辑xaml代码的代码如下所示:

<StackLayout><!——主要网格容器一切><网格x: Name = " mainGrid HorizontalOptions =“FillAndExpand VerticalOptions”=“FillAndExpand”><Grid.ColumnDefinitions><ColumnDefinition x: Name = " c0宽度= " * " /><ColumnDefinition x: Name = " c1宽度= " * " /><ColumnDefinition x: Name = " c2宽度= " * " /></ Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition x: Name = =“*”/“r0”高度><RowDefinition x: Name = =“*”/“r1”高度><RowDefinition x: Name = =“*”/“r2”高度><RowDefinition x: Name = =“*”/“r3”高度><RowDefinition x: Name = =“*”/“r4”高度><RowDefinition x: Name = =“*”/“r5”高度><RowDefinition x: Name = =“*”/“r6”高度><RowDefinition x: Name = =“*”/“r7”高度><RowDefinition x: Name = =“*”/“r8”高度></ Grid.RowDefinitions><名称空间:CameraView x: Name = " leadCamera”网格。行= " 0 "网格。网格列= " 0 "。ColumnSpan = " 3 "网格。行宽= " 8 " HorizontalOptions = VerticalOptions =“FillAndExpand”/“FillAndExpand”><按钮x: Name = " liveCapture "文本=“实时捕获”网格。行= " 8 "网格。点击列= " 1 " = " liveCapture_Clicked " /></网格></ StackLayout>

右键单击页面并选择视图代码或按F7,将背后的代码页。下面是在确保语句使用块。

c#
使用系统;使用Xamarin.Forms;使用Xamarin.Forms.Xaml;使用Leadtools;使用Leadtools.Camera.Xamarin;使用Leadtools.ImageProcessing.Core;

下面的全局变量添加到类中。

c#
AutoCapture AutoCapture =AutoCapture ();

修改liveCapture_Clicked(对象发送方,EventArgs e)活动包括以下代码。

c#
私人无效liveCapture_Clicked (对象发送方的EventArgs e){/ /利用现场捕获按钮将钩FrameReceived事件处理程序,允许处理每一帧如果(liveCapture。文本= =“实时捕捉”){liveCapture。文本=“停止”;leadCamera。FrameReceived + = LeadCamera_FrameReceived;leadCamera.Camera。FocusMode = Leadtools.Camera.Xamarin.FocusMode.Continuous;autoCapture。CaptureMethod = AutoCapture.AutoCaptureMethod.DocumentDetection;}其他的{liveCapture。文本=“实时捕捉”;leadCamera。FrameReceived - = LeadCamera_FrameReceived;}}

修改LeadCamera_FrameReceived (Leadtools.Camera.Xamarin。FrameHandlerEventArgs e)活动包括以下代码。这个事件引发了汽车检测、作物,噪声去除在移动设备的图片,并将其发送到图像查看器。

c#
私人无效LeadCamera_FrameReceived (Leadtools.Camera.Xamarin。FrameHandlerEventArgs e){使用(RasterImage _img = e.Image.Clone ()){如果(autoCapture.CheckHoldStability (_img)){leadCamera。FrameReceived - = LeadCamera_FrameReceived;RasterImage _image = e.Image.Clone ();PerspectiveDeskewCommand _cmd =PerspectiveDeskewCommand ();_cmd.Run (_image);Device.BeginInvokeOnMainThread (() = >{App.Current。主页=NavigationPage (ViewerPage (_image));});}}}

添加图像浏览器的代码

解决方案资源管理器,右键单击并选择c#项目添加- >新项目。选择内容页选择和名称ViewerPage.xaml

添加xaml下面的代码创建网格,将主办imageview对象。

<网格x: Name = " imageViewerContainer HorizontalOptions =“FillAndExpand”VerticalOptions =写成BackgroundColor =“黑色”/“FillAndExpand”>

右键单击页面并选择视图代码或按F7,将背后的代码页。下面是在确保语句使用块。

c#
使用系统;使用Xamarin.Forms;使用Xamarin.Forms.Xaml;使用Leadtools;使用Leadtools.Controls;

下面的全局变量添加到类中。

c#
私人RasterImage _image;

ViewerPage ()公共方法,添加RasterImage文档它的参数。添加的代码ViewerPage (RasterImage文档)方法。

c#
公共ViewerPage (RasterImage文档){InitializeComponent ();_image =文档;InitImageViewer ();}

创建一个新的命名方法InitImageViewer ()。将下面的代码添加到初始化imageview并设置文档图像。确保内部调用这个方法ViewerPage ()方法,如上所示。

c#
私人异步无效InitImageViewer (){imageview _imageViewer =imageview{ViewHorizontalAlignment = ControlAlignment.Center,ViewVerticalAlignment = ControlAlignment.Center,写成BackgroundColor = Color.FromHex (“# 1 e1e1e”),VerticalOptions = LayoutOptions.FillAndExpand,HorizontalOptions = LayoutOptions.FillAndExpand,利润=厚度(0,0),AutoDisposeImages =真正的,};网格。SetRow (_imageViewer 0);网格。SetRowSpan (_imageViewer, 1);ImageViewerPanZoomInteractiveMode panZoom =ImageViewerPanZoomInteractiveMode ();_imageViewer.InteractiveModes.Add (panZoom);_imageViewer.Zoom (ControlSizeMode。FitAlways, 1.0, _imageViewer.DefaultZoomOrigin);imageViewerContainer.Children.Add (_imageViewer);_imageViewer。形象= _image;}

上面的代码主要是来源于显示图像的图像查看器教程。

运行该项目

选择所需的项目(iOS和Android)和运行项目按F5,或通过选择调试- >开始调试

如果是正确的步骤,应用程序运行,它将要求允许相机权限是必需的。用于测试,点击捕捉生活按钮底部的设备的屏幕。从设备的相机预览会显示在CameraView。按住相机仍然文档,保持整个文档在相机视图中。文档将被检测到,裁剪,然后显示在imageview

总结

本教程演示了如何使用CameraView,AutoCapture,PerspectiveDeskewCommand文档类来检测和作物使用移动设备的相机。

另请参阅

iOS
188金宝搏的网址客服|支持|联系我们|知识产权的通知
©1991 - 2023领先的技术公司。保留所有权利。