feat: webcam crop

This commit is contained in:
Michel Roux 2024-01-27 15:22:45 +01:00
parent f6b5408275
commit 95665b2aab
3 changed files with 28 additions and 6 deletions

View File

@ -625,10 +625,10 @@ RectTransform:
m_Children: []
m_Father: {fileID: 1908036955}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: 512, y: 512}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1128585036
MonoBehaviour:
@ -643,6 +643,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
webCamTexture: {fileID: 0}
freezeButton: {fileID: 1776746473}
resumeButton: {fileID: 1872873213}
--- !u!114 &1128585037
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -11,14 +11,34 @@ public class CameraManager : MonoBehaviour
void Start()
{
webCamTexture = new WebCamTexture();
//gameObject.transform.rotation = transform.rotation * Quaternion.AngleAxis(webCamTexture.videoRotationAngle, Vector3.up);
WebcamResume();
}
// Update is called once per frame
void Update()
{
gameObject.GetComponent<RawImage>().texture = webCamTexture;
gameObject.GetComponent<RawImage>().material.mainTexture = webCamTexture;
var x = 0;
var y = 0;
var size = webCamTexture.height;
if (webCamTexture.height > webCamTexture.width)
{
size = webCamTexture.width;
y = (webCamTexture.height - webCamTexture.width) / 2;
}
else if (webCamTexture.height < webCamTexture.width)
{
size = webCamTexture.height;
x = (webCamTexture.width - webCamTexture.height) / 2;
}
Texture2D cropped = new(size, size);
cropped.SetPixels(webCamTexture.GetPixels(x, y, size, size));
cropped.Apply();
gameObject.GetComponent<RawImage>().texture = cropped;
gameObject.GetComponent<RawImage>().material.mainTexture = cropped;
}
public void WebcamResume()

View File

@ -8,7 +8,7 @@ PlayerSettings:
AndroidProfiler: 0
AndroidFilterTouchesWhenObscured: 0
AndroidEnableSustainedPerformanceMode: 0
defaultScreenOrientation: 4
defaultScreenOrientation: 0
targetDevice: 2
useOnDemandResources: 0
accelerometerFrequency: 60