Microsoft HoloLens Emulator - Callback for PhotoCapture.CreateAsync not being called
I want to add to this HoloLens app, under a NDA, the ability to take photos with the holograms. A more general example can be a photo of someone with a holographic model of the One World Trade Center sitting on the viewer's desk.
For some reason, after doing some debugging, I am noticing that the callback function I've passed in as the second argument of PhotoCapture.CreateAsync is not being called at all. Not even after 10 seconds once this function is called.
The package.appxmanifest file of this UWP app I'm deploying to the HoloLens after building it from Unity does have DeviceCapability tags to use both the webcam and the microphone on the HoloLens itself, including the one in the emulator.
Since this project is under a non-disclosure agreement, unfortunately I can't share a code snippet at all.
Why is the callback not being called at all? Also, as I'm new to this, what am I supposed to do?
Answer by KDamen · Mar 29, 2018 at 11:07 AM
Hello @GregPD65356T,
I have some experise with programming with the HoloLens. I ones tested the webcam of the HoloLens, using a script that set the photo as texture of an object.
But the emulator has no webcam, so this must be tested on the HoloLens.
using UnityEngine;
using System.Linq;
using UnityEngine.XR.WSA.WebCam;
public class WebcamToTexture : MonoBehaviour
{
PhotoCapture photoCaptureObject = null;
// Use this for initialization
void Start()
{
PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);
}
void OnPhotoCaptureCreated( PhotoCapture captureObject )
{
photoCaptureObject = captureObject;
Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res ) => res.width * res.height).First();
CameraParameters c = new CameraParameters();
c.hologramOpacity = 0.0f;
c.cameraResolutionWidth = cameraResolution.width;
c.cameraResolutionHeight = cameraResolution.height;
c.pixelFormat = CapturePixelFormat.BGRA32;
captureObject.StartPhotoModeAsync(c, OnPhotoModeStarted);
}
void OnStoppedPhotoMode( PhotoCapture.PhotoCaptureResult result )
{
photoCaptureObject.Dispose();
photoCaptureObject = null;
}
private void OnPhotoModeStarted( PhotoCapture.PhotoCaptureResult result )
{
if (result.success) {
photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
} else {
Debug.LogError("Unable to start photo mode!");
}
}
void OnCapturedPhotoToMemory( PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame )
{
if (result.success) {
// Create our Texture2D for use and set the correct resolution
Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res ) => res.width * res.height).First();
Texture2D targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
// Copy the raw image data into our target texture
photoCaptureFrame.UploadImageDataToTexture(targetTexture);
// Do as we wish with the texture such as apply it to a material, etc.
gameObject.GetComponent<Renderer>().material.mainTexture = targetTexture;
}
// Clean up
photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
}
}
Hope it helps you.
That's so weird having to learn that the virtual HoloLens in the emulator does not have a virtual webcam of its own. I don't quite understand why it's not included in the emulator to begin with, since it would be so useful for development-level testing.
$$anonymous$$aybe it's posible to test this particular feature inside Unity itself. Unity can use the webcam of the PC to make pictures.
Is this a possibility?
With my current project setup, when I click on the Play button, the editor crashes. What I got is a couple of scripts: one responsible for interaction sources, and one for gestures. The Unity editor itself does not have the plugins, I think, to handle it.
Your answer
Follow this Question
Related Questions
Setting manual focus on UWP device camera 0 Answers
how to run ARCore Instant Preview on Android emulator? 0 Answers
How do you take multiple photos using Webcamtexture and rotate it to show it as smartphone rotation? 0 Answers
Coroutine from Callback doesn't handle yield returns. 2 Answers
keyboard input (num pad) when unity does not have focus 0 Answers