简体   繁体   English

如何在Unity iOS中正确使用WebCamTexture?

[英]How can I properly use WebCamTexture in Unity iOS?

I was recently using the WebCamTexture API in Unity , but ran across a couple issues. 我最近在Unity中使用了WebCamTexture API ,但是遇到了几个问题。

My biggest issue is orientation. 我最大的问题是方向。 When I ran the app on my phone, it wouldn't work properly in portrait mode: the image was orientated so it was landscape while the phone was portrait. 当我在手机上运行该应用程序时,它无法在纵向模式下正常工作:图像经过定向,因此在手机为纵向模式时为横向。 Rotating the phone didn't help. 旋转手机没有帮助。

Then I changed the default orientation of the app to landscape and it worked, but the image was reflected: letters and such would be backwards in the image. 然后,我将应用程序的默认方向更改为横向,并且可以使用,但是图像得到了反映:字母等在图像中向后倾斜。 Rotating the image 180 on the y-axis didn't help since it was a 1 sided image. 将图像在y轴上旋转180度无济于事,因为它是1面图像。

Here's the code for the camera alone: 这是单独的相机代码:

cam = new WebCamTexture();
camImage.texture = cam;
camImage.material.mainTexture = cam;
cam.Play ();
camImage.transform.localScale = new Vector3(-1,-1,1);

where camImage is a RawImage. 其中camImage是RawImage。

How would I rotate the image to work correctly in portrait as well as reflecting the image correctly? 如何旋转图像以使其在人像中正常工作以及如何正确反射图像? Am I using the API incorrectly? 我使用API​​的方式有误吗?

important - 重要-

for some years now, it is really only practical to use "NatCam" now for camera work, either ios or droid, in Unity3D - every app which uses the camera, uses it. 多年来,在Unity3D中使用“ NatCam”进行ios或droid的摄像头工作实际上是仅实际的-每个使用摄像头的应用程序都使用它。

There is no other realistic solution, until Unity actually do the job and include (working :) ) camera software. 没有其他现实的解决方案,直到Unity真正完成工作并包括(working :))摄像头软件。


solution is basically this ... 解决方案基本上是这个...

you have to do this EVERY FRAME, you can't do it "when the camera starts". 您必须做到每一个帧,“相机启动时”就不能这样做。

Unity f'd up and the actual values only arrive after a second or so. 团结起来,实际价值只有一秒钟左右。 it's a well-known problem 这是一个众所周知的问题

private void _orient()
    {
    float physical = (float)wct.width/(float)wct.height;
    rawImageARF.aspectRatio = physical;

    float scaleY = wct.videoVerticallyMirrored ? -1f : 1f;
    rawImageRT.localScale = new Vector3(1f, scaleY, 1f);

    int orient = -wct.videoRotationAngle;
    rawImageRT.localEulerAngles = new Vector3(0f,0f,orient);
    showOrient.text = orient.ToString();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM