unity3d - 如何从Unity3d摄像头抓取帧并实时显示在另一个rawImage上?

标签 unity3d camera rawimage

the results

我想从Unity3d虚拟相机中抓取帧,然后让它们显示在另一个原始图像上。结果是原始图像屏幕非常闪烁。

using UnityEngine;
using UnityEngine.UI;

public class RawImageVirtualWebCamTexture : MonoBehaviour
{
    private RawImage rawimage;

    void Start()
    {
        GameObject obj = GameObject.Find("RawImageTransform");
        rawimage = obj.GetComponent<RawImage>();
    }

    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (source != null)
        {
            rawimage.texture = source;
        }
        Graphics.Blit(source, destination);
    }
}

我想看到流畅的画面。但是该怎么做呢?

最佳答案

如果它是关于 Unity Camera 的,则您无需捕获任何内容。

只需创建一个新的 RenderTexture

Assets -> 右键单击 -> Create -> RenderTexture

enter image description here

让您的 Camera 渲染到 RenderTexture 中,而不是通过简单地引用 Target Texture< 中创建的 RenderTexture 来渲染游戏 View (这使得此 Camera 不再渲染到游戏 View ,而是渲染到引用的 RenderTexture)

enter image description here

最后简单地使用创建的 RenderTexture 作为 RawImageTexture

enter image description here


如果您需要那个 Camera 同时渲染到正常的游戏 View ,只需在上述过程的子对象上使用另一个 Camera

enter image description here


结果

enter image description here

关于unity3d - 如何从Unity3d摄像头抓取帧并实时显示在另一个rawImage上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56783654/

相关文章:

c++ - 将帧速率提高到 30 fps 并从 AVT GigE 相机获取 bayerrg8

iphone - 捕获相机 View 并叠加在图像中

ios - 可用的 RawPhotoPixelFormatTypes 在 iPhone 7+ 和 iOS 11 上为空

c# - Unity - 如何让我的跳跃动画循环工作?

c# - 在主线程中获取 UdpClient 接收数据

unity3d - Unity iPhone 应用程序大小太大

javascript - 如何存储从 Phonegap/Android 应用程序拍摄的照片

android - 将 android camera2 图像保存为无损 PNG

image-processing - 如何使用 Python 显示数字高程模型 (DEM) (.raw)?

c# - Unity 3d List<> 在 android 中不起作用,但在 Unity Editor 中工作正常