Skip to content

Commit 1431256

Browse files
committed
v1.0.3
Updated OpenCVForUnity version to 2.3.2. Updated NatCam version to 2.1f3. Updated NatShare version to 1.1f3.
1 parent d841873 commit 1431256

File tree

55 files changed

+10189
-5433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+10189
-5433
lines changed

.gitignore

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
Assets/OpenCVForUnity
2-
Assets/NatCam
3-
Assets/NatShare
4-
Assets/OpenCVForUnity.meta
5-
Assets/NatCam.meta
6-
Assets/NatShare.meta
7-
Library/
8-
Temp/
9-
.vs/
10-
.vscode/
11-
obj/
1+
.gitignore
2+
3+
/release

Assembly-CSharp-Editor.csproj

Lines changed: 0 additions & 391 deletions
This file was deleted.

Assembly-CSharp.csproj

Lines changed: 0 additions & 695 deletions
This file was deleted.

Assets/NatCamWithOpenCVForUnityExample/IntegrationWithNatShareExample/IntegrationWithNatShareExample.cs

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,57 @@
88
using NatCamU.Core;
99
using NatShareU;
1010

11-
namespace NatCamWithOpenCVForUnityExample {
11+
namespace NatCamWithOpenCVForUnityExample
12+
{
1213

1314
/// <summary>
1415
/// Integration With NatShare Example
1516
/// An example of the native sharing and save to the camera roll using NatShare.
1617
/// </summary>
17-
public class IntegrationWithNatShareExample : ExampleBase<NatCamSource> {
18+
public class IntegrationWithNatShareExample : ExampleBase<NatCamSource>
19+
{
20+
public Toggle applyComicFilterToggle;
1821

1922
Mat frameMatrix;
2023
Texture2D texture;
2124
ComicFilter comicFilter;
2225

23-
protected override void Start () {
26+
FpsMonitor fpsMonitor;
27+
28+
protected override void Start ()
29+
{
2430
// Load global camera benchmark settings.
2531
int width, height, framerate;
26-
NatCamWithOpenCVForUnityExample.CameraConfiguration(out width, out height, out framerate);
32+
NatCamWithOpenCVForUnityExample.CameraConfiguration (out width, out height, out framerate);
33+
NatCamWithOpenCVForUnityExample.ExampleSceneConfiguration (out performImageProcessingEachTime);
2734
// Create camera source
28-
cameraSource = new NatCamSource(width, height, framerate, useFrontCamera);
29-
cameraSource.StartPreview(OnStart, OnFrame);
35+
cameraSource = new NatCamSource (width, height, framerate, useFrontCamera);
36+
cameraSource.StartPreview (OnStart, OnFrame);
3037
// Create comic filter
3138
comicFilter = new ComicFilter ();
39+
40+
fpsMonitor = GetComponent<FpsMonitor> ();
41+
if (fpsMonitor != null) {
42+
fpsMonitor.Add ("Name", "IntegrationWithNatShareExample");
43+
fpsMonitor.Add ("performImageProcessingEveryTime", performImageProcessingEachTime.ToString ());
44+
fpsMonitor.Add ("onFrameFPS", onFrameFPS.ToString ("F1"));
45+
fpsMonitor.Add ("drawFPS", drawFPS.ToString ("F1"));
46+
fpsMonitor.Add ("width", "");
47+
fpsMonitor.Add ("height", "");
48+
fpsMonitor.Add ("orientation", "");
49+
}
3250
}
3351

34-
protected override void OnStart () {
52+
protected override void OnStart ()
53+
{
3554
// Create matrix
36-
frameMatrix = new Mat(cameraSource.height, cameraSource.width, CvType.CV_8UC4);
55+
if (frameMatrix != null)
56+
frameMatrix.Dispose ();
57+
frameMatrix = new Mat (cameraSource.height, cameraSource.width, CvType.CV_8UC4);
3758
// Create texture
38-
texture = new Texture2D(
59+
if (texture != null)
60+
Texture2D.Destroy (texture);
61+
texture = new Texture2D (
3962
cameraSource.width,
4063
cameraSource.height,
4164
TextureFormat.RGBA32,
@@ -45,20 +68,47 @@ protected override void OnStart () {
4568
// Display preview
4669
rawImage.texture = texture;
4770
aspectFitter.aspectRatio = NatCam.Preview.width / (float)NatCam.Preview.height;
48-
Debug.Log("NatCam camera source started with resolution: "+cameraSource.width+"x"+cameraSource.height);
71+
Debug.Log ("NatCam camera source started with resolution: " + cameraSource.width + "x" + cameraSource.height);
72+
73+
if (fpsMonitor != null) {
74+
fpsMonitor.Add ("width", cameraSource.width.ToString ());
75+
fpsMonitor.Add ("height", cameraSource.height.ToString ());
76+
fpsMonitor.Add ("orientation", Screen.orientation.ToString ());
77+
}
4978
}
5079

51-
protected override void OnFrame () {
52-
cameraSource.CaptureFrame(frameMatrix);
53-
comicFilter.Process(frameMatrix, frameMatrix);
54-
Imgproc.putText(frameMatrix, "[NatCam With OpenCVForUnity Example]", new Point (5, frameMatrix.rows () - 50), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar (255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
55-
Imgproc.putText(frameMatrix, "- Integration With NatShare Example", new Point (5, frameMatrix.rows () - 10), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar (255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
56-
Utils.fastMatToTexture2D(frameMatrix, texture, true, 0, false);
80+
protected override void Update ()
81+
{
82+
base.Update ();
83+
84+
if (updateCount == 0) {
85+
if (fpsMonitor != null) {
86+
fpsMonitor.Add ("onFrameFPS", onFrameFPS.ToString ("F1"));
87+
fpsMonitor.Add ("drawFPS", drawFPS.ToString ("F1"));
88+
fpsMonitor.Add ("orientation", Screen.orientation.ToString ());
89+
}
90+
}
5791
}
5892

59-
protected override void OnDestroy () {
60-
cameraSource.Dispose();
61-
cameraSource = null;
93+
protected override void UpdateTexture ()
94+
{
95+
cameraSource.CaptureFrame (frameMatrix);
96+
97+
if (applyComicFilterToggle.isOn)
98+
comicFilter.Process (frameMatrix, frameMatrix);
99+
100+
Imgproc.putText (frameMatrix, "[NatCam With OpenCVForUnity Example]", new Point (5, frameMatrix.rows () - 50), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar (255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
101+
Imgproc.putText (frameMatrix, "- Integration With NatShare Example", new Point (5, frameMatrix.rows () - 10), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar (255, 255, 255, 255), 2, Imgproc.LINE_AA, false);
102+
// Convert to Texture2D
103+
Utils.fastMatToTexture2D (frameMatrix, texture, true, 0, false);
104+
}
105+
106+
protected override void OnDestroy ()
107+
{
108+
if (cameraSource != null) {
109+
cameraSource.Dispose ();
110+
cameraSource = null;
111+
}
62112
if (frameMatrix != null)
63113
frameMatrix.Dispose ();
64114
frameMatrix = null;
@@ -67,5 +117,18 @@ protected override void OnDestroy () {
67117
comicFilter.Dispose ();
68118
comicFilter = null;
69119
}
120+
121+
public void OnShareButtonClick ()
122+
{
123+
NatShare.Share (texture,
124+
() => {
125+
Debug.Log ("sharing is complete.");
126+
});
127+
}
128+
129+
public void OnSaveToCameraRollButtonClick ()
130+
{
131+
NatShare.SaveToCameraRoll (texture, "NatCamWithOpenCVForUnityExample");
132+
}
70133
}
71134
}

0 commit comments

Comments
 (0)