I am trying to run a hand pose estimator unitypackage from NatML. The original code was taking Texture 2D Image as input and results displayed were correct. However, I wanted to detect the hand in real time and display the results in real time too. In unity, there is no direct conversion from webcamtexture to texture2D so I extracted pixels from webcam and gave it as input to my model to run. I got no errors in unity with this following code but when I press play, it says NullReferenceException I have also attached image of my unity editor. Can anyone please guide me what possibly could be the error? namespace NatSuite.Examples {
using UnityEngine;
using NatSuite.ML;
using NatSuite.ML.Features;
using NatSuite.ML.Vision;
using NatSuite.ML.Visualizers;
using Stopwatch = System.Diagnostics.Stopwatch;
using System.Collections;
using System.Collections.Generic;
public sealed class HandPoseSample : MonoBehaviour {
[Header(@"NatML Hub")]
public string accessKey;
[Header(@"Prediction")]
public WebCamTexture webcam;
Color32[] data;
public Texture2D output;
public HandPoseVisualizer visualizer;
//public HandPosePredictor predictor;
public MLModelData modelData;
async void Start() {
webcam = new WebCamTexture();
webcam.Play();
output = new Texture2D(webcam.width, webcam.height);
data = new Color32[webcam.width * webcam.height];
// Fetch the model data from Hub
Debug.Log("Fetching model data from Hub");
modelData = await MLModelData.FromHub("@natsuite/hand-pose", accessKey);
// Deserialize the model
var model = modelData.Deserialize();
// Create the hand pose predictor
var predictor = new HandPosePredictor(model);
// Create input feature
var input = new MLImageFeature(output);
// Predict
var watch = Stopwatch.StartNew();
var hand = predictor.Predict(input);
watch.Stop();
// Visualize
Debug.Log($"Detected {hand.handedness} hand with score {hand.score:0.##} after {watch.Elapsed.TotalMilliseconds}ms");
visualizer.Render(hand);
// Dispose the model
model.Dispose();
}
void Update () {
if (data != null) {
webcam.GetPixels32(data);
output.SetPixels32(data);
output.Apply();
}
}
}
}