This repository was archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDepthCameraManger.cs
More file actions
111 lines (101 loc) · 3.1 KB
/
Copy pathDepthCameraManger.cs
File metadata and controls
111 lines (101 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Intel.RealSense;
public class DepthCameraManger : MonoBehaviour {
/**
* Depth Camera Component
**/
public SenseManager senseManager;
CaptureManager captureManager;
DeviceInfo deviceInfo;
public bool isStart;
// Tag for Log
string TAG = "Depth Camera : ";
//Call this before start
void Awake()
{
InititalizeSenseManager();
}
// Initialize Sense Manager
void InititalizeSenseManager()
{
Session session = Session.CreateInstance()
if (session == null)
throw new System.Exception("Session Initialize Failure!");
senseManager = session.CreateSenseManager();
if (senseManager == null)
throw new System.Exception("Sense Manager Initialize Failure!");
else
{
Debug.Log(TAG + "Sense Manager Initialize Successful");
InitializeCaptureManager();
}
}
// Initialize Capture Manager
void InitializeCaptureManager()
{
captureManager = senseManager.CaptureManager;
if (captureManager == null)
throw new System.Exception("Capture Manager Initialize Failure!");
else
{
Debug.Log(TAG + "Capture Manager Initialize Successful");
LoadCapture();
}
}
// Load Capture from Group Sensor Info
void LoadCapture()
{
ImplDesc desc = new ImplDesc()
{
group = ImplGroup.IMPL_GROUP_SENSOR,
subgroup = ImplSubgroup.IMPL_SUBGROUP_VIDEO_CAPTURE
};
Capture capture;
if (senseManager.Session.CreateImpl<Capture>(senseManager.Session.QueryImpl(desc, 0), out capture) < Status.STATUS_NO_ERROR)
throw new System.Exception("Initialize Capture Failure!");
else
{
if (capture == null || capture.DeviceInfo == null || capture.DeviceInfo.Length == 0)
throw new System.Exception("Capturing Failure");
else
{
CaptureDevice(capture);
}
}
}
// Capture Device
void CaptureDevice(Capture capture)
{
deviceInfo = capture.DeviceInfo[0];
if (deviceInfo == null)
throw new System.Exception("Fail to obtain camera!");
else
{
if (captureManager.SetFileName(deviceInfo.name, true) < Status.STATUS_NO_ERROR)
throw new System.Exception("Fail to connect to " + deviceInfo.name);
else
{
Debug.Log(TAG + "Connect to " + deviceInfo.name);
GetComponent<HandManager>().InitializeHandManger();
}
}
}
// Start Device
public void StartDevice()
{
if (senseManager.Init() == Status.STATUS_NO_ERROR)
{
Debug.Log(TAG + "Initialization Successful!");
isStart = true;
}
else
throw new System.Exception("Initialization Failed!");
}
// Call when exit application
void OnApplicationQuit()
{
senseManager.Close();
}
}