From f14642fb00e5347e4c797d09e22ebe96c75bfa62 Mon Sep 17 00:00:00 2001 From: Tae-Young Chung Date: Tue, 26 Sep 2017 16:50:07 +0900 Subject: [PATCH] Add guide documentation of Tizen.Multimedia.Vision PS4: Reviewed PS6: Added the gateway topic back in. PS7: Synced the gateway topic with the native version Change-Id: I69254bd7c1378cb16c40930e82266c2c235fab31 Signed-off-by: Tae-Young Chung --- .../html/dotnet/media/vision/face_detection_cs.htm | 294 ++++++++++++++ .../html/dotnet/media/vision/image_barcode_cs.htm | 442 +++++++++++++++++++++ .../dotnet/media/vision/image_recognition_cs.htm | 283 +++++++++++++ .../html/dotnet/media/vision/media_vision_cs.htm | 72 ++++ 4 files changed, 1091 insertions(+) create mode 100644 org.tizen.guides/html/dotnet/media/vision/face_detection_cs.htm create mode 100644 org.tizen.guides/html/dotnet/media/vision/image_barcode_cs.htm create mode 100644 org.tizen.guides/html/dotnet/media/vision/image_recognition_cs.htm create mode 100644 org.tizen.guides/html/dotnet/media/vision/media_vision_cs.htm diff --git a/org.tizen.guides/html/dotnet/media/vision/face_detection_cs.htm b/org.tizen.guides/html/dotnet/media/vision/face_detection_cs.htm new file mode 100644 index 0000000..e9ea5b4 --- /dev/null +++ b/org.tizen.guides/html/dotnet/media/vision/face_detection_cs.htm @@ -0,0 +1,294 @@ + + + + + + + + + + + + + Face Detection, Recognition, and Tracking + + + + + +
+ +

Face Detection, Recognition, and Tracking

+ +

You can detect a face in an image, or track a face in the device camera preview.

+ +

The main face detection, recognition, and tracking features include:

+ +
    +
  • Detecting faces +

    You can decode an image file and detect faces on it.

    +
  • +
  • Recognizing faces +

    You can recognize faces in an image with a set of example faces.

    +
  • +
  • Tracking faces +

    You can track faces using the camera preview images, starting from a specific location in the image.

    +
  • +
+ +

Prerequisites

+ +

To enable your application to use the face detection, recognition, and tracking functionality:

+
    +
  1. Install the Nuget packages for Media Vision and Camera.
  2. +
  3. To use the methods and properties of the face detection, tracking, and recognition classes and to handle camera preview, include the Tizen.Multimedia namespace in your application: +
    +using Tizen.Multimedia;
    +
    +
  4. +
  5. Define the configuration settings: +
      +
    • For face detection, create an instance of the Tizen.Multimedia.FaceDetectionConfiguration class and set its properties accordingly: +
      +static FaceDetectionConfiguration configDetection = new FaceDetectionConfiguration();
      +
      +/// Set a model path if you want to save your own model in a certain place
      +configDetection.ModelFilePath = "app_path/your_own_model";
      +
      +/// Set a minimum face size if you want to detect only larger faces
      +configDetection.MinWidth = 50;
      +configDetection.MinHeight = 50;
      +
      +/// Set a region of interest if you want to detect in a specific region
      +configDetection.Roi = new Rectangle(10, 10, 20, 30);
      +
      +
    • +
    • For face recognition, create an instance of the Tizen.Multimedia.FaceRecognitionConfiguration class and set its properties accordingly: +
      +static FaceRecognitionConfiguration configRecog = new FaceRecognitionConfiguration();
      +
      +/// Set the face recognition learning model algorithm to one of the
      +/// values of the Tizen.Multimedia.FaceRecognitionModelType enumeration
      +configRecog.ModelType = FaceRecognitionModelType.lbph;
      +
      +
    • +
    • For face tracking, no configuration is needed.
    • +
    +
  6. +
+ +

Detecting Faces

+ +

To detect faces:

+ +
    +
  1. Create an instance of the Tizen.Multimedia.MediaVisionSource class with raw image buffer data and its corresponding width, height, and color space parameters: +
    +/// Assume that there is a decoded raw data buffer of the byte[] type, and
    +/// it has 640x480 resolution with an RGB888 color space
    +
    +MediaVisionSource source = new MediaVisionSource(bytes, width, height, ColorSpace.Rgb888);
    +
    +
  2. +
  3. To detect faces, use the DetectAsync() method of the Tizen.Multimedia.FaceDetector class: +
    +var faceLists = await FaceDetector.DetectAsync(source);
    +
    +/// If you want to change the face detection configuration, use an instance
    +/// of the Tizen.Multimedia.FaceDetectionConfiguration class as a
    +/// parameter for the DetectAsync() method
    +/// For example,
    +/// var faceLists = await FaceDetector.DetectAsync(source, configDetection);
    +
    +foreach (Rectangle location in faceLists)
    +{
    +    Log.Info("Face detection sample", $"location is {location}");
    +}
    +
    +
  4. +
+ +

Recognizing Faces

+ +

To recognize faces:

+ +
    +
  1. Create an instance of the Tizen.Multimedia.FaceRecognitionModel class and add face examples to it with the Add() method. +

    Face examples need to be of the same person but captured at different angles. The example assumes that 10 face samples are used and that the face area in each example covers approximately 95~100% of the image. The face to be recognized is given the label "1".

    +
    +static FaceRecognitionModel model = new FaceRecognitionModel();
    +
    +/// faceExamples contains 10 face examples as instances
    +/// of the Tizen.Multimedia.MediaVisionSource class
    +foreach (MediaVisionSource example in faceExamples)
    +{
    +    model.add(example, 1);
    +}
    +
    +
  2. +
  3. Learn the face recognition model based on the provided examples with the Learn() method: +
    +model.Learn();
    +
    +
  4. +
  5. To recognize a face, use the RecognizeAsync() method of the Tizen.Multimedia.FaceRecognizer class: +
    +/// whoFaceSource is an instance of the Tizen.Multimedia.MediaVisionSource class
    +/// that contains the face to be recognized
    +/// whoFaceRoi is an instance of the Tizen.Multimedia.Rectangle struct that defines
    +/// a region of interest containing the face to be recognized
    +var result = await FaceRecognizer.RecognizeAsync(whoFaceSource, model, whoFaceRoi);
    +
    +Log.Info("Face recognition sample", $"confidence is {result.Confidence}");
    +Log.Info("Face recognition sample", $"success is {result.Success}");
    +if (result.Success)
    +{
    +    Log.info("Face recognition sample", $"label is {result.Label}");
    +}
    +
    +
  6. +
+ +

Tracking Faces

+ +

To track faces:

+ +
    +
  1. Prepare the camera: +
      +
    1. Define a camera preview event handler for the Preview event of the Tizen.Multimedia.Camera class and create an instance of that class: +
      +/// Define a camera preview event handler
      +static void PreviewCallback(object sender, PreviewEventArgs e)
      +{
      +    PreviewData preview = e.Preview;
      +
      +    SinglePlane singlePlane = (SinglePlane)preview.Plane;
      +    if (preview.Format == CameraPixelFormat.Rgb888)
      +    {
      +        MediaVisionSource source = new MediaVisionSource(singlePlane.Data, preview.width, preview.height, ColorSpace.Rgb888);
      +    }
      +}
      +
      +/// Create the Tizen.Multimedia.Camera instance
      +static Camera camera = null;
      +try
      +{
      +    camera = new Camera(CameraDevice.Rear);
      +}
      +catch (NotSupportedException)
      +{
      +    Log.Info("Face Detection Sample", "NotSupported");
      +}
      +
      +
    2. +
    3. Set the camera display, register the camera preview event handler, and start the camera preview with the StartPreview() method of the Tizen.Multimedia.Camera class: +
      +/// Set the camera display
      +camera.Display = new Display(new Window("Preview"));
      +
      +/// Register the camera preview event handler
      +camera.Preview += PreviewCallback;
      +
      +IList previewFormats = camera.Feature.SupportedPreviewPixelFormats.ToList();
      +foreach (CameraPixelFormat previewFormat in previewFormats)
      +{
      +    camera.Setting.PreviewPixelFormat = previewFormat;
      +    break;
      +}
      +
      +/// Start the camera preview
      +camera.StartPreview();
      +
      +
    4. +
    +
  2. +
  3. Manage face tracking: +
      +
    1. Set the initial tracking location. +

      In the following example, the DetectAsync() method of the Tizen.Multimedia.FaceDetector class is used to detect a face and provide its initial location:

      +
      +var faceLocation = await FaceDetector.DetectAsync(source);
      +
      +Point[] initialPoint =
      +{
      +    new Point(faceLocation.Left, FaceLocation.Top),
      +    new Point(faceLocation.Right, FaceLocation.Top),
      +    new Point(faceLocation.Right, FaceLocation.Bottom),
      +    new Point(faceLocation.Left, FaceLocation.Bottom)
      +};
      +
      +
    2. +
    3. Create an instance of the Tizen.Multimedia.FaceTrackingModel class and prepare the model with the initial location: +
      +Quadrangle faceLocation = new Quadrangle(initialPoint);
      +
      +static FaceTrackingModel model = new FaceTrackingModel();
      +
      +model.Prepare(source, faceLocation);
      +
      +
    4. +
    5. To track the face, use the TrackAsync() method of the Tizen.Multimedia.FaceTracker class: +
      +var result = await FaceTracker.TrackAsync(source, model, false);
      +if (result.Region != null)
      +{
      +    Log.Info("Face tracking sample", $"location is {result.Region}");
      +}
      +
      +
    6. +
    7. When face tracking is no longer needed, deregister the camera preview event handler, stop the camera preview, and destroy the camera instance: +
      +camera.Preview -= PreviewCallback;
      +
      +camera.StopPreview();
      +camera.Dispose();
      +
      +
    8. +
    +
  4. +
+ + + +
+ +Go to top + + + + + + + diff --git a/org.tizen.guides/html/dotnet/media/vision/image_barcode_cs.htm b/org.tizen.guides/html/dotnet/media/vision/image_barcode_cs.htm new file mode 100644 index 0000000..27a9268 --- /dev/null +++ b/org.tizen.guides/html/dotnet/media/vision/image_barcode_cs.htm @@ -0,0 +1,442 @@ + + + + + + + + + + + + + Barcode Detection and Generation + + + + + +
+ +

Barcode Detection and Generation

+ +

You can perceive and understand an image or extract information from images in your application.

+ +

The main barcode detection and generation features include:

+ + + +

Prerequisites

+ +

To enable your application to use the barcode detection and generation functionality:

+
    +
  1. Install the Nuget packages for Media Vision and Camera.
  2. +
  3. To use the methods and properties of the barcode detection and generation classes and to handle camera preview, include the Tizen.Multimedia namespace in your application: +
    +using Tizen.Multimedia;
    +
    +
  4. +
+ + +

Preparing the Barcode Engines

+ +

To initialize the barcode detection and generation engines for use:

+ +
    +
  • For barcode detection: +
      +
    1. Create an instance of the Tizen.Multimedia.BarcodeDetectionConfiguration class and set the Target property as a value of the Tizen.Multimedia.BarcodeDetectionTarget enumeration: +
      +static BarcodeDetectionConfiguration configDetection = new BarcodeDetectionConfiguration();
      +
      +/// To detect all barcode types
      +configDetection.Target = BarcodeDetectionTarget.All;
      +
      +/// To detect only 1D barcodes
      +/// configDetection.Target = BarcodeDetectionTarget.Barcode1D;
      +/// To detect only 2D barcodes (QR codes)
      +/// configDetection.Target = BarcodeDetectionTarget.Barcode2D;
      +
      +
    2. +
    3. Create an instance of the Tizen.Multimedia.MediaVisionSource class with raw image buffer data and its corresponding width, height, and color space: +
      +/// Assume that there is a decoded raw data buffer of the byte[] type, and
      +/// it has 640x480 resolution with an RGB888 color space
      +MediaVisionSource source = new MediaVisionSource(bytes, width, height, ColorSpace.Rgb888);
      +
      +

      The source stores the barcode to be detected and all related data.

      +
    4. +
    5. To provide camera preview images, define a camera preview event handler for the Preview event of the Tizen.Multimedia.Camera class and create an instance of that class: +
      +/// Define a camera preview event handler
      +static void PreviewCallback(object sender, PreviewEventArgs e)
      +{
      +    PreviewData preview = e.Preview;
      +
      +    SinglePlane singlePlane = (SinglePlane)preview.Plane;
      +    if (preview.Format == CameraPixelFormat.Rgb888)
      +    {
      +        MediaVisionSource source = new MediaVisionSource(singlePlane.Data, preview.width, preview.height, ColorSpace.Rgb888);
      +    }
      +}
      +
      +/// Create the Tizen.Multimedia.Camera instance
      +static Camera camera = null;
      +try
      +{
      +    camera = new Camera(CameraDevice.Rear);
      +}
      +catch (NotSupportedException)
      +{
      +    Log.Info("Barcode Sample", "NotSupported");
      +}
      +
      +
    6. +
    7. Set the camera display, register the camera preview event handler, and start the camera preview with the StartPreview() method: +
      +/// Set the camera display
      +camera.Display = new Display(new Window("Preview"));
      +
      +/// Register the camera preview event handler
      +camera.Preview += PreviewCallback;
      +
      +IList previewFormats = camera.Feature.SupportedPreviewPixelFormats.ToList();
      +foreach (CameraPixelFormat previewFormat in previewFormats)
      +{
      +    camera.Setting.PreviewPixelFormat = previewFormat;
      +    break;
      +}
      +
      +/// Start the camera preview
      +camera.StartPreview();
      +
      +
    8. +
    +
  • +
  • For barcode generation, create an instance of the Tizen.Multimedia.BarcodeGenerationConfiguration class and set its properties: +
    +static BarcodeGenerationConfiguration configGeneration = new BarcodeGenerationConfiguration();
    +
    +/// To show message on the generated barcode image
    +configGeneration.TextVisibility = Visibility.Visible;
    +
    +/// To hide message on the generated barcode image
    +/// configGeneration.TextVisibility = Visibility.Invisible;
    +
    +/// To change the foreground or background color
    +/// For this example, the foreground and background are set as black and white, respectively
    +configGeneration.ForegroundColor = Color.Black;
    +configGeneration.BackgroundColor = Color.White;
    +
    +
  • +
+ +

Detecting Barcodes

+ +

To detect barcodes:

+ +
    +
  1. To access the camera preview data from which to detect barcodes, create a new instance of the Tizen.Multimedia.MediaVisionSource class in the camera preview event handler: +
    +static void PreviewCallback(object sender, PreviewEventArgs e)
    +{
    +    PreviewData preview = e.Preview;
    +
    +    SinglePlane singlePlane = (SinglePlane)preview.Plane;
    +    if (preview.Format == CameraPixelFormat.Rgb888)
    +    {
    +        MediaVisionSource source = new MediaVisionSource(singlePlane.Data, preview.width, preview.height, ColorSpace.Rgb888);
    +    }
    +
    +
  2. +
  3. Detect barcodes in the image using the DetectAsync() method of the Tizen.Multimedia.BarcodeDetector class: +
    +    Point point = new Point(0,0);
    +    Size size = new Size((int)source.Width, (int)source.Height);
    +
    +    Rectangle roi = new Rectangle(point, size);
    +
    +    var barcodeLists = await BarcodeDetector.DetectAsync(source, roi, configDetection);
    +
    +    foreach (Barcode barcode in barcodeLists)
    +    {
    +        Log.Info("Barcode sample", $"Barcode type is {barcode.Type}");
    +        Log.Info("Barcode sample", $"Barcode message is {barcode.Message}");
    +    }
    +}
    +
    +

    The ROI (region of interest) feature allows you to define a rectangular region of the image in which to detect barcodes. In the above example, the whole image is set as the ROI.

    +
  4. +
  5. When barcode detection is no longer needed, deregister the camera preview event handler, stop the camera preview, and destroy the camera instance: +
    +camera.Preview -= PreviewCallback;
    +
    +camera.StopPreview();
    +camera.Dispose();
    +
    +

    For more information, see the Tizen.Multimedia.Camera class.

    +
  6. +
+ +

Generating Barcodes

+ +

To generate a barcode:

+ +
    +
  • To generate the barcode into memory: +
      +
    • To generate a 1D barcode, create a source instance using the GenerateSource() method of the Tizen.Multimedia.BarcodeGenerator class with a message and a barcode type: +
      +string message = "0123455";
      +
      +/// For a Code 128 type barcode
      +var source = BarcodeGenerator.GenerateSource(message, BarcodeType.Code128);
      +
      +/// If you want to change the barcode color or change the visibility of the text, give an instance
      +/// of the Tizen.Multimedia.BarcodeGenerationConfiguration class as an additional parameter:
      +/// var source = BarcodeGenerator.GenerateSource(message, BarcodeType.code128, configGeneration);
      +
      +
    • +
    • To generate a QR code: +
        +
      1. To create the QR code configuration, create an instance of the Tizen.Multimedia.QrConfiguration class with the QR code encoding mode as a value of the Tizen.Multimedia.QrMode enumeration, the QR code error correction level as a value of the Tizen.Multimedia.ErrorCorrectionLevel enumeration, and the QR code version: +
        +string message = "Tizen QR";
        +
        +/// For the UTF8 encoding type
        +QrConfiguration qrConfig = new QrConfiguration(QrMode.Utf8, ErrorCorrectionLevel.Medium, 30);
        +
        +
      2. +
      3. Create a source instance using the GenerateSource() method of the Tizen.Multimedia.BarcodeGenerator class with a message and the QR code configuration: +
        +var source = BarcodeGenerator.GenerateSource(message, qrConfig);
        +
        +/// If you want to change the QR code color, give an instance
        +/// of the Tizen.Multimedia.BarcodeGenerationConfiguration class as an additional parameter:
        +/// var source = BarcodeGenerator.GenerateSource(message, qrConfig, configGeneration);
        +
        +
      4. +
      +
    • +
    +
  • +
  • To generate the barcode into a file: +
      +
    • To generate a 1D barcode: +
        +
      1. Create an instance of the Tizen.Multimedia.BarcodeImageConfiguration class with the file format as a value of the Tizen.Multimedia.BarcodeImageFormat enumeration, the image file resolution, and a path where the file is to be saved: +
        +int width = 300;
        +int height = 100;
        +BarcodeImageFormat format = BarcodeImageFormat.Jpeg;
        +string path = "/tmp/tizen_barcode.jpg";
        +BarcodeImageConfiguration imageConfig = new BarcodeImageConfiguration(width, height, path, format);
        +
        +
      2. +
      3. Generate the barcode using the GenerateImage() method of the Tizen.Multimedia.BarcodeGenerator class: +
        +string message = "0123455";
        +BarcodeType type = BarcodeType.Code128;
        +BarcodeGenerator.GenerateImage(message, type, imageConfig);
        +
        +
      4. +
      +
    • +
    • To generate a QR code, create instances of the Tizen.Multimedia.BarcodeImageConfiguration and Tizen.Multimedia.QrConfiguration classes as above, and generate the QR code using the GenerateImage() method of the Tizen.Multimedia.BarcodeGenerator class: +
      +int width = 300;
      +int height = 300;
      +BarcodeImageFormat format = BarcodeImageFormat.Jpeg;
      +string path = "/tmp/tizen_qr.jpg";
      +BarcodeImageConfiguration imageConfig = new BarcodeImageConfiguration(width, height, path, format);
      +Qrconfiguration qrConfig = new QrConfiguration(QrMode.Utf8, ErrorCorrectionLevel.Medium, 30);
      +
      +string message = "Tizen QR"
      +BarcodeGenerator.GenerateImage(message, qrConfig, imageConfig);
      +
      +
    • +
    +
  • +
+ +

Barcode Specifications

+ +

The following tables provide more information on the barcode generation specifications.

+

Table: Supported barcode types

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1D or 2DTypeDescriptionExample
1-DUPC-AUniversal product code with numeric 12-digit

UPC-A

UPC-EUniversal product code with numeric 6-digit

UPC-E

EAN-8International article number with numeric 8-digit

EAN-8

EAN-13International article number with numeric 13-digit

EAN-13

CODE-128Code 128; supports alphanumeric or numeric-only

CODE-128

CODE-39Code 39; supports 34 characters consisting of uppercase letters (A to Z), numeric digits (0 to 9), and special characters (-, ., $, /, %, space)

CODE-39

INTERLEAVED 2 of 5Interleaved 2 of 5 with numeric digits

UPC-A

2-DQR codeQuick Response code

UPC-A

+ +

Table: Supported QR code specifications

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
SpecificationSupport typeDescription
Error Correction Code (ECC) LevelECC LowRecovery up to 7% damage
ECC MediumRecovery up to 15% damage
ECC QuartileRecovery up 25% damage
ECC HighRecovery up to 30% damage
Encoding modeNumericNumeric digits ('0', '1', ..., '9')
AlphanumericAlphanumeric characters: numeric (0, 1, ..., 9), characters (A, B, ..., Z), and punctuation (' ', $, %, *, +, -, '.', /, ':')
Byte 8-bitRaw 8-bit bytes
UTF-8Universal character set and Transformation Format 8-bit, encoding characters
+ + + +
+ +Go to top + + + + + + + diff --git a/org.tizen.guides/html/dotnet/media/vision/image_recognition_cs.htm b/org.tizen.guides/html/dotnet/media/vision/image_recognition_cs.htm new file mode 100644 index 0000000..801a5c9 --- /dev/null +++ b/org.tizen.guides/html/dotnet/media/vision/image_recognition_cs.htm @@ -0,0 +1,283 @@ + + + + + + + + + + + + + Image Recognition and Tracking + + + +
+
+

Dependencies

+
    +
  • Tizen 4.0 and Higher
  • +
+

Content

+ +

Related Info

+ +
+
+ +
+ +

Image Recognition and Tracking

+ +

You can extract features of an image object and recognize it from specific images. You can also track the image object in your application.

+ +

The main image recognition and tracking features include:

+ +
    +
  • Recognizing images +

    You can recognize image objects in specific images, and extract image object features.

    +
  • +
  • Tracking images +

    You can track image objects using the camera preview images and a specific image tracking model.

    +
  • +
+ +

Prerequisites

+ +

To enable your application to use the image recognition and tracking functionality:

+
    +
  1. Install the Nuget packages for Media Vision and Camera.
  2. +
  3. To use the methods and properties of the image recognition and tracking classes and to handle camera preview, include the Tizen.Multimedia namespace in your application: +
    +using Tizen.Multimedia;
    +
    +
  4. +
  5. Define the configuration settings: +
      +
    • For configuring image object and feature extraction, create an instance of the Tizen.Multimedia.ImageFillConfiguration class and set its attributes accordingly: +
      +static ImageFillConfiguration configFill = new ImageFillConfiguration();
      +
      +/// Set the scale factor of the image being recognized
      +configFill.ObjectScaleFactor = 1.2;
      +
      +/// Set the maximum amount of image key points to be detected
      +configFill.ObjectMaxKeyPoints = 1000;
      +
      +
    • +
    • For image recognition, create an instance of the Tizen.Multimedia.ImageRecognitionConfiguration class and set its attributes accordingly: +
      +static ImageRecognitionConfiguration configRecog = new ImageRecognitionConfiguration();
      +
      +/// Set the scene scale factor
      +configRecog.SceneScaleFactor = 1.2;
      +
      +/// Set the maximum amount of key points to be detected in a scene
      +configRecog.SceneMaxKeyPoints = 3000;
      +
      +
    • +
    • For image tracking, create an instance of the Tizen.Multimedia.ImageTrackingConfiguration class and set its attributes accordingly: +
      +static ImageTrackingConfiguration configTrack = new ImageTrackingConfiguration();
      +
      +/// Set the history amount
      +configTrack.HistroyAmount = 5;
      +
      +/// Set the expected offset
      +configTrack.ExpectedOffset = 0.5;
      +
      +
    • +
    +
  6. +
+ +

Recognizing Images

+ +

To recognize an image (the target) in another (the scene):

+ +
    +
  1. To prepare the target image being recognized, create an instance of the Tizen.Multimedia.MediaVisionSource class with raw image buffer data and its corresponding width, height, and color space parameters: +
    +/// Assume that there is a decoded raw data buffer of the byte[] type, and
    +/// it has 640x480 resolution with an RGB888 color space
    +
    +MediaVisionSource sourceTarget = new MediaVisionSource(bytes, width, height, ColorSpace.Rgb888);
    +
    +
  2. +
  3. Create an instance of the Tizen.Multimedia.ImageObject class and use its Fill() method to fill it with the Tizen.Multimedia.MediaVisionSource instance: +
    +static ImageObject obj = new ImageObject();
    +
    +obj.Fill(sourceTarget);
    +
    +/// If you want to apply configuration options to the fill operation:
    +/// obj.Fill(sourceTarget, configFill);
    +
    +/// If you want a specific label for the ImageObject instance, set it manually
    +/// Otherwise the label automatically increments with each fill operation
    +obj.setLabel(1);
    +
    +
  4. +
  5. To prepare the scene where the target image is to be recognized, create a Tizen.Multimedia.MediaVisionSource instance which stores the scene: +
    +/// Assume that there is a decoded raw data buffer of the byte[] type, and
    +/// it has 640x480 resolution with an RGB888 color space
    +
    +MediaVisionSource sourceScene  = new MediaVisionSource(bytes, width, height, ColorSpace.Rgb888);
    +
    +
  6. +
  7. To recognize the target inside the scene, use the RecognizeAsync() method of the Tizen.Multimedia.ImageRecognizer class: +
    +/// You can recognize multiple targets
    +ImageObject[] targets = new ImageObject[1] (obj);
    +
    +var results = await ImageRecognizer.RecognizeAsync(sourceScene, targets);
    +
    +foreach (ImageRecognitionResult imageResult in results)
    +{
    +    if (imageResult.Success)
    +        Log.info(LogUtils.TAG, imageResult, Region.ToString();
    +    else
    +        Log.info(LogUtils.Tag, "ImageRecognition: + imageResult.Success.ToString()");
    +}
    +
    +
  8. +
+ +

Tracking Images

+ +

To track images:

+ +
    +
  1. To prepare the camera and create an image tracking model: +
      +
    1. Define a camera preview event handler for the Preview event of the Tizen.Multimedia.Camera class and create an instance of that class: +
      +/// Define a camera preview event handler
      +static void PreviewCallback(object sender, PreviewEventArgs e)
      +{
      +    PreviewData preview = e.Preview;
      +
      +    SinglePlane singlePlane = (SinglePlane)preview.Plane;
      +    if (preview.Format == CameraPixelFormat.Rgb888)
      +    {
      +        MediaVisionSource source = new MediaVisionSource(singlePlane.Data, preview.width, preview.height, ColorSpace.Rgb888);
      +    }
      +}
      +
      +/// Create the Tizen.Multimedia.Camera instance
      +static Camera camera = null;
      +try
      +{
      +    camera = new Camera(CameraDevice.Rear);
      +}
      +catch (NotSupportedException)
      +{
      +    Log.Info("Image Tracking Sample", "NotSupported");
      +}
      +
      +
    2. +
    3. Set the camera display, register the camera preview event handler, and start the camera preview with the StartPreview() method: +
      +/// Set the camera display
      +camera.Display = new Display(new Window("Preview"));
      +
      +/// Register the camera preview event handler
      +camera.Preview += PreviewCallback;
      +
      +IList previewFormats = camera.Feature.SupportedPreviewPixelFormats.ToList();
      +foreach (CameraPixelFormat previewFormat in previewFormats)
      +{
      +    camera.Setting.PreviewPixelFormat = previewFormat;
      +    break;
      +}
      +
      +/// Start the camera preview
      +camera.StartPreview();
      +
      +
    4. +
    5. Create the image tracking model as an instance of the Tizen.Multimedia.ImageTrackingModel class: +
      +static ImageTrackingModel model = new ImageTrackingModel();
      +
      +
    6. +
    +
  2. +
  3. Create a target image as an instance of the Tizen.Multimedia.MediaVisionSource class. +

    Create an instance of the Tizen.Multimedia.ImageObject class and use its Fill() method to fill it with the target image.

    +
    +static MediaVisionSource sourceTarget = new MediaVisionSource(bytes, width, height, ColorSpace.Rgb888);
    +
    +static ImageObject obj = new ImageObject();
    +obj.Fill(sourceTarget);
    +
    +
  4. +
  5. Set the target of the image tracking model with the SetTarget() method of the Tizen.Multimedia.ImageTrackingModel class, which takes the Tizen.Multimedia.ImageObject instance as its parameter: +
    +model.SetTarget(obj)
    +
    +
  6. + +
  7. To track the target, use the TrackAsync() method of the Tizen.Multimedia.ImageTracker class: +
    +/// Assume that "frames" contains a sequence of decoded images as
    +/// Tizen.Multimedia.MediaVisionSource instances
    +
    +foreach (MediaVisionSource frame in frames)
    +{
    +    var result = await ImageTracker.TrackAsync(frame, model);
    +
    +    /// If you want to apply configuration options to the tracking operation:
    +    /// var result = await ImageTracker.TrackAsync(frame, model, configTrack);
    +
    +    if (result == null)
    +    {
    +        continue;
    +    }
    +}
    +
    +
  8. + +
  9. +

    When image tracking is no longer needed, deregister the camera preview event handler, stop the camera preview, and destroy the camera instance:

    +
    +camera.Preview -= PreviewCallback;
    +
    +camera.StopPreview();
    +camera.Dispose();
    +
    +
  10. +
+ + + +
+ +Go to top + + + + + + + diff --git a/org.tizen.guides/html/dotnet/media/vision/media_vision_cs.htm b/org.tizen.guides/html/dotnet/media/vision/media_vision_cs.htm new file mode 100644 index 0000000..7ddb8ba --- /dev/null +++ b/org.tizen.guides/html/dotnet/media/vision/media_vision_cs.htm @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + Visual Detection and Recognition + + + + +
+
+

Dependencies

+
    +
  • Tizen 4.0 and Higher
  • +
+
+
+ +
+

Visual Detection and Recognition

+ +

You can perform various visual detection and recognition tasks in your application. You can detect or generate barcodes. In addition, you can track how faces or image objects move as well as detect and recognize faces or objects.

+ +

You can use the following visual detection and recognition features in your .NET applications:

+ +
    +
  • Barcode Detection and Generation + +

    You can handle images containing barcodes. You can encrypt a message by generating a barcode from it, and you can also detect barcodes in an image or from a camera preview stream.

  • + +
  • Face Detection, Recognition, and Tracking + +

    You can detect a face from an image, and recognize a face with a set of examples. You can also track a face within the camera preview stream.

  • + +
  • Image Recognition and Tracking + +

    You can extract features of an image object and recognize it from specific images. You can also track the image object within the camera preview stream.

  • +
+ + + +
+ +Go to top + + + + + + + + -- 2.7.4