学什么可以做响应式网站,网页设计网站官网,wordpress上传sh文件,软装设计网站有哪些目录 一、前言
二、场景介绍
1.WebCamTextureToMatExample脚本
2.FpsMonitor脚本
三、 结构体Scaler
四、找到相机并使用
1.相机的启用
2.格式转换
a.把webCamTexture转换成Mat
b.把Mat转换成Texture2D
五、脚本组合
六、作者的碎碎念 一、前言
第二个案例#xf…目录 一、前言
二、场景介绍
1.WebCamTextureToMatExample脚本
2.FpsMonitor脚本
三、 结构体Scaler
四、找到相机并使用
1.相机的启用
2.格式转换
a.把webCamTexture转换成Mat
b.把Mat转换成Texture2D
五、脚本组合
六、作者的碎碎念 一、前言
第二个案例如图1所示讲的内容是使用相机和把相机的图片转换成Mat再去使用。 图1 案例2 二、场景介绍
这个案例如果你点击运行了就是把相机的内容显示在界面里同时你可以控制相机的切换是否启动。
整个场景中重要的脚本有两个。如图2所示 图2 两个重要的脚本 1.WebCamTextureToMatExample脚本 这个脚本主要是控制相机的启停输出图片把图片显示在界面上。
2.FpsMonitor脚本
这个脚本是帧率监视器把图片的长宽和输出图片的帧率显示在界面上。如图3所示
这些数字和方框都是在脚本里画的所以在界面里看不见这个游戏物体。 图3 面板 本篇文章不讲脚本2因为不是主要脚本只讲脚本1.
三、 结构体Scaler
图片计算一般是四个数据。比如Color是255,255,255,255。
但是我们每次设置就要new Color(255,255,255,255)再进行修改或者计算是比较麻烦的。
为了不那么麻烦OpenCV中设置了一个结构体Scaler专门用来存放四个数可以复制可以相乘等写了一些帮助计算的代码。本质就是存放四个数的结构体。
大家后面看见了不要太陌生。
四、找到相机并使用
我把WebCamTextureToMatExample脚本中最核心的部分拿了出来单独写了一个脚本。
1.相机的启用
//相机驱动
WebCamDevice webCamDevice;
//相机拍摄的图片
WebCamTexture webCamTexture;//你希望输出的分辨率宽
public int requestedWidth 1920;
//你希望输出的分辨率高
public int requestedHight 1080;
//相机按什么帧率输出图片
public int requestFPS 30;void Start()
{//初始化Initialize();
}//相机的初始化用携程比较好就再创建个携程调用
private void Initialize()
{ StartCoroutine(_Initialize());
}//携程
IEnumerator _Initialize()
{//获取所有可以传输图片的相机WebCamDevice[] webCamDevices WebCamTexture.devices;//如果这个数量是大于1的if (webCamDevices.Length 0){ //默认取第一个相机这里你也可以选别的不要紧webCamDevice webCamDevices[0];//初始化一下图片提供驱动名称图片的宽高输出图片的帧率webCamTexture new WebCamTexture(webCamDevice.name, requestedWidth,requestedHight,requestFPS);}//如果没初始化说明没找到相机if (webCamTexture null){Debug.Log(没有找到相机);//跳出方法yield break;}//如果找到了就开始接收图片webCamTexture.Play();//相机照到以后OnInited(); }这部分代码就可以把相机打开并且把图片拿到WebCamTexture中了。
2.格式转换 还是老规矩万物都要转换成OpenCV的通用格式Mat所以分两步 a.把webCamTexture转换成Mat b.把mat转换成Texture2D。 a.把webCamTexture转换成Mat
需要的参数有三个
public static void webCamTextureToMat(
WebCamTexture webCamTexture,
Mat mat,
Color32[] pixels32Buffer,
bool flipAfter true,
int flipCode 0)
webCamTexture有了
新建Mat
Mat rgbaMat;rgbaMat new Mat(
webCamTexture.height,
webCamTexture.width,
CvType.CV_8UC4,
new Scalar(0, 0, 0, 255)); //初始化一个黑色
新建Color32[]
它的大小必须装得下你想要的相机图片大小。
Color32[] colors;colors new Color32[webCamTexture.width * webCamTexture.height];webCamTexture转换成Mat
上一集说过转换的方法都放在Utils类里面所以转换方法为
Utils.webCamTextureToMat(webCamTexture, rgbaMat, colors);
b.把Mat转换成Texture2D
上节课的内容这里略过。
五、脚本组合
WebCamDevice webCamDevice;WebCamTexture webCamTexture;public int requestedWidth 1920;public int requestedHight 1080;public int requestFPS 30;Mat rgbaMat;Color32[] colors;Texture2D texture;void Start(){Initialize();}private void Initialize(){ StartCoroutine(_Initialize());}IEnumerator _Initialize(){WebCamDevice[] webCamDevices WebCamTexture.devices;if (webCamDevices.Length 0){ webCamDevice webCamDevices[0];webCamTexture new WebCamTexture(webCamDevice.name,requestedWidth,requestedHight,requestFPS);}if (webCamTexture null){Debug.Log(没有找到相机);yield break;}webCamTexture.Play();OnInited();}private void OnInited(){//初始化Colorscolors new Color32[webCamTexture.width * webCamTexture.height];//初始化texturetexture new Texture2D(webCamTexture.width, webCamTexture.height, TextureFormat.RGBA32, false);//初始化mat并赋值黑色rgbaMat new Mat(webCamTexture.height, webCamTexture.width, CvType.CV_8UC4, new Scalar(0, 0, 0, 255));//转换Utils.matToTexture2D(rgbaMat, texture, colors);//我是把脚本挂在RawImage上的所以可以直接赋值gameObject.GetComponentRawImage().texture texture;}void Update(){if (webCamTexture.isPlaying webCamTexture.didUpdateThisFrame){Utils.webCamTextureToMat(webCamTexture, rgbaMat, colors);Utils.matToTexture2D(rgbaMat, texture, colors);//我是把脚本挂在RawImage上的所以可以直接赋值gameObject.GetComponentRawImage().texture webCamTexture;}}
六、作者的碎碎念
发现数据还挺好所以....继续更了。 文章转载自: http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.yyngs.cn.gov.cn.yyngs.cn http://www.morning.gbjxj.cn.gov.cn.gbjxj.cn http://www.morning.lrzst.cn.gov.cn.lrzst.cn http://www.morning.mqgqf.cn.gov.cn.mqgqf.cn http://www.morning.gbfuy28.cn.gov.cn.gbfuy28.cn http://www.morning.zqfz.cn.gov.cn.zqfz.cn http://www.morning.mjats.com.gov.cn.mjats.com http://www.morning.pplxd.cn.gov.cn.pplxd.cn http://www.morning.zfhwm.cn.gov.cn.zfhwm.cn http://www.morning.glnmm.cn.gov.cn.glnmm.cn http://www.morning.mtktn.cn.gov.cn.mtktn.cn http://www.morning.lfmwt.cn.gov.cn.lfmwt.cn http://www.morning.wzwpz.cn.gov.cn.wzwpz.cn http://www.morning.xfrqf.cn.gov.cn.xfrqf.cn http://www.morning.lbhck.cn.gov.cn.lbhck.cn http://www.morning.sqfrg.cn.gov.cn.sqfrg.cn http://www.morning.nwfxp.cn.gov.cn.nwfxp.cn http://www.morning.qmwzr.cn.gov.cn.qmwzr.cn http://www.morning.swzpx.cn.gov.cn.swzpx.cn http://www.morning.jwfqq.cn.gov.cn.jwfqq.cn http://www.morning.msxhb.cn.gov.cn.msxhb.cn http://www.morning.pcjw.cn.gov.cn.pcjw.cn http://www.morning.jfzbk.cn.gov.cn.jfzbk.cn http://www.morning.xcbnc.cn.gov.cn.xcbnc.cn http://www.morning.ympcj.cn.gov.cn.ympcj.cn http://www.morning.muniubangcaishui.cn.gov.cn.muniubangcaishui.cn http://www.morning.gcqs.cn.gov.cn.gcqs.cn http://www.morning.qrhh.cn.gov.cn.qrhh.cn http://www.morning.hcqd.cn.gov.cn.hcqd.cn http://www.morning.jqzns.cn.gov.cn.jqzns.cn http://www.morning.yrnrr.cn.gov.cn.yrnrr.cn http://www.morning.sgfpn.cn.gov.cn.sgfpn.cn http://www.morning.psxxp.cn.gov.cn.psxxp.cn http://www.morning.xqjz.cn.gov.cn.xqjz.cn http://www.morning.qblcm.cn.gov.cn.qblcm.cn http://www.morning.zdsqb.cn.gov.cn.zdsqb.cn http://www.morning.rxpp.cn.gov.cn.rxpp.cn http://www.morning.nrbqf.cn.gov.cn.nrbqf.cn http://www.morning.dtlnz.cn.gov.cn.dtlnz.cn http://www.morning.yhyqg.cn.gov.cn.yhyqg.cn http://www.morning.rpljf.cn.gov.cn.rpljf.cn http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.gglhj.cn.gov.cn.gglhj.cn http://www.morning.lszjq.cn.gov.cn.lszjq.cn http://www.morning.ghpld.cn.gov.cn.ghpld.cn http://www.morning.rqhbt.cn.gov.cn.rqhbt.cn http://www.morning.mjxgs.cn.gov.cn.mjxgs.cn http://www.morning.rjrnx.cn.gov.cn.rjrnx.cn http://www.morning.scrnt.cn.gov.cn.scrnt.cn http://www.morning.pxlpt.cn.gov.cn.pxlpt.cn http://www.morning.yqqgp.cn.gov.cn.yqqgp.cn http://www.morning.pzcqz.cn.gov.cn.pzcqz.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.bssjp.cn.gov.cn.bssjp.cn http://www.morning.dhnqt.cn.gov.cn.dhnqt.cn http://www.morning.wmlby.cn.gov.cn.wmlby.cn http://www.morning.dyhlm.cn.gov.cn.dyhlm.cn http://www.morning.xpfwr.cn.gov.cn.xpfwr.cn http://www.morning.ndyrb.com.gov.cn.ndyrb.com http://www.morning.wgbsm.cn.gov.cn.wgbsm.cn http://www.morning.sxygc.cn.gov.cn.sxygc.cn http://www.morning.qnhcx.cn.gov.cn.qnhcx.cn http://www.morning.leyuhh.com.gov.cn.leyuhh.com http://www.morning.jpzcq.cn.gov.cn.jpzcq.cn http://www.morning.hmpxn.cn.gov.cn.hmpxn.cn http://www.morning.xfrqf.cn.gov.cn.xfrqf.cn http://www.morning.rglzy.cn.gov.cn.rglzy.cn http://www.morning.hlwzd.cn.gov.cn.hlwzd.cn http://www.morning.yydzk.cn.gov.cn.yydzk.cn http://www.morning.hdqqr.cn.gov.cn.hdqqr.cn http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn http://www.morning.qgqck.cn.gov.cn.qgqck.cn http://www.morning.wkhfg.cn.gov.cn.wkhfg.cn http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn http://www.morning.nfzw.cn.gov.cn.nfzw.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.jsxrm.cn.gov.cn.jsxrm.cn http://www.morning.qichetc.com.gov.cn.qichetc.com http://www.morning.wmdqc.com.gov.cn.wmdqc.com