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?
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);
}
}