Skip to content

Commit 56aa17f

Browse files
committed
v1.0.1
1 parent 426abf4 commit 56aa17f

File tree

9 files changed

+66
-38
lines changed

9 files changed

+66
-38
lines changed

Assets/NatCamWithOpenCVForUnityExample/IntegrationWithNatShareExample/IntegrationWithNatShareExample.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public virtual void OnStart ()
111111
matrix = null;
112112
}
113113
matrix = matrix ?? new Mat(NatCam.Preview.height, NatCam.Preview.width, CvType.CV_8UC4);
114-
matrix.put(0, 0, pixelBuffer);
114+
Utils.copyToMat (pixelBuffer, matrix);
115115

116116
// Create display texture
117117
if (texture && (texture.width != matrix.cols() || texture.height != matrix.rows())) {
@@ -203,7 +203,7 @@ private Mat GetMat ()
203203
// Set `flip` flag to true because OpenCV uses inverted Y-coordinate system
204204
NatCam.CaptureFrame(pixelBuffer, true);
205205

206-
matrix.put(0, 0, pixelBuffer);
206+
Utils.copyToMat (pixelBuffer, matrix);
207207

208208
return matrix;
209209
}

Assets/NatCamWithOpenCVForUnityExample/IntegrationWithNatShareExample/IntegrationWithNatShareExample.unity

Lines changed: 7 additions & 8 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 &4
@@ -1423,14 +1425,11 @@ MonoBehaviour:
14231425
m_Script: {fileID: 11500000, guid: f5ca190fc54d25e4a80601d2e5f9c573, type: 3}
14241426
m_Name:
14251427
m_EditorClassIdentifier:
1426-
preview: {fileID: 675452960}
14271428
useFrontCamera: 0
1429+
preview: {fileID: 675452960}
14281430
previewResolution:
14291431
width: 1280
14301432
height: 720
1431-
photoResolution:
1432-
width: 1920
1433-
height: 1080
14341433
requestedFPS: 30
14351434
aspectFitter: {fileID: 675452962}
14361435
--- !u!4 &1466705441

Assets/NatCamWithOpenCVForUnityExample/NatCamPreviewOnlyExample/NatCamPreviewOnlyExample.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ public enum ImageProcessingType
5858

5959
public virtual void Start ()
6060
{
61+
fpsMonitor = GetComponent<FpsMonitor> ();
62+
63+
if (!NatCam.Implementation.HasPermissions) {
64+
Debug.LogError ("NatCam.Implementation.HasPermissions == false");
65+
66+
if (fpsMonitor != null)
67+
fpsMonitor.consoleText = "NatCam.Implementation.HasPermissions == false";
68+
69+
return;
70+
}
71+
6172
// Load global camera benchmark settings.
6273
int width, height, fps;
6374
NatCamWithOpenCVForUnityExample.GetCameraResolution (out width, out height);
@@ -86,7 +97,6 @@ public virtual void Start ()
8697
NatCam.OnStart += OnStart;
8798
NatCam.OnFrame += OnFrame;
8899

89-
fpsMonitor = GetComponent<FpsMonitor> ();
90100
if (fpsMonitor != null){
91101
fpsMonitor.Add ("Name", "NatCamPreviewOnlyExample");
92102
fpsMonitor.Add ("onFrameFPS", onFrameFPS.ToString("F1"));

Assets/NatCamWithOpenCVForUnityExample/NatCamPreviewToMatExample/NatCamPreviewToMatExample.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public enum MatCaptureMethod
2323
NatCam_CaptureFrame,
2424
NatCam_CaptureFrame_OpenCVFlip,
2525
BlitWithReadPixels,
26-
OpenCVForUnity_LowLevelTextureToMat,
2726
Graphics_CopyTexture,
2827
}
2928

@@ -84,6 +83,17 @@ public enum ImageFlippingMethod
8483

8584
public virtual void Start ()
8685
{
86+
fpsMonitor = GetComponent<FpsMonitor> ();
87+
88+
if (!NatCam.Implementation.HasPermissions) {
89+
Debug.LogError ("NatCam.Implementation.HasPermissions == false");
90+
91+
if (fpsMonitor != null)
92+
fpsMonitor.consoleText = "NatCam.Implementation.HasPermissions == false";
93+
94+
return;
95+
}
96+
8797
// Load global camera benchmark settings.
8898
int width, height, fps;
8999
NatCamWithOpenCVForUnityExample.GetCameraResolution (out width, out height);
@@ -114,7 +124,6 @@ public virtual void Start ()
114124
NatCam.OnStart += OnStart;
115125
NatCam.OnFrame += OnFrame;
116126

117-
fpsMonitor = GetComponent<FpsMonitor> ();
118127
if (fpsMonitor != null){
119128
fpsMonitor.Add ("Name", "NatCamPreviewToMatExample");
120129
fpsMonitor.Add ("onFrameFPS", onFrameFPS.ToString("F1"));
@@ -146,7 +155,7 @@ public virtual void OnStart ()
146155
matrix = null;
147156
}
148157
matrix = matrix ?? new Mat(NatCam.Preview.height, NatCam.Preview.width, CvType.CV_8UC4);
149-
matrix.put(0, 0, pixelBuffer);
158+
Utils.copyToMat (pixelBuffer, matrix);
150159

151160
// Create display texture
152161
if (texture && (texture.width != matrix.cols() || texture.height != matrix.rows())) {
@@ -250,14 +259,14 @@ private Mat GetMat (MatCaptureMethod matCaptureMethod = MatCaptureMethod.NatCam_
250259
// Set `flip` flag to true because OpenCV uses inverted Y-coordinate system
251260
NatCam.CaptureFrame(pixelBuffer, true);
252261

253-
matrix.put(0, 0, pixelBuffer);
262+
Utils.copyToMat (pixelBuffer, matrix);
254263

255264
break;
256265
case MatCaptureMethod.NatCam_CaptureFrame_OpenCVFlip:
257266
// Get the preview data
258267
NatCam.CaptureFrame(pixelBuffer, false);
259268

260-
matrix.put(0, 0, pixelBuffer);
269+
Utils.copyToMat (pixelBuffer, matrix);
261270

262271
// OpenCV uses an inverted coordinate system. Y-0 is the top of the image, whereas in OpenGL (and so NatCam), Y-0 is the bottom of the image.
263272
Core.flip (matrix, matrix, 0);
@@ -271,27 +280,19 @@ private Mat GetMat (MatCaptureMethod matCaptureMethod = MatCaptureMethod.NatCam_
271280
// The texture2D's TextureFormat needs to be RGBA32(Unity5.5+), ARGB32, RGB24, RGBAFloat or RGBAHalf.
272281
Utils.textureToTexture2D (NatCam.Preview, texture);
273282

274-
matrix.put (0, 0, texture.GetRawTextureData ());
283+
Utils.copyToMat (texture.GetRawTextureData (), matrix);
275284

276285
// OpenCV uses an inverted coordinate system. Y-0 is the top of the image, whereas in OpenGL (and so NatCam), Y-0 is the bottom of the image.
277286
Core.flip (matrix, matrix, 0);
278287

279-
break;
280-
case MatCaptureMethod.OpenCVForUnity_LowLevelTextureToMat:
281-
282-
// When NatCam.PreviewMatrix function does not work properly. (Zenfone 2)
283-
// Converts OpenCV Mat to Unity Texture using low-level native plugin interface.
284-
// It seems that if enables the Multithreaded Rendering option in Android Player Settings, not work.
285-
Utils.textureToMat (NatCam.Preview, matrix);
286-
287288
break;
288289
case MatCaptureMethod.Graphics_CopyTexture:
289290

290291
// When NatCam.PreviewMatrix function does not work properly. (Zenfone 2)
291292
if (SystemInfo.copyTextureSupport != UnityEngine.Rendering.CopyTextureSupport.None) {
292293
Graphics.CopyTexture (NatCam.Preview, texture);
293294

294-
matrix.put (0, 0, texture.GetRawTextureData ());
295+
Utils.copyToMat (texture.GetRawTextureData (), matrix);
295296

296297
// OpenCV uses an inverted coordinate system. Y-0 is the top of the image, whereas in OpenGL (and so NatCam), Y-0 is the bottom of the image.
297298
Core.flip (matrix, matrix, 0);

Assets/NatCamWithOpenCVForUnityExample/NatCamPreviewToMatExample/NatCamPreviewToMatExample.unity

Lines changed: 6 additions & 6 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 &4
@@ -216,8 +218,6 @@ MonoBehaviour:
216218
m_Image: {fileID: 0}
217219
- m_Text: 'Cap: BlitWithReadPixels'
218220
m_Image: {fileID: 0}
219-
- m_Text: 'Cap: LowLevelTextureToMat'
220-
m_Image: {fileID: 0}
221221
- m_Text: 'Cap: CopyTexture'
222222
m_Image: {fileID: 0}
223223
m_OnValueChanged:

Assets/NatCamWithOpenCVForUnityExample/NatCamWithOpenCVForUnityExample.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace NatCamWithOpenCVForUnityExample
1111
{
1212
public class NatCamWithOpenCVForUnityExample : MonoBehaviour
1313
{
14+
public Text exampleTitle;
1415
public Text versionInfo;
1516
public ScrollRect scrollRect;
1617
static float verticalNormalizedPosition = 1f;
@@ -22,9 +23,16 @@ public class NatCamWithOpenCVForUnityExample : MonoBehaviour
2223
public Dropdown cameraFPSDropdown;
2324
static FPSPreset cameraFPS = FPSPreset._30;
2425

26+
void Awake () {
27+
QualitySettings.vSyncCount = 0;
28+
Application.targetFrameRate = 60;
29+
}
30+
2531
// Use this for initialization
2632
void Start ()
2733
{
34+
exampleTitle.text = "NatCamWithOpenCVForUnity Example " + Application.version;
35+
2836
versionInfo.text = OpenCVForUnity.Core.NATIVE_LIBRARY_NAME + " " + OpenCVForUnity.Utils.getVersion () + " (" + OpenCVForUnity.Core.VERSION + ")";
2937
versionInfo.text += " / UnityEditor " + Application.unityVersion;
3038
versionInfo.text += " / ";

Assets/NatCamWithOpenCVForUnityExample/NatCamWithOpenCVForUnityExample.unity

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ MonoBehaviour:
560560
m_HorizontalOverflow: 0
561561
m_VerticalOverflow: 0
562562
m_LineSpacing: 1
563-
m_Text: NatCamPreviewToMatHelper Examplee
563+
m_Text: NatCamPreviewToMatHelper Example
564564
--- !u!222 &265521585
565565
CanvasRenderer:
566566
m_ObjectHideFlags: 0
@@ -1998,6 +1998,7 @@ MonoBehaviour:
19981998
m_Script: {fileID: 11500000, guid: 3fc005588c60a0a4c827e3838c5f0e0d, type: 3}
19991999
m_Name:
20002000
m_EditorClassIdentifier:
2001+
exampleTitle: {fileID: 346089861}
20012002
versionInfo: {fileID: 595830809}
20022003
scrollRect: {fileID: 296877747}
20032004
cameraResolutionDropdown: {fileID: 453525395}
@@ -2527,8 +2528,8 @@ MonoBehaviour:
25272528
m_TargetGraphic: {fileID: 760072663}
25282529
m_HandleRect: {fileID: 760072662}
25292530
m_Direction: 2
2530-
m_Value: 0
2531-
m_Size: 1
2531+
m_Value: 1
2532+
m_Size: 0.79066855
25322533
m_NumberOfSteps: 0
25332534
m_OnValueChanged:
25342535
m_PersistentCalls:

Assets/NatCamWithOpenCVForUnityExample/Scripts/Utils/NatCamPreviewToMatHelper.cs

Lines changed: 11 additions & 2 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.0
12+
/// v 1.0.2
1313
/// Depends on NatCam version 2.0f1 or later.
1414
/// </summary>
1515
public class NatCamPreviewToMatHelper : WebCamTextureToMatHelper
@@ -89,6 +89,15 @@ public virtual void LateUpdate ()
8989
/// </summary>
9090
protected override IEnumerator _Initialize ()
9191
{
92+
if (!NatCam.Implementation.HasPermissions) {
93+
Debug.LogError ("NatCam.Implementation.HasPermissions == false");
94+
95+
if (onErrorOccurred != null)
96+
onErrorOccurred.Invoke (ErrorCode.CAMERA_DEVICE_NOT_EXIST);
97+
98+
yield break;
99+
}
100+
92101
if (hasInitDone)
93102
{
94103
ReleaseResources ();
@@ -284,7 +293,7 @@ public override Mat GetMat ()
284293

285294
// Set `flip` flag to true because OpenCV uses inverted Y-coordinate system
286295
NatCam.CaptureFrame(pixelBuffer, true);
287-
frameMat.put(0, 0, pixelBuffer);
296+
Utils.copyToMat (pixelBuffer, frameMat);
288297

289298
FlipMat (frameMat, flipVertical, flipHorizontal);
290299
if (rotatedFrameMat != null) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Unity >= 5.6.1f1
1414
* Scripting backend MONO / IL2CPP
1515
* NatCam - WebCam API 2.0f1 ([https://assetstore.unity.com/packages/tools/integration/natcam-pro-webcam-api-52154](https://assetstore.unity.com/packages/tools/integration/natcam-pro-webcam-api-52154))
16-
* NatShare-API 1.0 ([https://github.com/olokobayusuf/NatShare-API](https://github.com/olokobayusuf/NatShare-API))
16+
* NatShare - Mobile Sharing API 1.0f2 ([https://assetstore.unity.com/packages/tools/integration/natshare-mobile-sharing-api-117705](https://assetstore.unity.com/packages/tools/integration/natshare-mobile-sharing-api-117705))
1717
* OpenCV for Unity 2.2.8 ([https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088](https://assetstore.unity.com/packages/tools/integration/opencv-for-unity-21088))
1818

1919

0 commit comments

Comments
 (0)