프로젝트

일반

사용자정보

통계
| 개정판:

t1 / TFDContents / Assets / KinectDemos / FaceTrackingDemo / Scripts / SetBackgroundRemovalImage.cs @ 3

이력 | 보기 | 이력해설 | 다운로드 (2.32 KB)

1
using UnityEngine;
2
using System.Collections;
3

    
4
public class SetBackgroundRemovalImage : MonoBehaviour 
5
{
6
	[Tooltip("GUI-texture used to display the color camera feed on the scene background.")]
7
	public GUITexture backgroundImage;
8

    
9
	[Tooltip("Camera that will be set-up to display 3D-models in the Kinect FOV.")]
10
	public Camera foregroundCamera;
11

    
12
	[Tooltip("Use this setting to minimize the offset between the image and the model overlay.")]
13
	[Range(-0.1f, 0.1f)]
14
	public float adjustedCameraOffset = 0f;
15
	
16
	
17
	// variable to track the current camera offset
18
	private float currentCameraOffset = 0f;
19
	// initial camera position
20
	private Vector3 initialCameraPos = Vector3.zero;
21
	
22

    
23
	void Start()
24
	{
25
		KinectManager manager = KinectManager.Instance;
26
		
27
		if(manager && manager.IsInitialized())
28
		{
29
			KinectInterop.SensorData sensorData = manager.GetSensorData();
30

    
31
			if(foregroundCamera != null && sensorData != null && sensorData.sensorInterface != null)
32
			{
33
				foregroundCamera.fieldOfView = sensorData.colorCameraFOV;
34

    
35
				initialCameraPos = foregroundCamera.transform.position;
36
				Vector3 fgCameraPos = initialCameraPos;
37
				
38
				fgCameraPos.x += sensorData.faceOverlayOffset + adjustedCameraOffset;
39
				foregroundCamera.transform.position = fgCameraPos;
40
				currentCameraOffset = adjustedCameraOffset;
41
			}
42
		}
43
	}
44

    
45
	void Update()
46
	{
47
		BackgroundRemovalManager backManager = BackgroundRemovalManager.Instance;
48
		if(backManager && backManager.IsBackgroundRemovalInitialized())
49
		{
50
			Texture foregroundTex = backManager.GetForegroundTex();
51

    
52
			if(backgroundImage && (backgroundImage.texture == null) && foregroundTex)
53
			{
54
				backgroundImage.texture = foregroundTex;
55
			}
56
		}
57

    
58
		KinectManager manager = KinectManager.Instance;
59
		if(manager && manager.IsInitialized())
60
		{
61
			if(currentCameraOffset != adjustedCameraOffset)
62
			{
63
				// update the camera automatically, according to the current sensor height and angle
64
				KinectInterop.SensorData sensorData = manager.GetSensorData();
65
				
66
				if(foregroundCamera != null && sensorData != null)
67
				{
68
					Vector3 fgCameraPos = initialCameraPos;
69
					fgCameraPos.x += sensorData.faceOverlayOffset + adjustedCameraOffset;
70
					foregroundCamera.transform.position = fgCameraPos;
71
					currentCameraOffset = adjustedCameraOffset;
72
				}
73
			}
74
		}
75
	}
76

    
77
}