Hey all,
My app uses the image capture abilities pretty frequently. I only take still images, not using video or anything.
When capturing an image I experience severe framerate drop (from 60 fps to about 10).
My image capture logic is mostly built around the example scene. I think I may not get it all the way through tough.
this is the method that captures the image
public override void StartCapture()
{
if (CanCapture())
{
_isCapturing = true;
_imageCapturedThisPress = false;
// Initialize CaptureConfig
Debug.Log("Stream capabilities initialized");
MLCamera.StreamCapability selectedCapability = _targetStreamCapability;
MLCamera.CaptureConfig captureConfig = new MLCamera.CaptureConfig
{
CaptureFrameRate = frameRate,
StreamConfigs = new MLCamera.CaptureStreamConfig[1] { MLCamera.CaptureStreamConfig.Create(selectedCapability, OutputFormat.JPEG) }
};
// Prepare for capture
Debug.Log("Prepare Capture");
MLResult result = _captureCamera.PrepareCapture(captureConfig, out MLCamera.Metadata _);
if (MLResult.DidNativeCallSucceed(result.Result, nameof(_captureCamera.PrepareCapture)))
{
// Trigger auto-exposure and auto-white-balance convergence
Debug.Log("Trigger auto-exposure and auto-white-balance convergence");
_captureCamera.PreCaptureAEAWB();
}
else
{
Debug.Log("pre capture failed");
// Failed to prepare the camera
return;
}
// Capture the image
Debug.Log("Capture");
_captureCamera.CaptureImage();
onCaptureStarted?.Invoke();
if (!result.IsOk)
{
Debug.Log(" Image capture failed " + result);
return;
}
}
and this is method caled when image was captured
private void OnCaptureRawImageComplete(MLCamera.CameraOutput output, MLCamera.ResultExtras resultExtras,
MLCamera.Metadata metadataHandle)
{
if (output.Format != MLCamera.OutputFormat.YUV_420_888)
{
try
{
_latestCaptureData = ImageConvertor.ConvertBytesToJpegTexture(output.Planes[0].Data, output.ToString());
_imageCapturedThisPress = true;
if (streamToDisplay) imageDisplay.DisplayCapture(_latestCaptureData);
}
catch (Exception e)
{
Debug.LogError(e.Message);
}
finally
{
_isCapturing = false;
}
}
}
Unity Editor version: 2022.3.16f1
ML2 OS version:1.4.0-dev2
Unity SDK version: 1.12
Host OS: Windows