PhotoCapture throwing IMediaCapture error

Hi! I'm pretty new to HoloLens. I'm trying to do a photo capture on the HoloLens and interact with the raw bytes. However, I get this error message when I run the program = Failed to initialize IMediaCapture (hr = 0xC00DABE0) when I try to create the asynchronous call in the beginning - PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);

Would really appreciate any help or tips! Thank you so much!


using UnityEngine;
using System.Collections;
using UnityEngine.VR.WSA.WebCam;
using System.Linq;
using System.Collections.Generic;

public class PhotoStream : MonoBehaviour {

private PhotoCapture photoCaptureObject = null;


// Use this for initialization
void Start () {
    Debug.Log("Webcam Mode is: " + WebCamMode.PhotoMode);
    PhotoCapture.CreateAsync(false, OnPhotoCaptureCreated);


}

// Update is called once per frame
void Update()
{

}

void OnPhotoCaptureCreated(PhotoCapture captureObject)
{
    Debug.Log("begin on photo capture created");
    // store object
    photoCaptureObject = captureObject;

    Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();

    // set parameters
    CameraParameters c = new CameraParameters();
    c.hologramOpacity = 0.0f;
    c.cameraResolutionWidth = cameraResolution.width;
    c.cameraResolutionHeight = cameraResolution.height;
    c.pixelFormat = CapturePixelFormat.BGRA32;

    // start photo mode
    captureObject.StartPhotoModeAsync(c, false, OnPhotoModeStarted);
}

// clean up 
void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)
{
    photoCaptureObject.Dispose();
    photoCaptureObject = null;
}

private void OnPhotoModeStarted(PhotoCapture.PhotoCaptureResult result)
{
    if (result.success)
    {
        // capture a frame to memory
        photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
    }
    else
    {
        Debug.LogError("Unable to start photo mode!");
    }
}

void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
{
    if (result.success)
    {
        List<byte> imageBufferList = new List<byte>();
        // Copy the raw IMFMediaBuffer data into our empty byte list.
        photoCaptureFrame.CopyRawImageDataIntoBuffer(imageBufferList);

        // In this example, we captured the image using the BGRA32 format.
        // So our stride will be 4 since we have a byte for each rgba channel.
        // The raw image data will also be flipped so we access our pixel data
        // in the reverse order.
        int stride = 4;
        float denominator = 1.0f / 255.0f;
        List<Color> colorArray = new List<Color>();
        for (int i = imageBufferList.Count - 1; i >= 0; i -= stride)
        {
            float a = (int)(imageBufferList[i - 0]) * denominator;
            float r = (int)(imageBufferList[i - 1]) * denominator;
            float g = (int)(imageBufferList[i - 2]) * denominator;
            float b = (int)(imageBufferList[i - 3]) * denominator;

            colorArray.Add(new Color(r, g, b, a));
            Debug.Log("color: (" + r + ", " + g + ", " + b + ", " + a + ")");
        }
        // Now we could do something with the array such as texture.SetPixels() or run image processing on the list
    }
    photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
}

}

Answers

  • Make sure you are specifying the webcam and microphone capabilities in your app manifest.

  • @Abecvar already specified webcam and microphone capabilities under player settings-->publishing settings-->capabilities. Is there a special way to declare that in the appmanifest file?

  • In vs. Double click the appmanifest file. Select the capabilities tab and check the webcam and microphone.

  • Hello i am having the same problem..despite having checked webcam and microphone i still get the error, though running it directly in unity seems to access the camera

  • edited July 2017

    I thought I had the same issue but mine is that it seems to hang on StartPhotoModeAsync..

  • I have also get the issue! How can I solve it?

  • I am getting Failed to initialize IMediaCapture when using Holographic Emulation -> Remote to Device with HoloLens. However, I can't find anything online that says this should not work. Can anyone else verify whether this works for them?

    I have the webcam and microphone capabilities enabled. And when building the app and deploying to HoloLens via Visual Studio, I can capture and display camera frames just fine.

    This is quite annoying though, since it is much faster to prototype with Holographic Remoting.

  • Me too , maybe Had to choose the way of UWP, give up unity

  • TroldenTrolden
    edited August 2018

    SOLUTION IDENTIFIED

    Ok, so I came across a soluton that worked for me. I had Research Mode turned "On" this whole time. I turned it "Off" and restarted the Hololens. Then the PhotoCapture code worked. I am guessing this is because Research Mode accesses the low level sensors of the Hololens and was intervening with the standard way of accessing the camera. I hope this helps someone in the same situation as me.


    Hi.

    I get the Failed to initialize IMediaCapture error too. Did anyone find a solution to this problem? I have checked the Microphone and Camera capabilities. I am running the newest version of the OS on the Hololens and using Unity 2017.4.6f1 for development.

    Last year around the same time I had no problem running the PhotoCapture code (see above code by holotinker) on the Hololens. Now, 2018, is a different story, which is quite frustrating.

    I can run my PhotoCapture code just fine in Unity using the Holographic Remoting Player, altrough the code accesses the webcam of the laptop, not the Hololens camera.
    But the UWP app, deployed on the Hololens, does not seem to access the Hololens camera and therefore fails to capture a photo and throws the Failed to initialize IMediaCapture error. Any help and thoughts appreciated :)

  • I must be missing something here.

    I checked and "Research Mode" is not on.

    I checked and under the "Player Settings" -> "Publish Setting" -> Capabilities. I have "WebCam" selected.

    I checked under Settings -> Privacy -> Camera. Turned on the share camera with applications and enabled to all applications.

    I have restarted the HoloLens multiple times.

    But When I connect the HoloLens to Unity under the "Holographic" tab and select "Remote to Device" open the "Holographic Remoting" on the HoloLens I get a connection. Pressing play will start my application on HoloLens, but my first message on the log is still
    "Failed to initialize IMediaCapture"

    I am never asked on the HoloLens to allow the usage of the camera when application, not sure if this is supposed to happen.

    Could someone point me in the right direction.

    When you do "Play" on Unity is it possible to access the camera on HoloLens device?

    God bless,
    Bruno

  • Hi,
    I have applied all the changes mentioned above but couldn't able to resolve the error.
    I am still getting an error of Failed to initialize IMediaCapture (hr = 0xC00DABE0) with holoLens photo capture script.
    You can refer details over here :
    https://answers.unity.com/questions/1596165/unitys-hololens-photo-capture-script-is-not-workin.html

    hope, someone can help on this.

  • Succeed to take and save pictures from my HoloLens using this source code.

Sign In or Register to comment.