Skip to content

Commit 9a0ef51

Browse files
committed
Added a helper class for getting the Camera Intrinsics of a Hololens device.
Updated the usage version of the WebCamTextureToMatHelper to 1.0.2. Updated the usage version of the OptimizationWebCamTextureToMatHelper to 1.0.2. Fixed typos.
1 parent a59219d commit 9a0ef51

25 files changed

Lines changed: 819 additions & 132 deletions

Assets/HoloLensWithOpenCVForUnityExample/HoloLensArUcoExample/HoloLensArUcoExample.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
namespace HoloLensWithOpenCVForUnityExample
1515
{
1616
/// <summary>
17-
/// HoloLens ArUco example. (Example of marker based AR using the OpenCVForUnity on Hololens)
18-
/// https://github.com/opencv/opencv_contrib/blob/master/modules/aruco/samples/detect_markers.cpp
17+
/// HoloLens ArUco example.
18+
/// An example of marker based AR using OpenCVForUnity on Hololens.
19+
/// Referring to https://github.com/opencv/opencv_contrib/blob/master/modules/aruco/samples/detect_markers.cpp.
1920
/// </summary>
2021
[RequireComponent(typeof(WebCamTextureToMatHelper))]
2122
public class HoloLensArUcoExample : MonoBehaviour
@@ -159,9 +160,10 @@ public class HoloLensArUcoExample : MonoBehaviour
159160
Mat rgbMat4preview;
160161
Texture2D texture;
161162

162-
// Camera matrix value of Hololens camera 896x504 size.
163-
// These values ​​are unique to my device, obtained from "Windows.Media.Devices.Core.CameraIntrinsics" class. (https://docs.microsoft.com/en-us/uwp/api/windows.media.devices.core.cameraintrinsics)
164-
// (can adjust the position of the AR hologram with the values ​​of cx and cy. see http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html)
163+
// The camera matrix value of Hololens camera 896x504 size.
164+
// For details on the camera matrix, please refer to this page. (http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html)
165+
// These values ​​are unique to my device, obtained from the "Windows.Media.Devices.Core.CameraIntrinsics" class. (https://docs.microsoft.com/en-us/uwp/api/windows.media.devices.core.cameraintrinsics)
166+
// Can get these values by using this helper script. (https://github.com/EnoxSoftware/HoloLensWithOpenCVForUnityExample/tree/master/Assets/HololensCameraIntrinsicsChecker/CameraIntrinsicsCheckerHelper)
165167
double fx = 1035.149;//focal length x.
166168
double fy = 1034.633;//focal length y.
167169
double cx = 404.9134;//principal point x.
@@ -473,11 +475,11 @@ private void OnDetectionDone()
473475

474476
isDetecting = false;
475477
}
476-
478+
477479
/// <summary>
478-
/// Raises the disable event.
480+
/// Raises the destroy event.
479481
/// </summary>
480-
void OnDisable ()
482+
void OnDestroy ()
481483
{
482484
webCamTextureToMatHelper.Dispose ();
483485
}

Assets/HoloLensWithOpenCVForUnityExample/HoloLensArUcoExample/TapInput.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ namespace HoloLensWithOpenCVForUnityExample
88
{
99
public class TapInput : MonoBehaviour
1010
{
11-
1211
public UnityEvent OnTappedEvent;
1312

1413
GestureRecognizer recognizer;

Assets/HoloLensWithOpenCVForUnityExample/HoloLensComicFilterExample/HoloLensComicFilterExample.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
namespace HoloLensWithOpenCVForUnityExample
1111
{
1212
/// <summary>
13-
/// HoloLens ComicFilter example. (Example of the comic filter using the OpenCVForUnity on Hololens)
14-
/// referring to the http://dev.classmethod.jp/smartphone/opencv-manga-2/.
13+
/// HoloLens ComicFilter example.
14+
/// An example of image processing (comic filter) using OpenCVForUnity on Hololens.
15+
/// Referring to http://dev.classmethod.jp/smartphone/opencv-manga-2/.
1516
/// </summary>
1617
[RequireComponent(typeof(OptimizationWebCamTextureToMatHelper))]
1718
public class HoloLensComicFilterExample : MonoBehaviour
@@ -277,9 +278,9 @@ void Update ()
277278
}
278279

279280
/// <summary>
280-
/// Raises the disable event.
281+
/// Raises the destroy event.
281282
/// </summary>
282-
void OnDisable ()
283+
void OnDestroy ()
283284
{
284285
webCamTextureToMatHelper.Dispose ();
285286
}

Assets/HoloLensWithOpenCVForUnityExample/HoloLensFaceDetectionExample/HoloLensFaceDetectionExample.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
namespace HoloLensWithOpenCVForUnityExample
1616
{
1717
/// <summary>
18-
/// HoloLens face detection example. (Example of face detection using the OpenCVForUnity on Hololens)
19-
/// This cord referred to https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/detection_based_tracker.cpp.
18+
/// HoloLens face detection example.
19+
/// An example of detecting face using OpenCVForUnity on Hololens.
20+
/// Referring to https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/detection_based_tracker.cpp.
2021
/// </summary>
2122
[RequireComponent(typeof(OptimizationWebCamTextureToMatHelper))]
2223
public class HoloLensFaceDetectionExample : MonoBehaviour
@@ -408,11 +409,11 @@ private void DetectInRegion (Mat img, Rect r, List<Rect> detectedObjectsInRegion
408409
detectedObjectsInRegions.Add (curres);
409410
}
410411
}
411-
412+
412413
/// <summary>
413-
/// Raises the disable event.
414+
/// Raises the destroy event.
414415
/// </summary>
415-
void OnDisable ()
416+
void OnDestroy ()
416417
{
417418
webCamTextureToMatHelper.Dispose ();
418419

Assets/HoloLensWithOpenCVForUnityExample/HoloLensFaceDetectionOverlayExample/HoloLensFaceDetectionOverlayExample.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
namespace HoloLensWithOpenCVForUnityExample
1616
{
1717
/// <summary>
18-
/// HoloLens face detection overlay example. (Overlay display of face area rectangles)
19-
/// This cord referred to https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/detection_based_tracker.cpp.
18+
/// HoloLens face detection overlay example.
19+
/// An example of overlay display of face area rectangles using OpenCVForUnity on Hololens.
20+
/// Referring to https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/detection_based_tracker.cpp.
2021
/// </summary>
2122
[RequireComponent(typeof(OptimizationWebCamTextureToMatHelper))]
2223
public class HoloLensFaceDetectionOverlayExample : MonoBehaviour
@@ -408,9 +409,9 @@ private void DetectInRegion (Mat img, Rect r, List<Rect> detectedObjectsInRegion
408409
}
409410

410411
/// <summary>
411-
/// Raises the disable event.
412+
/// Raises the destroy event.
412413
/// </summary>
413-
void OnDisable ()
414+
void OnDestroy ()
414415
{
415416
webCamTextureToMatHelper.Dispose ();
416417

Assets/HoloLensWithOpenCVForUnityExample/HoloLensFaceDetectionOverlayExample/Overlay/RectOverlay.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public float height
3535
return targetHeight;
3636
}
3737
}
38-
39-
protected Transform overlayTransform;
38+
4039
protected Transform targetTransform;
4140
protected float targetWidth = 0;
4241
protected float targetHeight = 0;
42+
protected Transform overlayTransform;
4343
protected ObjectPool objectPool;
4444

4545
void Awake()
@@ -110,10 +110,10 @@ public virtual void UpdateOverlayTransform(Transform targetTransform)
110110
this.targetTransform = null;
111111
return;
112112
}
113-
114-
this.targetTransform = targetTransform;
113+
115114
targetWidth = targetTransform.localScale.x;
116115
targetHeight = targetTransform.localScale.y;
116+
this.targetTransform = targetTransform;
117117
overlayTransform.localPosition = targetTransform.localPosition;
118118
overlayTransform.localRotation = targetTransform.localRotation;
119119
overlayTransform.localScale = targetTransform.localScale;

Assets/HoloLensWithOpenCVForUnityExample/HoloLensPhotoCaptureExample/HoloLensPhotoCaptureExample.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
namespace HoloLensWithOpenCVForUnityExample
1414
{
1515
/// <summary>
16-
/// HoloLens photo capture (and face detection) example.
17-
/// referring to the https://forum.unity3d.com/threads/holographic-photo-blending-with-photocapture.416023/.
16+
/// HoloLens photo capture example.
17+
/// An example of holographic photo blending using the PhotocCapture class on Hololens.
18+
/// Referring to https://forum.unity3d.com/threads/holographic-photo-blending-with-photocapture.416023/.
1819
/// </summary>
1920
public class HoloLensPhotoCaptureExample:MonoBehaviour
2021
{
@@ -201,9 +202,9 @@ void OnStopPhotoMode (PhotoCapture.PhotoCaptureResult result)
201202
}
202203

203204
/// <summary>
204-
/// Raises the disable event.
205+
/// Raises the destroy event.
205206
/// </summary>
206-
void OnDisable ()
207+
void OnDestroy ()
207208
{
208209
if (m_PhotoCaptureObj != null)
209210
m_PhotoCaptureObj.StopPhotoModeAsync (OnStopPhotoMode);
Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
using UnityEngine;
2-
using System.Collections;
3-
4-
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
5-
using UnityEngine.SceneManagement;
6-
#endif
7-
8-
namespace HoloLensWithOpenCVForUnityExample
9-
{
10-
public class HoloLensWithOpenCVForUnityExample : MonoBehaviour
11-
{
12-
// Use this for initialization
13-
void Start ()
14-
{
15-
16-
}
17-
18-
// Update is called once per frame
19-
void Update ()
20-
{
21-
22-
}
23-
24-
public void OnShowLicenseButtonClick ()
25-
{
26-
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
27-
SceneManager.LoadScene ("ShowLicense");
28-
#else
29-
Application.LoadLevel ("ShowLicense");
30-
#endif
31-
}
32-
33-
public void OnHoloLensPhotoCaptureExampleButtonClick ()
34-
{
35-
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
36-
SceneManager.LoadScene ("HoloLensPhotoCaptureExample");
37-
#else
38-
Application.LoadLevel ("HoloLensPhotoCaptureExample");
39-
#endif
40-
}
41-
42-
public void OnHoloLensComicFilterExampleButtonClick ()
43-
{
44-
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
45-
SceneManager.LoadScene ("HoloLensComicFilterExample");
46-
#else
47-
Application.LoadLevel ("HoloLensComicFilterExample");
48-
#endif
49-
}
50-
51-
public void OnHoloLensFaceDetectionExampleButtonClick ()
52-
{
53-
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
54-
SceneManager.LoadScene ("HoloLensFaceDetectionExample");
55-
#else
56-
Application.LoadLevel ("HoloLensFaceDetectionExample");
57-
#endif
58-
}
59-
60-
public void OnHoloLensFaceDetectionOverlayExampleButtonClick ()
61-
{
62-
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
63-
SceneManager.LoadScene ("HoloLensFaceDetectionOverlayExample");
64-
#else
65-
Application.LoadLevel ("HoloLensFaceDetectionOverlayExample");
66-
#endif
67-
}
68-
69-
public void OnHoloLensArUcoExampleButtonClick ()
70-
{
71-
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
72-
SceneManager.LoadScene ("HoloLensArUcoExample");
73-
#else
74-
Application.LoadLevel ("HoloLensArUcoExample");
75-
#endif
76-
}
77-
}
1+
using UnityEngine;
2+
using System.Collections;
3+
4+
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
5+
using UnityEngine.SceneManagement;
6+
#endif
7+
8+
namespace HoloLensWithOpenCVForUnityExample
9+
{
10+
public class HoloLensWithOpenCVForUnityExample : MonoBehaviour
11+
{
12+
// Use this for initialization
13+
void Start ()
14+
{
15+
16+
}
17+
18+
// Update is called once per frame
19+
void Update ()
20+
{
21+
22+
}
23+
24+
public void OnShowLicenseButtonClick ()
25+
{
26+
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
27+
SceneManager.LoadScene ("ShowLicense");
28+
#else
29+
Application.LoadLevel ("ShowLicense");
30+
#endif
31+
}
32+
33+
public void OnHoloLensPhotoCaptureExampleButtonClick ()
34+
{
35+
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
36+
SceneManager.LoadScene ("HoloLensPhotoCaptureExample");
37+
#else
38+
Application.LoadLevel ("HoloLensPhotoCaptureExample");
39+
#endif
40+
}
41+
42+
public void OnHoloLensComicFilterExampleButtonClick ()
43+
{
44+
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
45+
SceneManager.LoadScene ("HoloLensComicFilterExample");
46+
#else
47+
Application.LoadLevel ("HoloLensComicFilterExample");
48+
#endif
49+
}
50+
51+
public void OnHoloLensFaceDetectionExampleButtonClick ()
52+
{
53+
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
54+
SceneManager.LoadScene ("HoloLensFaceDetectionExample");
55+
#else
56+
Application.LoadLevel ("HoloLensFaceDetectionExample");
57+
#endif
58+
}
59+
60+
public void OnHoloLensFaceDetectionOverlayExampleButtonClick ()
61+
{
62+
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
63+
SceneManager.LoadScene ("HoloLensFaceDetectionOverlayExample");
64+
#else
65+
Application.LoadLevel ("HoloLensFaceDetectionOverlayExample");
66+
#endif
67+
}
68+
69+
public void OnHoloLensArUcoExampleButtonClick ()
70+
{
71+
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
72+
SceneManager.LoadScene ("HoloLensArUcoExample");
73+
#else
74+
Application.LoadLevel ("HoloLensArUcoExample");
75+
#endif
76+
}
77+
}
7878
}

Assets/HoloLensWithOpenCVForUnityExample/Materials/holographicImageBlend.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Shader "AR/HolographicImageBlend"
44
{
5-
// referring to the https://forum.unity3d.com/threads/holographic-photo-blending-with-photocapture.416023/.
5+
// Referring to https://forum.unity3d.com/threads/holographic-photo-blending-with-photocapture.416023/.
66

77
Properties
88
{

Assets/HoloLensWithOpenCVForUnityExample/RectangleTracker/Scripts/RectangleTracker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace OpenCVForUnity.RectangleTrack
77
{
88
/// <summary>
99
/// Rectangle tracker.
10-
/// This cord referred to https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/detection_based_tracker.cpp.
10+
/// Referring to https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/detection_based_tracker.cpp.
1111
/// v 1.0.1
1212
/// </summary>
1313
public class RectangleTracker : IDisposable

0 commit comments

Comments
 (0)