Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Microsoft HoloLens图像捕获无法工作_C#_Unity3d_Camera_Hololens_Image Capture - Fatal编程技术网

C# Microsoft HoloLens图像捕获无法工作

C# Microsoft HoloLens图像捕获无法工作,c#,unity3d,camera,hololens,image-capture,C#,Unity3d,Camera,Hololens,Image Capture,我正试图用全息镜头拍摄一张照片。我接受使用全息照相机的许可 我正在使用这个代码 using UnityEngine; using System.Collections; using System.Linq; using UnityEngine.XR.WSA.WebCam; using UnityEngine.UI; public class WebCamera : MonoBehaviour { PhotoCapture photoCaptureObject = null; T

我正试图用全息镜头拍摄一张照片。我接受使用全息照相机的许可

我正在使用这个代码

using UnityEngine;
using System.Collections;
using System.Linq;
using UnityEngine.XR.WSA.WebCam;
using UnityEngine.UI;

public class WebCamera : MonoBehaviour
{
    PhotoCapture photoCaptureObject = null;
    Texture2D targetTexture = null;


    // Use this for initialization
    void Start()
    {
        Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
        targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);

        // Create a PhotoCapture object
        PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject) {
            photoCaptureObject = captureObject;
            CameraParameters cameraParameters = new CameraParameters();
            cameraParameters.hologramOpacity = 0.0f;
            cameraParameters.cameraResolutionWidth = cameraResolution.width;
            cameraParameters.cameraResolutionHeight = cameraResolution.height;
            cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;

            // Activate the camera
            photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate (PhotoCapture.PhotoCaptureResult result) {
                // Take a picture
                photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
            });
        });
    }

    void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
    {
        // Copy the raw image data into the target texture

        photoCaptureFrame.UploadImageDataToTexture(targetTexture);

        // Create a GameObject to which the texture can be applied
        GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
        Renderer quadRenderer = quad.GetComponent<Renderer>() as Renderer;
        quadRenderer.material = new Material(Shader.Find("Custom/Unlit/UnlitTexture"));

        quad.transform.parent = this.transform;
        quad.transform.localPosition = new Vector3(0.0f, 0.0f, 3.0f);

        quadRenderer.material.SetTexture("_MainTex", targetTexture);

        // Deactivate the camera
        photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
    }

    void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)
    {
        // Shutdown the photo capture resource
        photoCaptureObject.Dispose();
        photoCaptureObject = null;
    }
}
使用UnityEngine;
使用系统集合;
使用System.Linq;
使用UnityEngine.XR.WSA.WebCam;
使用UnityEngine.UI;
公共类网络摄像机:单一行为
{
PhotoCapture photoCaptureObject=null;
Texture2D targetTexture=null;
//用于初始化
void Start()
{
分辨率cameraResolution=PhotoCapture.SupportedResolutions.OrderByDescending((res)=>res.width*res.height)。First();
targetTexture=新纹理2D(cameraResolution.width、cameraResolution.height);
//创建一个PhotoCapture对象
CreateAsync(false,委托(PhotoCaptureObject){
photoCaptureObject=captureObject;
CameraParameters CameraParameters=新的CameraParameters();
摄像机参数。全息容量=0.0f;
cameraParameters.cameraResolutionWidth=cameraResolution.width;
cameraParameters.cameraResolutionHeight=cameraResolution.height;
cameraParameters.pixelFormat=CapturePixelFormat.BGRA32;
//启动摄像机
photoCaptureObject.StartPhotoModeAsync(cameraParameters,委托(PhotoCapture.PhotoCaptureResult){
//拍照
TakePhotoAsync(OnCapturedPhotoToMemory);
});
});
}
void onCapturedPhototomory(PhotoCapture.PhotoCaptureResult结果,PhotoCaptureFrame PhotoCaptureFrame)
{
//将原始图像数据复制到目标纹理中
photoCaptureFrame.UploadImageDataToTexture(targetTexture);
//创建一个可以应用纹理的游戏对象
GameObject quad=GameObject.CreatePrimitive(PrimitiveType.quad);
Renderer quadRenderer=quad.GetComponent()作为渲染器;
quadrender.material=新材质(Shader.Find(“自定义/未照明/未照明结构”);
quad.transform.parent=this.transform;
quad.transform.localPosition=新矢量3(0.0f、0.0f、3.0f);
quadrender.material.SetTexture(“_MainTex”,targetTexture);
//关闭相机
photoCaptureObject.StopHotoModeAsync(OnStoppedPhotoMode);
}
无效OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult)
{
//关闭照片捕获资源
photoCaptureObject.Dispose();
photoCaptureObject=null;
}
}
此脚本附加到一个空的游戏对象

我得到以下错误

ArgumentNullException:  Value cannot be null
Parameter name: shader.UnityEngine.Material..ctor(UnityEngine.Shader shader) (at <00000000000000000000>:0)
ArgumentNullException:值不能为null
参数名称:shader.UnityEngine.Material..ctor(UnityEngine.shader着色器)(at:0)

请任何人帮我拍一张照片。我哪里出错了?

它正在查找位于此处的着色器,“自定义/未照明/未照明结构”。这可能是不可用的。
我建议注释掉这一行,以确定它周围的其他代码是否有效。

这一行代码是否引发了此错误:
quadrender.material=new material(Shader.Find(“自定义/未照明/未照明结构”)如果您对该代码行进行了注释,则无法使用相同的消息引发异常。您能确认最新的异常和错误消息吗?作为测试,请创建一个测试着色器并调用shader.Find()对其进行测试。