unity 开启外部摄像头
2024-09-01 10:46:51
在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);
}
最新文章
- 如何在mac上用终端打开XAMPP自带的MySQL
- 主成分分析(PCA)的一种直观理解
- jqueryui / accordion的用法记录
- java 大数计算
- 全面了解 Linux 服务器 - 4. 查看 Linux 系统的平均负载
- 【洛谷P1080】国王游戏
- C# eval()函数浅谈
- eclipse中logcat偶尔不显示log的问题解决办法
- as3+java+mysql(mybatis) 数据自动工具(一)
- [原]RobotFrameWork(四)变量运算与Evaluate
- sql分页查询公式
- Python学习笔记 - 生成器generator
- Matcher.replaceFirst(String replacement)
- Mac环境下Scrapy的安装
- Web前端 HTML知识总结
- Python 进阶 异步async/await
- Cocos Creator 动态设置Canvas的宽度与高度,更改适配
- FFmpeg 将YUV数据转RGB
- visual studio code 在 mac 下按 F12无效
- 使用pygal_maps_world展示世界地图
热门文章
- centos7下mongoDB安装和配置
- 23种设计模式之适配器模式(Adapter Pattern)
- 手把手教你Pytest+Allure2.X定制报告详细教程,给自己的项目量身打造一套测试报告-02(非常详细,非常实用)
- WEB开发中常见的漏洞
- jedis 2.9版本部分属性变更
- 如何解决myeclipse2014突然无法打开的问题
- Python IAQ中文版 - Python中少有人回答的问题
- Kubernetes 系列(七):持久化存储StorageClass
- 不吹不黑,今天我们来聊一聊 Kubernetes 落地的三种方式
- [go设计模式]简单工厂模式