Skip to content

Commit a1b80db

Browse files
author
satoo air
committed
Changed the name of asset project.("Sample" to "Example")
1 parent 9217d19 commit a1b80db

10 files changed

+109
-36
lines changed

Assets/KinectOpenCVForUnityExample.meta

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ColorFrameSample.cs renamed to Assets/KinectOpenCVForUnityExample/ColorFrameExample.cs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
using OpenCVForUnity;
66

7-
public class ColorFrameSample : MonoBehaviour
7+
public class ColorFrameExample : MonoBehaviour
88
{
99

1010
KinectSensor sensor;
1111
ColorFrameReader reader;
1212
Texture2D texture;
1313
byte[] data;
14-
1514
Mat rgbaMat;
1615

1716
public enum modeType
@@ -39,8 +38,6 @@ public enum modeType
3938
Mat comicDstMat;
4039
byte[] comicGrayPixels;
4140
byte[] comicMaskPixels;
42-
43-
4441

4542
void Start ()
4643
{
@@ -92,7 +89,11 @@ void Start ()
9289
//create a striped background.
9390
comicBgMat = new Mat (texture.height, texture.width, CvType.CV_8UC1, new Scalar (255));
9491
for (int i = 0; i < comicBgMat.rows ()*2.5f; i=i+4) {
92+
#if OPENCV_3
9593
Imgproc.line (comicBgMat, new Point (0, 0 + i), new Point (comicBgMat.cols (), -comicBgMat.cols () + i), new Scalar (0), 1);
94+
#else
95+
Core.line (comicBgMat, new Point (0, 0 + i), new Point (comicBgMat.cols (), -comicBgMat.cols () + i), new Scalar (0), 1);
96+
#endif
9697
}
9798

9899
comicDstMat = new Mat (texture.height, texture.width, CvType.CV_8UC1);
@@ -118,29 +119,37 @@ void Update ()
118119
frame = null;
119120

120121
}
121-
}else{
122+
} else {
122123
return;
123124
}
124125

125126
Utils.copyToMat (data, rgbaMat);
126127

127128

128129
if (mode == modeType.original) {
129-
130-
Imgproc.putText (rgbaMat, "ORIGINAL MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
131-
130+
#if OPENCV_3
131+
Imgproc.putText (rgbaMat, "ORIGINAL MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
132+
#else
133+
Core.putText (rgbaMat, "ORIGINAL MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
134+
#endif
132135
} else if (mode == modeType.sepia) {
133-
136+
134137
Core.transform (rgbaMat, rgbaMat, sepiaKernel);
135-
136-
Imgproc.putText (rgbaMat, "SEPIA MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
137138

139+
#if OPENCV_3
140+
Imgproc.putText (rgbaMat, "SEPIA MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
141+
#else
142+
Core.putText (rgbaMat, "SEPIA MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
143+
#endif
138144
} else if (mode == modeType.pixelize) {
139145
Imgproc.resize (rgbaMat, pixelizeIntermediateMat, pixelizeSize0, 0.1, 0.1, Imgproc.INTER_NEAREST);
140146
Imgproc.resize (pixelizeIntermediateMat, rgbaMat, rgbaMat.size (), 0.0, 0.0, Imgproc.INTER_NEAREST);
141-
142-
Imgproc.putText (rgbaMat, "PIXELIZE MODE" + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
143147

148+
#if OPENCV_3
149+
Imgproc.putText (rgbaMat, "PIXELIZE MODE" + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
150+
#else
151+
Core.putText (rgbaMat, "PIXELIZE MODE" + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
152+
#endif
144153
} else if (mode == modeType.comic) {
145154
Imgproc.cvtColor (rgbaMat, comicGrayMat, Imgproc.COLOR_RGBA2GRAY);
146155

@@ -189,8 +198,11 @@ void Update ()
189198

190199
Imgproc.cvtColor (comicDstMat, rgbaMat, Imgproc.COLOR_GRAY2RGBA);
191200

192-
Imgproc.putText (rgbaMat, "COMIC MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
193-
201+
#if OPENCV_3
202+
Imgproc.putText (rgbaMat, "COMIC MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
203+
#else
204+
Core.putText (rgbaMat, "COMIC MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
205+
#endif
194206
}
195207

196208
Utils.matToTexture (rgbaMat, texture);

Assets/KinectOpenCVForUnityExample/ColorFrameExample.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MultiSourceFrameSample.cs renamed to Assets/KinectOpenCVForUnityExample/MultiSourceFrameExample.cs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
using OpenCVForUnity;
66

7-
public class MultiSourceFrameSample : MonoBehaviour
7+
public class MultiSourceFrameExample : MonoBehaviour
88
{
99

1010
KinectSensor sensor;
@@ -46,8 +46,6 @@ public enum modeType
4646
byte[] comicGrayPixels;
4747
byte[] comicMaskPixels;
4848

49-
50-
5149
void Start ()
5250
{
5351
sensor = KinectSensor.GetDefault ();
@@ -109,7 +107,11 @@ void Start ()
109107
//create a striped background.
110108
comicBgMat = new Mat (texture.height, texture.width, CvType.CV_8UC1, new Scalar (255));
111109
for (int i = 0; i < comicBgMat.rows ()*2.5f; i=i+4) {
110+
#if OPENCV_3
112111
Imgproc.line (comicBgMat, new Point (0, 0 + i), new Point (comicBgMat.cols (), -comicBgMat.cols () + i), new Scalar (0), 1);
112+
#else
113+
Core.line (comicBgMat, new Point (0, 0 + i), new Point (comicBgMat.cols (), -comicBgMat.cols () + i), new Scalar (0), 1);
114+
#endif
113115
}
114116

115117
comicDstMat = new Mat (texture.height, texture.width, CvType.CV_8UC1);
@@ -149,7 +151,7 @@ void Update ()
149151

150152
frame = null;
151153
}
152-
}else{
154+
} else {
153155
return;
154156
}
155157

@@ -167,9 +169,7 @@ void Update ()
167169

168170
int index = x + y * width;
169171

170-
int tmp = ((int)depthSpacePoints [index].X + (int)depthSpacePoints [index].Y * depthWidth < 0) ? 0 : (int)depthSpacePoints [index].X + (int)depthSpacePoints [index].Y * depthWidth;
171-
172-
if (bodyIndexData [tmp] == 255) {
172+
if (bodyIndexData [(int)depthSpacePoints [index].X + (int)depthSpacePoints [index].Y * depthWidth] == 255) {
173173
maskData [index] = 0;
174174
} else {
175175
maskData [index] = 255;
@@ -182,25 +182,34 @@ void Update ()
182182
if (mode == modeType.original) {
183183

184184
rgbaMat.copyTo (outputMat, maskMat);
185-
186-
Imgproc.putText (outputMat, "ORIGINAL MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
187-
185+
186+
#if OPENCV_3
187+
Imgproc.putText (outputMat, "ORIGINAL MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
188+
#else
189+
Core.putText (outputMat, "ORIGINAL MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
190+
#endif
188191
} else if (mode == modeType.sepia) {
189192

190193
Core.transform (rgbaMat, rgbaMat, sepiaKernel);
191194

192195
rgbaMat.copyTo (outputMat, maskMat);
193-
194-
Imgproc.putText (outputMat, "SEPIA MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
195-
196+
197+
#if OPENCV_3
198+
Imgproc.putText (outputMat, "SEPIA MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
199+
#else
200+
Core.putText (outputMat, "SEPIA MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
201+
#endif
196202
} else if (mode == modeType.pixelize) {
197203
Imgproc.resize (rgbaMat, pixelizeIntermediateMat, pixelizeSize0, 0.1, 0.1, Imgproc.INTER_NEAREST);
198204
Imgproc.resize (pixelizeIntermediateMat, rgbaMat, rgbaMat.size (), 0.0, 0.0, Imgproc.INTER_NEAREST);
199205

200206
rgbaMat.copyTo (outputMat, maskMat);
201207

202-
Imgproc.putText (outputMat, "PIXELIZE MODE" + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
203-
208+
#if OPENCV_3
209+
Imgproc.putText (outputMat, "PIXELIZE MODE" + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
210+
#else
211+
Core.putText (outputMat, "PIXELIZE MODE" + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
212+
#endif
204213
} else if (mode == modeType.comic) {
205214
Imgproc.cvtColor (rgbaMat, comicGrayMat, Imgproc.COLOR_RGBA2GRAY);
206215

@@ -252,8 +261,11 @@ void Update ()
252261

253262
rgbaMat.copyTo (outputMat, maskMat);
254263

255-
Imgproc.putText (outputMat, "COMIC MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Imgproc.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
256-
264+
#if OPENCV_3
265+
Imgproc.putText (outputMat, "COMIC MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
266+
#else
267+
Core.putText (outputMat, "COMIC MODE " + texture.width + "x" + texture.height, new Point (5, texture.height - 5), Core.FONT_HERSHEY_PLAIN, 4.0, new Scalar (255, 0, 0, 255), 3);
268+
#endif
257269
}
258270

259271
Utils.matToTexture (outputMat, texture);

Assets/KinectOpenCVForUnityExample/MultiSourceFrameExample.cs.meta

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/KinectOpenCVForUnityExample/SampleMaterial.mat.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

KinectOpenCVForUnityExample.unity.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Kinect with OpenCV for Unity Sample
1+
Kinect with OpenCV for Unity Example
22
====================
33

44
Demo Video
@@ -17,12 +17,12 @@ Setup
1717
* Import OpenCVForUnity2.0.0 from AssetStore
1818

1919

20-
Samples
20+
Examples
2121
-----
22-
**[ColorFrameSample.cs](ColorFrameSample.cs)**
22+
**[ColorFrameExample.cs](/Assets/KinectOpenCVForUnityExample/ColorFrameExample.cs)**
2323
Converts ColorFrame acquired from "Kinect" to Mat of "OpenCV", perform image processing.
2424

25-
**[MultiSourceFrameSample.cs](MultiSourceFrameSample.cs)**
25+
**[MultiSourceFrameExample.cs](/Assets/KinectOpenCVForUnityExample/MultiSourceFrameExample.cs)**
2626
Converts BodyIndexFrame acquired from "Kinect" to Mat of "OpenCV", perform image processing only person.
2727

2828

0 commit comments

Comments
 (0)