Skip to content

Commit 4e8e86a

Browse files
committed
Add 2D tracker threading support.
1 parent b891f8a commit 4e8e86a

File tree

7 files changed

+53
-9
lines changed

7 files changed

+53
-9
lines changed

Release Notes.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# artoolkitX for Unity Release Notes
22
------------------------------------
33

4+
## Version 1.1.10
5+
### 2023-05-18
6+
7+
* Support for asynchronous tracking (on a secondary thread) has been added to the 2D tracker. When enabled, the tracking rate can run slower than the video capture frame rate. This results in increased smoothness of the display of video frames, at the expense of some memory usage and a possible lag on lower-powered devices between the displayed frame and the tracking results. It has been enabled by default, and can be adjusted using the control on ARController under "2D tracking options".
8+
49
## Version 1.1.9
510
### 2023-05-15
611

Source/Extras/artoolkitx

Submodule artoolkitx updated 51 files

Source/Package/Assets/artoolkitX-Unity/Scripts/ARController.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,12 @@ public struct ARVideoSourceInfoT
375375
private bool currentUseVideoBackground = true;
376376
[SerializeField]
377377
private bool currentNFTMultiMode = false;
378+
[Tooltip("The max. number of markers to track simultaneously. If fewer than this number are found, then detection will run each frame, as well as tracking for any detected markers.")]
378379
[SerializeField]
379380
private int currentTwoDMaxMarkersToTrack = 1;
381+
[Tooltip("If set, detection and tracking will run independently from frame capture and display on a separate thread.")]
382+
[SerializeField]
383+
private bool currentTwoDThreaded = true;
380384
[SerializeField]
381385
private AR_LOG_LEVEL currentLogLevel = AR_LOG_LEVEL.AR_LOG_LEVEL_INFO;
382386
[SerializeField]
@@ -775,6 +779,7 @@ public IEnumerator StartAR()
775779
ImageProcMode = currentImageProcMode;
776780
NFTMultiMode = currentNFTMultiMode;
777781
TwoDMaxMarkersToTrack = currentTwoDMaxMarkersToTrack;
782+
TwoDThreaded = currentTwoDThreaded;
778783
SquareMatrixModeAutocreateNewTrackables = currentSquareMatrixModeAutocreateNewTrackables;
779784
SquareMatrixModeAutocreateNewTrackablesDefaultWidth = currentSquareMatrixModeAutocreateNewTrackablesDefaultWidth;
780785

@@ -1300,6 +1305,27 @@ public bool NFTMultiMode
13001305
}
13011306
}
13021307

1308+
public bool TwoDThreaded
1309+
{
1310+
get
1311+
{
1312+
if (_running)
1313+
{
1314+
currentTwoDThreaded = PluginFunctions.arwGet2DThreaded();
1315+
}
1316+
return currentTwoDThreaded;
1317+
}
1318+
1319+
set
1320+
{
1321+
currentTwoDThreaded = value;
1322+
if (_running)
1323+
{
1324+
PluginFunctions.arwSet2DThreaded(currentTwoDThreaded);
1325+
}
1326+
}
1327+
}
1328+
13031329
public int TwoDMaxMarkersToTrack
13041330
{
13051331
get

Source/Package/Assets/artoolkitX-Unity/Scripts/Editor/ARControllerEditor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public class ARControllerEditor : Editor
6767
protected SerializedProperty ContentFlipH;
6868
protected SerializedProperty NearPlane;
6969
protected SerializedProperty FarPlane;
70+
protected SerializedProperty TwoDMaxMarkersToTrack;
71+
protected SerializedProperty TwoDThreaded;
7072

7173
private readonly static Dictionary<ARController.ARToolKitThresholdMode, string> thresholdModeDescriptions = new Dictionary<ARController.ARToolKitThresholdMode, string>
7274
{
@@ -92,6 +94,8 @@ protected virtual void OnEnable()
9294
ContentFlipH = serializedObject.FindProperty("ContentFlipH");
9395
NearPlane = serializedObject.FindProperty("NearPlane");
9496
FarPlane = serializedObject.FindProperty("FarPlane");
97+
TwoDMaxMarkersToTrack = serializedObject.FindProperty("currentTwoDMaxMarkersToTrack"); ;
98+
TwoDThreaded = serializedObject.FindProperty("currentTwoDThreaded"); ;
9599
}
96100

97101
public override void OnInspectorGUI()
@@ -299,12 +303,8 @@ public override void OnInspectorGUI()
299303
show2DTrackingOptions = EditorGUILayout.Foldout(show2DTrackingOptions, "2D Tracking Options");
300304
if (show2DTrackingOptions)
301305
{
302-
int n = EditorGUILayout.IntField("Max. number of markers to track", arcontroller.TwoDMaxMarkersToTrack);
303-
if (n != arcontroller.TwoDMaxMarkersToTrack)
304-
{
305-
Undo.RecordObject(arcontroller, "Set max. number of markers to track");
306-
arcontroller.TwoDMaxMarkersToTrack = n;
307-
}
306+
EditorGUILayout.PropertyField(TwoDMaxMarkersToTrack, new GUIContent("Max. number of markers to track"), null);
307+
EditorGUILayout.PropertyField(TwoDThreaded, new GUIContent("Threaded"), null);
308308
}
309309

310310
EditorGUILayout.Separator();

Source/Package/Assets/artoolkitX-Unity/Scripts/IPluginFunctions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public struct ARWTrackableStatus
8181
abstract public bool arwGetNFTMultiMode();
8282
abstract public void arwSet2DMaxMarkersToTrack(int maxMarkersToTrack);
8383
abstract public int arwGet2DMaxMarkersToTrack();
84+
abstract public bool arwGet2DThreaded();
85+
abstract public void arwSet2DThreaded(bool threaded);
8486
abstract public int arwGetPatternDetectionMode();
8587
abstract public bool arwGetProjectionMatrix(float nearPlane, float farPlane, float[] matrix);
8688
abstract public bool arwGetProjectionMatrixStereo(float nearPlane, float farPlane, float[] matrixL, float[] matrixR);

Source/Package/Assets/artoolkitX-Unity/Scripts/PluginFunctionsARX.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public class PluginFunctionsARX : IPluginFunctions
7373
/*ARW_TRACKER_OPTION_2D_TRACKER_FEATURE_TYPE = 11,*/ ///< Feature detector type used in the 2d Tracker - 0 AKAZE, 1 ORB, 2 BRISK, 3 KAZE
7474
ARW_TRACKER_OPTION_2D_MAXIMUM_MARKERS_TO_TRACK = 12, ///< Maximum number of markers able to be tracked simultaneously. Defaults to 1. Should not be set higher than the number of 2D markers loaded.
7575
ARW_TRACKER_OPTION_SQUARE_MATRIX_MODE_AUTOCREATE_NEW_TRACKABLES = 13, ///< If true, when the square tracker is detecting matrix (barcode) markers, new trackables will be created for unmatched markers. Defaults to false. bool.
76-
ARW_TRACKER_OPTION_SQUARE_MATRIX_MODE_AUTOCREATE_NEW_TRACKABLES_DEFAULT_WIDTH = 14; ///< If ARW_TRACKER_OPTION_SQUARE_MATRIX_MODE_AUTOCREATE_NEW_TRACKABLES is true, this value will be used for the initial width of new trackables for unmatched markers. Defaults to 80.0f. float.
76+
ARW_TRACKER_OPTION_SQUARE_MATRIX_MODE_AUTOCREATE_NEW_TRACKABLES_DEFAULT_WIDTH = 14, ///< If ARW_TRACKER_OPTION_SQUARE_MATRIX_MODE_AUTOCREATE_NEW_TRACKABLES is true, this value will be used for the initial width of new trackables for unmatched markers. Defaults to 80.0f. float.
77+
ARW_TRACKER_OPTION_2D_THREADED = 15; ///< bool, If false, 2D tracking updates synchronously, and arwUpdateAR will not return until 2D tracking is complete. If true, 2D tracking updates asychronously on a secondary thread, and arwUpdateAR will not block if the track is busy. Defaults to true.
7778

7879
override public bool IsConfigured()
7980
{
@@ -383,6 +384,16 @@ override public void arwSet2DMaxMarkersToTrack(int maxMarkersToTrack)
383384
ARX_pinvoke.arwSetTrackerOptionInt(ARW_TRACKER_OPTION_2D_MAXIMUM_MARKERS_TO_TRACK, maxMarkersToTrack);
384385
}
385386

387+
override public bool arwGet2DThreaded()
388+
{
389+
return ARX_pinvoke.arwGetTrackerOptionBool(ARW_TRACKER_OPTION_2D_THREADED);
390+
}
391+
392+
override public void arwSet2DThreaded(bool threaded)
393+
{
394+
ARX_pinvoke.arwSetTrackerOptionBool(ARW_TRACKER_OPTION_2D_THREADED, threaded);
395+
}
396+
386397
override public int arwGet2DMaxMarkersToTrack()
387398
{
388399
return ARX_pinvoke.arwGetTrackerOptionInt(ARW_TRACKER_OPTION_2D_MAXIMUM_MARKERS_TO_TRACK);

artoolkitx-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.8
1+
1.1.9

0 commit comments

Comments
 (0)