private void CreateSegmentAnalyzer() { // Create a segmentation analyzer. You can create an analyzer using the provided customized face detection parameter: MLImageSegmentationSetting MLImageSegmentationSetting setting = new MLImageSegmentationSetting.Factory() .SetExact(false) .SetScene(MLImageSegmentationScene.ForegroundOnly) .SetAnalyzerType(MLImageSegmentationSetting.BodySeg) .Create(); this.analyzer = MLAnalyzerFactory.Instance.GetImageSegmentationAnalyzer(setting); this.analyzer.SetTransactor(new MLTransactor(this)); }
private async void Analyze() { /** * Configure image segmentation analyzer with custom parameter MLImageSegmentationSetting. * * SetExact(): Set the segmentation fine mode, true is the fine segmentation mode, * and false is the speed priority segmentation mode. * SetAnalyzerType(): Set the segmentation mode. When segmenting a static image, support setting * MLImageSegmentationSetting.BodySeg (only segment human body and background) * and MLImageSegmentationSetting.ImageSeg (segment 10 categories of scenes, including human bodies) * SetScene(): Set the type of the returned results. This configuration takes effect only in * MLImageSegmentationSetting.BodySeg mode. In MLImageSegmentationSetting.ImageSeg mode, * only pixel-level tagging information is returned. * Supports setting MLImageSegmentationScene.All (returns all segmentation results, * including: pixel-level tag information, portrait images with transparent backgrounds * and portraits are white, gray background with black background), * MLImageSegmentationScene.MaskOnly (returns only pixel-level tag information), * MLImageSegmentationScene.ForegroundOnly (returns only portrait images with transparent background), * MLImageSegmentationScene.GrayscaleOnly (returns only grayscale images with white portrait and black background). */ MLImageSegmentationSetting setting = new MLImageSegmentationSetting.Factory() .SetExact(false) .SetAnalyzerType(MLImageSegmentationSetting.BodySeg) .SetScene(MLImageSegmentationScene.All) .Create(); this.analyzer = MLAnalyzerFactory.Instance.GetImageSegmentationAnalyzer(setting); // Create an MLFrame by using android.graphics.Bitmap. Recommended image size: large than 224*224. MLFrame mlFrame = new MLFrame.Creator().SetBitmap(this.mBitmapTarget).Create(); Task <MLImageSegmentation> task = this.analyzer.AnalyseFrameAsync(mlFrame); try { await task; if (task.IsCompleted && task.Result != null) { // Analyze success var imageSegmentationResult = task.Result; this.DisplaySuccess(imageSegmentationResult); } else { // Analyze failure this.DisplayFailure(); } } catch (Exception e) { // Operation failure this.DisplayFailure(); } }