Skip to content

Commit cdb994b

Browse files
committed
update 2.5.9
1 parent 9248458 commit cdb994b

29 files changed

+1796
-114
lines changed

Assets/OpenCVForUnity/Examples/Advanced/AlphaBlendingExample/AlphaBlendingExample.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ namespace OpenCVForUnityExample
4141
/// You need to add a file "smcs.rsp" (or "gmcs.rsp") in your "Assets" directory, which contains the line: -unsafe
4242
/// https://answers.unity.com/questions/804103/how-to-enable-unsafe-and-use-pointers.html
4343
///
44-
/// To use this example, need to add "OPENCV_USE_UNSAFE_CODE" to Scripting Define Symbols in Player Settings.
4544
///
4645
/// ######
4746
/// </summary>
@@ -516,7 +515,7 @@ private void AlphaBlend_Marshal(Mat fg, Mat bg, Mat alpha, Mat dst)
516515
private void AlphaBlend_pointerAccess(Mat fg, Mat bg, Mat alpha, Mat dst)
517516
{
518517

519-
#if OPENCV_USE_UNSAFE_CODE
518+
#if !OPENCV_DONT_USE_UNSAFE_CODE
520519

521520
IntPtr fg_ptr = new IntPtr(fg.dataAddr());
522521
IntPtr bg_ptr = new IntPtr(bg.dataAddr());
@@ -678,10 +677,10 @@ public void OnMarshalButtonClick()
678677
/// </summary>
679678
public void OnPointerAccessButtonClick()
680679
{
681-
#if OPENCV_USE_UNSAFE_CODE
680+
#if !OPENCV_DONT_USE_UNSAFE_CODE
682681
StartCoroutine(AlphaBlending(pointerAccess, count));
683682
#else
684-
Debug.LogWarning("To use this example, need to add \"OPENCV_USE_UNSAFE_CODE\" to Scripting Define Symbols in Player Settings. In addition, unsafe code requires the `unsafe' command-line option to be specified.");
683+
Debug.LogWarning("Error : Allow 'unsafe' Code is disable. Please enable Allow 'unsafe' Code. [MenuItem]->[Tools]->[OpenCV for Unity]->[Open Setup Tools]->[Enable Use Unsafe Code]");
685684
#endif
686685
}
687686
}

Assets/OpenCVForUnity/Examples/Advanced/ComicFilterExample/ComicFilter.cs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using OpenCVForUnity.CoreModule;
22
using OpenCVForUnity.ImgprocModule;
3+
using OpenCVForUnity.UnityUtils;
34
using OpenCVForUnity.UtilsModule;
45
using System;
56

Assets/OpenCVForUnity/Examples/Basic/MatBasicProcessingExample/MatBasicProcessingExample.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,7 @@ public void OnAccessingPixelValueExampleButtonClick()
21312131
executionResultText.text += "3. Use MatUtils.copyFromMat and MatUtils.copyToMat method. time: " + watch.ElapsedMilliseconds + " ms" + "\n";
21322132

21332133

2134-
#if OPENCV_USE_UNSAFE_CODE
2134+
#if !OPENCV_DONT_USE_UNSAFE_CODE
21352135

21362136
//
21372137
// 4. Use pointer access.
@@ -2284,7 +2284,7 @@ public void OnAccessingPixelValueExampleButtonClick()
22842284
Debug.Log(""3. Use MatUtils.copyFromMat and MatUtils.copyToMat method. time: "" + watch.ElapsedMilliseconds + "" ms"");
22852285
22862286
2287-
#if OPENCV_USE_UNSAFE_CODE
2287+
#if !OPENCV_DONT_USE_UNSAFE_CODE
22882288
22892289
//
22902290
// 4. Use pointer access.

Assets/OpenCVForUnity/Examples/MainModules/dnn/FaceDetectionYuNetV2Example/YuNetV2FaceDetector.cs

+18-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using OpenCVForUnity.DnnModule;
55
using OpenCVForUnity.ImgprocModule;
66
using OpenCVForUnity.ObjdetectModule;
7+
using OpenCVForUnity.UnityUtils;
78
using System;
89
using System.Linq;
910
using System.Runtime.InteropServices;
@@ -138,7 +139,7 @@ public virtual void visualize(Mat image, Mat results, bool print_results = false
138139

139140
Imgproc.rectangle(image, new Point(left, top), new Point(right, bottom), bbcolor, 2);
140141

141-
string label = String.Format("{0:0.0000}", score);
142+
string label = score.ToString("F4");
142143
int[] baseLine = new int[1];
143144
Size labelSize = Imgproc.getTextSize(label, Imgproc.FONT_HERSHEY_SIMPLEX, 0.5, 1, baseLine);
144145

@@ -163,7 +164,7 @@ public virtual void visualize(Mat image, Mat results, bool print_results = false
163164
// Print results
164165
if (print_results)
165166
{
166-
StringBuilder sb = new StringBuilder();
167+
StringBuilder sb = new StringBuilder(128);
167168

168169
for (int i = 0; i < data.Length; ++i)
169170
{
@@ -174,20 +175,22 @@ public virtual void visualize(Mat image, Mat results, bool print_results = false
174175
float bottom = d.xy.y + d.wh.y;
175176
float score = d.score;
176177

177-
sb.AppendLine(String.Format("-----------face {0}-----------", i + 1));
178-
sb.AppendLine(String.Format("score: {0:0.0000}", score));
179-
sb.AppendLine(String.Format("box: {0:0} {1:0} {2:0} {3:0}", left, top, right, bottom));
178+
sb.AppendFormat("-----------face {0}-----------", i + 1);
179+
sb.AppendLine();
180+
sb.AppendFormat("score: {0:F4}", score);
181+
sb.AppendLine();
182+
sb.AppendFormat("box: {0:F0} {1:F0} {2:F0} {3:F0}", left, top, right, bottom);
183+
sb.AppendLine();
180184
sb.Append("landmarks: ");
181-
sb.Append(String.Format("{0:0} {1:0} ", d.rightEye.x, d.rightEye.y));
182-
sb.Append(String.Format("{0:0} {1:0} ", d.leftEye.x, d.leftEye.y));
183-
sb.Append(String.Format("{0:0} {1:0} ", d.nose.x, d.nose.y));
184-
sb.Append(String.Format("{0:0} {1:0} ", d.rightMouth.x, d.rightMouth.y));
185-
sb.Append(String.Format("{0:0} {1:0} ", d.leftMouth.x, d.leftMouth.y));
186-
185+
sb.AppendFormat("{0:F0} {1:F0} ", d.rightEye.x, d.rightEye.y);
186+
sb.AppendFormat("{0:F0} {1:F0} ", d.leftEye.x, d.leftEye.y);
187+
sb.AppendFormat("{0:F0} {1:F0} ", d.nose.x, d.nose.y);
188+
sb.AppendFormat("{0:F0} {1:F0} ", d.rightMouth.x, d.rightMouth.y);
189+
sb.AppendFormat("{0:F0} {1:F0} ", d.leftMouth.x, d.leftMouth.y);
187190
sb.AppendLine();
188191
}
189192

190-
Debug.Log(sb);
193+
Debug.Log(sb.ToString());
191194
}
192195
}
193196

@@ -236,7 +239,8 @@ public DetectionData(Vector2 xy, Vector2 wh, Vector2 rightEye, Vector2 leftEye,
236239

237240
public override string ToString()
238241
{
239-
return "xy:" + xy + " wh:" + wh + " rightEye:" + rightEye + " leftEye:" + leftEye + " nose:" + nose + " rightMouth:" + rightMouth + " leftMouth:" + leftMouth + " score:" + score;
242+
return "xy:" + xy.ToString() + " wh:" + wh.ToString() + " rightEye:" + rightEye.ToString() + " leftEye:" + leftEye.ToString()
243+
+ " nose:" + nose.ToString() + " rightMouth:" + rightMouth.ToString() + " leftMouth:" + leftMouth.ToString() + " score:" + score.ToString();
240244
}
241245
};
242246

@@ -246,7 +250,7 @@ public virtual DetectionData[] getData(Mat results)
246250
return new DetectionData[0];
247251

248252
var dst = new DetectionData[results.rows()];
249-
OpenCVForUnity.UtilsModule.MatUtils.copyFromMat(results, dst);
253+
MatUtils.copyFromMat(results, dst);
250254

251255
return dst;
252256
}

Assets/OpenCVForUnity/Examples/MainModules/dnn/FacialExpressionRecognitionExample/FacialExpressionRecognizer.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using OpenCVForUnity.DnnModule;
55
using OpenCVForUnity.ImgprocModule;
66
using OpenCVForUnity.ObjdetectModule;
7+
using OpenCVForUnity.UnityUtils;
78
using System;
89
using System.Collections.Generic;
910
using System.Linq;
@@ -172,7 +173,7 @@ public virtual void visualize(Mat image, List<Mat> results, Mat faces, bool prin
172173
StringBuilder sb = null;
173174

174175
if (print_results)
175-
sb = new StringBuilder();
176+
sb = new StringBuilder(64);
176177

177178
for (int i = 0; i < results.Count; ++i)
178179
{
@@ -186,7 +187,7 @@ public virtual void visualize(Mat image, List<Mat> results, Mat faces, bool prin
186187

187188
ClassificationData bmData = getBestMatchData(results[i]);
188189
int classId = (int)bmData.cls;
189-
string label = getClassLabel(bmData.cls) + ", " + String.Format("{0:0.0000}", bmData.conf);
190+
string label = $"{getClassLabel(bmData.cls)}, {bmData.conf:F4}";
190191

191192
Scalar c = palette[classId % palette.Count];
192193
Scalar color = isRGB ? c : new Scalar(c.val[2], c.val[1], c.val[0], c.val[3]);
@@ -206,13 +207,15 @@ public virtual void visualize(Mat image, List<Mat> results, Mat faces, bool prin
206207
// Print results
207208
if (print_results)
208209
{
209-
sb.AppendLine(String.Format("-----------expression {0}-----------", i + 1));
210-
sb.AppendLine(String.Format("Best match: " + getClassLabel(bmData.cls) + ", " + bmData));
210+
sb.AppendFormat("-----------expression {0}-----------", i + 1);
211+
sb.AppendLine();
212+
sb.Append("Best match: ").Append(getClassLabel(bmData.cls)).Append(", ").Append(bmData.ToString());
213+
sb.AppendLine();
211214
}
212215
}
213216

214217
if (print_results)
215-
Debug.Log(sb);
218+
Debug.Log(sb.ToString());
216219
}
217220

218221
public virtual void dispose()
@@ -258,7 +261,7 @@ public ClassificationData(int cls, float conf)
258261

259262
public override string ToString()
260263
{
261-
return "cls:" + cls + " conf:" + conf;
264+
return "cls:" + cls.ToString() + " conf:" + conf.ToString();
262265
}
263266
};
264267

@@ -280,7 +283,7 @@ public virtual ClassificationData[] getData(Mat results)
280283
results_numx1.copyTo(getDataMat.col(1));
281284

282285
var dst = new ClassificationData[num];
283-
OpenCVForUnity.UtilsModule.MatUtils.copyFromMat(getDataMat, dst);
286+
MatUtils.copyFromMat(getDataMat, dst);
284287

285288
return dst;
286289
}

Assets/OpenCVForUnity/Examples/MainModules/dnn/HandPoseEstimationMediaPipeExample/HandPoseEstimationMediaPipeExample.cs

+38
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Collections.Generic;
1212
using UnityEngine;
1313
using UnityEngine.SceneManagement;
14+
using UnityEngine.UI;
1415

1516
namespace OpenCVForUnityExample
1617
{
@@ -22,6 +23,15 @@ namespace OpenCVForUnityExample
2223
[RequireComponent(typeof(WebCamTextureToMatHelper))]
2324
public class HandPoseEstimationMediaPipeExample : MonoBehaviour
2425
{
26+
/// <summary>
27+
/// The show Skeleton toggle.
28+
/// </summary>
29+
public Toggle showSkeletonToggle;
30+
31+
public bool showSkeleton;
32+
33+
public MediaPipeHandPoseSkeletonVisualizer skeletonVisualizer;
34+
2535
[Header("TEST")]
2636

2737
[TooltipAttribute("Path to test input image.")]
@@ -90,6 +100,9 @@ void Start()
90100

91101
webCamTextureToMatHelper = gameObject.GetComponent<WebCamTextureToMatHelper>();
92102

103+
// Update GUI state
104+
showSkeletonToggle.isOn = showSkeleton;
105+
93106
#if UNITY_WEBGL
94107
getFilePath_Coroutine = GetFilePath();
95108
StartCoroutine(getFilePath_Coroutine);
@@ -203,6 +216,12 @@ void Run()
203216

204217
foreach (var hand in hands)
205218
handPoseEstimator.visualize(img, hand, true, false);
219+
220+
if (skeletonVisualizer != null && skeletonVisualizer.showSkeleton)
221+
{
222+
if (hands.Count > 0 && !hands[0].empty())
223+
skeletonVisualizer.UpdatePose(hands[0]);
224+
}
206225
}
207226

208227
gameObject.transform.localScale = new Vector3(img.width(), img.height(), 1);
@@ -349,6 +368,13 @@ void Update()
349368

350369
foreach (var hand in hands)
351370
handPoseEstimator.visualize(rgbaMat, hand, false, true);
371+
372+
373+
if (skeletonVisualizer != null && skeletonVisualizer.showSkeleton)
374+
{
375+
if (hands.Count > 0 && !hands[0].empty())
376+
skeletonVisualizer.UpdatePose(hands[0]);
377+
}
352378
}
353379

354380
Utils.matToTexture2D(rgbaMat, texture);
@@ -420,6 +446,18 @@ public void OnChangeCameraButtonClick()
420446
{
421447
webCamTextureToMatHelper.requestedIsFrontFacing = !webCamTextureToMatHelper.requestedIsFrontFacing;
422448
}
449+
450+
/// <summary>
451+
/// Raises the show skeleton toggle value changed event.
452+
/// </summary>
453+
public void OnShowSkeletonToggleValueChanged()
454+
{
455+
if (showSkeletonToggle.isOn != showSkeleton)
456+
{
457+
showSkeleton = showSkeletonToggle.isOn;
458+
skeletonVisualizer.showSkeleton = showSkeletonToggle.isOn;
459+
}
460+
}
423461
}
424462
}
425463

0 commit comments

Comments
 (0)