I have couple of questions regarding how TryGetLatestImage works…
- I have “TakeSnapshot” method connected with button (onclick). When i click the button first time it doesn’t go inside “arCameraManager.TryGetLatestImage(out cameraImage)”. Second time it works.
private void TakeSnapshot() {
XRCameraImage cameraImage;
if (arCameraManager.TryGetLatestImage(out cameraImage)) {
StartCoroutine(ProcessImage(cameraImage));
cameraImage.Dispose();
}
}
IEnumerator ProcessImage(XRCameraImage image) {
var request = image.ConvertAsync(new XRCameraImageConversionParams {
inputRect = new RectInt(0, 0, image.width, image.height),
outputDimensions = new Vector2Int(image.width, image.height),
outputFormat = TextureFormat.RGB24,
transformation = CameraImageTransformation.MirrorY
});
while (!request.status.IsDone())
yield return null;
if (request.status != AsyncCameraImageConversionStatus.Ready) {
Debug.LogErrorFormat("Request failed with status {0}", request.status);
request.Dispose();
yield break;
}
var rawData = request.GetData<byte>();
Texture2D imageTexture = new Texture2D(
request.conversionParams.outputDimensions.x,
request.conversionParams.outputDimensions.y,
request.conversionParams.outputFormat,
false);
imageTexture.LoadRawTextureData(rawData);
imageTexture.Apply();
request.Dispose();
snapshotImage.texture = imageTexture;
}
-
Texture is 640x480 and rotated (landscape instead of portrait). How can i set resolution to native and rotate it?
-
If i use “arCameraManager.frameReceived” resolution is correct, but this is not useful, cause frame is received every frame (i think).
private void OnEnable() {
arCameraManager.frameReceived += OnFrameReceived;
}
private void OnFrameReceived(ARCameraFrameEventArgs obj) {
var tex = obj.textures[0];
}
Help please … Thank you