This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<MediaAsset> CreateGIF (Texture2D[] textures) { | |
// Make sure `textures` is not empty | |
// Make sure every texture has the same size (width and height) | |
// Make sure every texture has the `TextureFormat.RGBA32` format | |
// Create recorder | |
var width = textures[0].width; | |
var height = textures[0].height; | |
var frameRate = 5; | |
var recorder = await MediaRecorder.Create( | |
MediaFormat.GIF, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Detect (RenderTexture renderTexture) { | |
// Create the YOLOX model | |
var model = await MLEdgeModel.Create("@natsuite/yolox"); | |
// Create the YOLOX predictor | |
var predictor = new YOLOXPredictor(model); | |
// Readback the render texture | |
AsyncGPUReadback.Request(renderTexture, request => { | |
// Create an image feature | |
var feature = new MLImageFeature(request.GetData<byte>(), request.width, request.height); | |
// Predict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* NatDevice | |
* Copyright (c) 2022 NatML Inc. All Rights Reserved. | |
*/ | |
namespace NatSuite.Devices.Outputs { | |
using System; | |
using OpenCVForUnity.CoreModule; | |
using OpenCVForUnity.UtilsModule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a classification predictor | |
var labels = new [] { "cat", "dog", ... }; | |
var predictor = new MobileNetv2Predictor(model, labels); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a classifier module | |
var labels = new [] { "goldfish", "tiger shark", ... }; | |
var classifier = new MLClassifier("/path/to/classifier.onnx", labels); | |
// Classify an image | |
Texture2D image = ...; | |
var (label, confidence) = classifier.Predict(image); | |
Debug.Log($"Image contains {label} with confidence: {confidence}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you have some feature | |
Texture2D image = ...; | |
// You can predict easily | |
var (label, confidence) = predictor.Predict(image); | |
Debug.Log($"Image contains {label} with confidence {confidence}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the ML model data | |
var modelData = MLModelData.FromFile("/path/to/model.onnx"); | |
// Deserialize the model | |
var model = modelData.Deserialize(); | |
// Print a model metadata value | |
Debug.Log("The model was created by: " + model["Author"]); | |
// Check the expected input size | |
var inputType = model.inputs[0] as MLImageType; | |
Debug.Log($"Model expects image with size: {inputType.width}x{inputType.height}"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NatSuite.Recorders.Inputs; | |
/// <summary> | |
/// Recorder input for recording video frames from textures. | |
/// </summary> | |
public class ThreadedAsyncTextureInput : ITextureInput { | |
#region --Client API-- | |
/// <summary> | |
/// Create a texture input which performs asynchronous readbacks. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async void StartPreview () { | |
// Start the camera preview | |
ICameraDevice device = ...; | |
Texture2D previewTexture = await device.StartRunning(); | |
// Display the preview texture on a UI panel | |
rawImage.texture = previewTexture; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Camera device which provides pixel buffers. | |
/// </summary> | |
public interface ICameraDevice : IMediaDevice { | |
/// <summary> | |
/// Is the camera front facing? | |
/// </summary> | |
bool frontFacing { get; } |
NewerOlder