在unity中建立一个image作为摄像头显示画面,然后通过命令render到image上即可。

    public WebCamTexture webTex;
public string deviceName; void Start()
{
StartCoroutine(CallCamera())
}
void Update()
{ } ///
///调用摄像头
///
IEnumerator CallCamera()
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if(Application.HasUserAuthorization(UserAuthorization.WebCam))
{
WebCamDevice[] devices = WebCamTexture.devices;
deviceName = devices[].name;
//设置摄像机摄像的区域
webTex=new WebCamTexture(deviceName,,,);
GetComponent<MeshRenderer>().material.mainTexture = webTex;
webTex.Play();//开始摄像
}
}

抓取当前画面

    public void Capture()
{
//WebCamTexture wc = new WebCamTexture(160, 120);
//wc.play();
Texture2D t = new Texture2D(webTex.width, webTex.height);
t.SetPixels(webTex.GetPixels());
t.Apply();
byte[] byt = t.EncodeToPNG();
File.WriteAllBytes(@"D:/test.jpg", byt);
}

最新文章

  1. 如何在mac上用终端打开XAMPP自带的MySQL
  2. 主成分分析(PCA)的一种直观理解
  3. jqueryui / accordion的用法记录
  4. java 大数计算
  5. 全面了解 Linux 服务器 - 4. 查看 Linux 系统的平均负载
  6. 【洛谷P1080】国王游戏
  7. C# eval()函数浅谈
  8. eclipse中logcat偶尔不显示log的问题解决办法
  9. as3+java+mysql(mybatis) 数据自动工具(一)
  10. [原]RobotFrameWork(四)变量运算与Evaluate
  11. sql分页查询公式
  12. Python学习笔记 - 生成器generator
  13. Matcher.replaceFirst(String replacement)
  14. Mac环境下Scrapy的安装
  15. Web前端 HTML知识总结
  16. Python 进阶 异步async/await
  17. Cocos Creator 动态设置Canvas的宽度与高度,更改适配
  18. FFmpeg 将YUV数据转RGB
  19. visual studio code 在 mac 下按 F12无效
  20. 使用pygal_maps_world展示世界地图

热门文章

  1. centos7下mongoDB安装和配置
  2. 23种设计模式之适配器模式(Adapter Pattern)
  3. 手把手教你Pytest+Allure2.X定制报告详细教程,给自己的项目量身打造一套测试报告-02(非常详细,非常实用)
  4. WEB开发中常见的漏洞
  5. jedis 2.9版本部分属性变更
  6. 如何解决myeclipse2014突然无法打开的问题
  7. Python IAQ中文版 - Python中少有人回答的问题
  8. Kubernetes 系列(七):持久化存储StorageClass
  9. 不吹不黑,今天我们来聊一聊 Kubernetes 落地的三种方式
  10. [go设计模式]简单工厂模式