Search Unity

PhotoCapture not called while running in Hololens

Discussion in 'VR' started by Aimi-no, Jul 23, 2018.

  1. Aimi-no

    Aimi-no

    Joined:
    Nov 9, 2017
    Posts:
    2
    Hi,
    I am trying to make an app that would capture photos in Hololens. I have followed the tutorial and almost copied the tutorial code. When I run it on my computer in Unity it works and takes a photo with my webcam. But when I run it on Hololens it doesn't work.
    My problematic part of code is here:

    void Start() {

    startHeadPosition = Camera.main.transform.position;
    newHeadPosition = startHeadPosition;
    dIndikator.text = "";

    CreateScene("Test");


    Debug.Log("\n Taking picture \n");
    PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);
    Debug.Log("\n Debug 2 \n");
    }

    void OnPhotoCaptureCreated(PhotoCapture captureObject)
    {
    Debug.Log("\n Debug 1 \n");
    photoCaptureObject = captureObject;

    m_cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).Last();

    CameraParameters c = new CameraParameters();
    c.hologramOpacity = 0.0f;
    c.cameraResolutionWidth = m_cameraResolution.width;
    c.cameraResolutionHeight = m_cameraResolution.height;
    c.pixelFormat = CapturePixelFormat.JPEG;

    Debug.Log("\n PhotoModeStarted \n");

    captureObject.StartPhotoModeAsync(c, OnPhotoModeStarted);
    }
    In Unity the log looks like this:
    Taking picture
    Debug 2
    Debug 1
    PhotoModeStarted

    But when in Hololens I get only:
    Taking picture
    Debug 2

    So it looks like it doesn't even enter the OnPhotoCaptureCreated. I have set capabilities to the camera and microphone and made sure I have them in the manifest file so I don't have any idea what would have caused this problem.
    Any ideas are greatly appreciated.
     
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
  3. Aimi-no

    Aimi-no

    Joined:
    Nov 9, 2017
    Posts:
    2
    I tried to change it to the code you've sent but I still have the same problem.

    Code (CSharp):
    1.  
    2. Debug.Log("\nCreating a PhotoCapture object\n");
    3.         PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject) {
    4.  
    5.             photoCaptureObject = captureObject;
    6.  
    7.             Debug.Log("\nSetting camera info\n");
    8.             m_cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).Last();
    9.  
    10.             CameraParameters cameraParameters = new CameraParameters();
    11.             cameraParameters.hologramOpacity = 0.0f;
    12.             cameraParameters.cameraResolutionWidth = m_cameraResolution.width;
    13.             cameraParameters.cameraResolutionHeight = m_cameraResolution.height;
    14.             cameraParameters.pixelFormat = CapturePixelFormat.JPEG;
    15.  
    16.             // Activate the camera
    17.             photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate (PhotoCapture.PhotoCaptureResult result) {
    18.                 // Take a picture
    19.                 Debug.Log("\nTaking the picture\n");
    20.                 photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
    21.             });
    22.         });
    The only debug log I get is "Creating a PhotoCapture object" when running in Hololens and in Unity on my laptop it all runs perfectly fine.
     
  4. MAlshair

    MAlshair

    Joined:
    Mar 18, 2018
    Posts:
    2
    Hello Everyone:

    This is maybe late for you, but I also have the same issue. If you are using one of the Unity versions that listed in the public tracker in the link below, then we have the same issue. So, I created a workaround for me and those that need to use the camera in the HoloLens by using MediaCapture. The workaround allows to take, save, and display photons in the HoloLens and it satisfies my needs. So, I am sharing this here to maybe help someone else that can't wait like me (I discovered this issue last Friday and it seems that it is going on for a long time):
    https://github.com/MSAlshair/HoloLensMediaCapture

    I also posted the comment in the public tracker, https://issuetracker.unity3d.com/issues/windowsmr-failure-to-take-photo-capture-in-hololens
    Thank you!