Skip to content

Commit baf9aa8

Browse files
committed
v1.0.2
Updated OpenCVForUnity version to 2.2.9. Updated NatCam version to 2.0f3. Updated NatShare version to 1.0f3.
1 parent 56aa17f commit baf9aa8

File tree

7 files changed

+151
-89
lines changed

7 files changed

+151
-89
lines changed

Assets/NatCamWithOpenCVForUnityExample/NatCamPreviewOnlyExample/NatCamPreviewOnlyExample.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ public virtual void Start ()
6565

6666
if (fpsMonitor != null)
6767
fpsMonitor.consoleText = "NatCam.Implementation.HasPermissions == false";
68-
69-
return;
7068
}
7169

7270
// Load global camera benchmark settings.
@@ -120,6 +118,9 @@ public virtual void OnStart ()
120118
// Scale the panel to match aspect ratios
121119
aspectFitter.aspectRatio = NatCam.Preview.width / (float)NatCam.Preview.height;
122120

121+
if (fpsMonitor != null)
122+
fpsMonitor.consoleText = "";
123+
123124
Debug.Log ("# Active Camera Properties #####################");
124125

125126
try
@@ -202,7 +203,7 @@ public virtual void OnFrame ()
202203
buffer = buffer ?? new byte[NatCam.Preview.width * NatCam.Preview.height * 4];
203204

204205
// Capture the current frame
205-
if (!NatCam.CaptureFrame (buffer)) return;
206+
NatCam.CaptureFrame (buffer);
206207

207208
// Size checking
208209
if (texture && (texture.width != NatCam.Preview.width || texture.height != NatCam.Preview.height)) {

Assets/NatCamWithOpenCVForUnityExample/NatCamPreviewToMatExample/NatCamPreviewToMatExample.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ public virtual void Start ()
9090

9191
if (fpsMonitor != null)
9292
fpsMonitor.consoleText = "NatCam.Implementation.HasPermissions == false";
93-
94-
return;
9593
}
9694

9795
// Load global camera benchmark settings.
@@ -170,6 +168,9 @@ public virtual void OnStart ()
170168
// Display the result
171169
preview.texture = texture;
172170

171+
if (fpsMonitor != null)
172+
fpsMonitor.consoleText = "";
173+
173174
Debug.Log ("OnStart (): " + matrix.cols() + " " + matrix.rows() + " " + NatCam.Preview.width + " " + NatCam.Preview.height + " " + texture.width + " " + texture.height);
174175
}
175176

Assets/NatCamWithOpenCVForUnityExample/NatCamWithOpenCVForUnityExample.unity

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,17 @@ LightmapSettings:
7777
m_PVRDirectSampleCount: 32
7878
m_PVRSampleCount: 500
7979
m_PVRBounces: 2
80-
m_PVRFiltering: 0
80+
m_PVRFilterTypeDirect: 0
81+
m_PVRFilterTypeIndirect: 0
82+
m_PVRFilterTypeAO: 0
8183
m_PVRFilteringMode: 1
8284
m_PVRCulling: 1
8385
m_PVRFilteringGaussRadiusDirect: 1
8486
m_PVRFilteringGaussRadiusIndirect: 5
8587
m_PVRFilteringGaussRadiusAO: 2
86-
m_PVRFilteringAtrousColorSigma: 1
87-
m_PVRFilteringAtrousNormalSigma: 1
88-
m_PVRFilteringAtrousPositionSigma: 1
88+
m_PVRFilteringAtrousPositionSigmaDirect: 0.5
89+
m_PVRFilteringAtrousPositionSigmaIndirect: 2
90+
m_PVRFilteringAtrousPositionSigmaAO: 1
8991
m_LightingDataAsset: {fileID: 0}
9092
m_ShadowMaskMode: 2
9193
--- !u!196 &5
@@ -1584,7 +1586,7 @@ GameObject:
15841586
- component: {fileID: 845653024}
15851587
- component: {fileID: 845653023}
15861588
m_Layer: 5
1587-
m_Name: WebCamTextureToMatExample
1589+
m_Name: WebCamTextureToMatExampleButton
15881590
m_TagString: Untagged
15891591
m_Icon: {fileID: 0}
15901592
m_NavMeshLayer: 0
@@ -2529,7 +2531,7 @@ MonoBehaviour:
25292531
m_HandleRect: {fileID: 760072662}
25302532
m_Direction: 2
25312533
m_Value: 1
2532-
m_Size: 0.79066855
2534+
m_Size: 0.9999999
25332535
m_NumberOfSteps: 0
25342536
m_OnValueChanged:
25352537
m_PersistentCalls:
@@ -2731,7 +2733,7 @@ GameObject:
27312733
- component: {fileID: 1415450861}
27322734
- component: {fileID: 1415450860}
27332735
m_Layer: 5
2734-
m_Name: IntegrationWithNatShareExample
2736+
m_Name: IntegrationWithNatShareExampleButton
27352737
m_TagString: Untagged
27362738
m_Icon: {fileID: 0}
27372739
m_NavMeshLayer: 0
@@ -3105,7 +3107,7 @@ GameObject:
31053107
- component: {fileID: 1470011369}
31063108
- component: {fileID: 1470011368}
31073109
m_Layer: 5
3108-
m_Name: NatCamPreviewToMatExample
3110+
m_Name: NatCamPreviewToMatExampleButton
31093111
m_TagString: Untagged
31103112
m_Icon: {fileID: 0}
31113113
m_NavMeshLayer: 0
@@ -3422,7 +3424,7 @@ GameObject:
34223424
- component: {fileID: 1504995596}
34233425
- component: {fileID: 1504995595}
34243426
m_Layer: 5
3425-
m_Name: NatCamPreviewOnlyExample
3427+
m_Name: NatCamPreviewOnlyExampleButton
34263428
m_TagString: Untagged
34273429
m_Icon: {fileID: 0}
34283430
m_NavMeshLayer: 0
@@ -4213,7 +4215,7 @@ GameObject:
42134215
- component: {fileID: 1723970709}
42144216
- component: {fileID: 1723970708}
42154217
m_Layer: 5
4216-
m_Name: WebCamTextureOnlyExample
4218+
m_Name: WebCamTextureOnlyExampleButton
42174219
m_TagString: Untagged
42184220
m_Icon: {fileID: 0}
42194221
m_NavMeshLayer: 0
@@ -4502,7 +4504,7 @@ GameObject:
45024504
- component: {fileID: 1791960687}
45034505
- component: {fileID: 1791960686}
45044506
m_Layer: 5
4505-
m_Name: NatCamPreviewToMatHelperExample
4507+
m_Name: NatCamPreviewToMatHelperExampleButton
45064508
m_TagString: Untagged
45074509
m_Icon: {fileID: 0}
45084510
m_NavMeshLayer: 0

Assets/NatCamWithOpenCVForUnityExample/Scripts/Utils/NatCamPreviewToMatHelper.cs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace NatCamWithOpenCVForUnityExample
99
{
1010
/// <summary>
1111
/// NatCamPreview to mat helper.
12-
/// v 1.0.2
12+
/// v 1.0.3
1313
/// Depends on NatCam version 2.0f1 or later.
1414
/// </summary>
1515
public class NatCamPreviewToMatHelper : WebCamTextureToMatHelper
@@ -77,6 +77,37 @@ public virtual void OnFrame ()
7777
// Update is called once per frame
7878
protected override void Update ()
7979
{
80+
if (hasInitDone) {
81+
// Catch the orientation change of the screen and correct the mat image to the correct direction.
82+
if (screenOrientation != Screen.orientation && (screenWidth != Screen.width || screenHeight != Screen.height)) {
83+
84+
if (onDisposed != null)
85+
onDisposed.Invoke ();
86+
87+
if (frameMat != null) {
88+
frameMat.Dispose ();
89+
frameMat = null;
90+
}
91+
if (rotatedFrameMat != null) {
92+
rotatedFrameMat.Dispose ();
93+
rotatedFrameMat = null;
94+
}
95+
96+
frameMat = new Mat (NatCam.Preview.height, NatCam.Preview.width, CvType.CV_8UC4);
97+
screenOrientation = Screen.orientation;
98+
screenWidth = Screen.width;
99+
screenHeight = Screen.height;
100+
101+
if (rotate90Degree)
102+
rotatedFrameMat = new Mat (NatCam.Preview.width, NatCam.Preview.height, CvType.CV_8UC4);
103+
104+
if (onInitialized != null)
105+
onInitialized.Invoke ();
106+
} else {
107+
screenWidth = Screen.width;
108+
screenHeight = Screen.height;
109+
}
110+
}
80111
}
81112

82113
public virtual void LateUpdate ()
@@ -91,11 +122,6 @@ protected override IEnumerator _Initialize ()
91122
{
92123
if (!NatCam.Implementation.HasPermissions) {
93124
Debug.LogError ("NatCam.Implementation.HasPermissions == false");
94-
95-
if (onErrorOccurred != null)
96-
onErrorOccurred.Invoke (ErrorCode.CAMERA_DEVICE_NOT_EXIST);
97-
98-
yield break;
99125
}
100126

101127
if (hasInitDone)
@@ -312,7 +338,7 @@ protected override void FlipMat (Mat mat, bool flipVertical, bool flipHorizontal
312338
{
313339
int flipCode = int.MinValue;
314340

315-
if (_flipVertical) {
341+
if (flipVertical) {
316342
if (flipCode == int.MinValue) {
317343
flipCode = 0;
318344
} else if (flipCode == 0) {
@@ -324,7 +350,7 @@ protected override void FlipMat (Mat mat, bool flipVertical, bool flipHorizontal
324350
}
325351
}
326352

327-
if (_flipHorizontal) {
353+
if (flipHorizontal) {
328354
if (flipCode == int.MinValue) {
329355
flipCode = 1;
330356
} else if (flipCode == 0) {

0 commit comments

Comments
 (0)