Image 着色三维模型Vuforia Unity

Image 着色三维模型Vuforia Unity,image,unity3d,3d,textures,vuforia,Image,Unity3d,3d,Textures,Vuforia,我想实现一个功能,在这个功能中,3d模型将拾取特定区域的颜色。我正在使用vuforia和unity3d,并成功地实现了目标检测。在下一步中,我想选择图像的颜色,并将该颜色放在3d模型上 许多人已经实现了这一点,但我无法找到一个完整的教程 我已经厌倦了使用区域Cature,但没有成功 我会取你要找的屏幕区域,然后将其放入像素阵列中,并对该阵列求平均值 public Color GetColorFromScreen(int x, int y, int width, int height){

我想实现一个功能,在这个功能中,3d模型将拾取特定区域的颜色。我正在使用vuforia和unity3d,并成功地实现了目标检测。在下一步中,我想选择图像的颜色,并将该颜色放在3d模型上

许多人已经实现了这一点,但我无法找到一个完整的教程


我已经厌倦了使用区域Cature,但没有成功

我会取你要找的屏幕区域,然后将其放入像素阵列中,并对该阵列求平均值

public Color GetColorFromScreen(int x, int y, int width, int height){
    Texture2D tex = new Texture2D(1, 1);
    tex.ReadPixels(new Rect(x, y, width, height), 0, 0);
    tex.Apply();
    Color [] pix = tex.GetPixels(x, y, width, height);
    float r,g,b,a;
    foreach (Color col in pix){
        r += col.r;
        g += col.g;
        b += col.b;
        a += col.a;
    } 

    r /= pix.Length;
    g /= pix.Length;
    b /= pix.Length;
    a /= pix.Length;
    return new Color(r,g,b,a);
}
然后抓取模型的材质并应用该颜色

GetComponent<Renderer>().material.color = GetColorFromScreen(x,y,w,h);
GetComponent().material.color=GetColorFromScreen(x,y,w,h);

我将获取您所关注的屏幕区域,然后将其放置在像素阵列中,并对该阵列求平均值

public Color GetColorFromScreen(int x, int y, int width, int height){
    Texture2D tex = new Texture2D(1, 1);
    tex.ReadPixels(new Rect(x, y, width, height), 0, 0);
    tex.Apply();
    Color [] pix = tex.GetPixels(x, y, width, height);
    float r,g,b,a;
    foreach (Color col in pix){
        r += col.r;
        g += col.g;
        b += col.b;
        a += col.a;
    } 

    r /= pix.Length;
    g /= pix.Length;
    b /= pix.Length;
    a /= pix.Length;
    return new Color(r,g,b,a);
}
然后抓取模型的材质并应用该颜色

GetComponent<Renderer>().material.color = GetColorFromScreen(x,y,w,h);
GetComponent().material.color=GetColorFromScreen(x,y,w,h);