Skip to content

Commit

Permalink
Add support for multi-marker tracking to 2D tracker.
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-lamb committed Mar 23, 2023
1 parent c70f0ce commit 8370a5b
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 241 deletions.
413 changes: 207 additions & 206 deletions Source/Package/Assets/artoolkitX-Unity/Example Scenes/2DScene.unity

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions Source/Package/Assets/artoolkitX-Unity/Scripts/ARController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ public struct ARVideoSourceInfoT
[SerializeField]
private bool currentNFTMultiMode = false;
[SerializeField]
private int currentTwoDMaxMarkersToTrack = 1;
[SerializeField]
private AR_LOG_LEVEL currentLogLevel = AR_LOG_LEVEL.AR_LOG_LEVEL_INFO;

// Main reference to the plugin functions. Created in OnEnable, destroyed in OnDisable().
Expand Down Expand Up @@ -771,6 +773,7 @@ public bool StartAR()
MatrixCodeType = currentMatrixCodeType;
ImageProcMode = currentImageProcMode;
NFTMultiMode = currentNFTMultiMode;
TwoDMaxMarkersToTrack = currentTwoDMaxMarkersToTrack;

// Prevent display sleep.
Screen.sleepTimeout = SleepTimeout.NeverSleep;
Expand Down Expand Up @@ -1299,6 +1302,27 @@ public bool NFTMultiMode
}
}

public int TwoDMaxMarkersToTrack
{
get
{
if (_running)
{
currentTwoDMaxMarkersToTrack = pluginFunctions.arwGet2DMaxMarkersToTrack();
}
return currentTwoDMaxMarkersToTrack;
}

set
{
currentTwoDMaxMarkersToTrack = value;
if (_running)
{
pluginFunctions.arwSet2DMaxMarkersToTrack(currentTwoDMaxMarkersToTrack);
}
}
}

public AR_LOG_LEVEL LogLevel
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ARControllerEditor : Editor
public bool showVideoOptions = true;
public bool showThresholdOptions = false;
public bool showSquareTrackingOptions = false;
public bool show2DTrackingOptions = false;
public bool showNFTTrackingOptions = false;
public bool showApplicationOptions = false;

Expand Down Expand Up @@ -124,51 +125,53 @@ public override void OnInspectorGUI()

EditorGUILayout.Separator();

showThresholdOptions = EditorGUILayout.Foldout(showThresholdOptions, "Threshold Options");
if (showThresholdOptions)
showSquareTrackingOptions = EditorGUILayout.Foldout(showSquareTrackingOptions, "Square Tracking Options");
if (showSquareTrackingOptions)
{
// Threshold mode selection
ARController.ARToolKitThresholdMode currentThreshMode = arcontroller.VideoThresholdMode;
ARController.ARToolKitThresholdMode newThreshMode = (ARController.ARToolKitThresholdMode)EditorGUILayout.EnumPopup("Mode:", currentThreshMode);
if (newThreshMode != currentThreshMode)
showThresholdOptions = EditorGUILayout.Foldout(showThresholdOptions, "Threshold Options");
if (showThresholdOptions)
{
arcontroller.VideoThresholdMode = newThreshMode;
}

// Info about the selected mode
EditorGUILayout.LabelField("", thresholdModeDescriptions[newThreshMode]);
// Threshold mode selection
ARController.ARToolKitThresholdMode currentThreshMode = arcontroller.VideoThresholdMode;
ARController.ARToolKitThresholdMode newThreshMode = (ARController.ARToolKitThresholdMode)EditorGUILayout.EnumPopup("Mode:", currentThreshMode);
if (newThreshMode != currentThreshMode)
{
Undo.RecordObject(arcontroller, "Set threshold mode");
arcontroller.VideoThresholdMode = newThreshMode;
}

// Show threshold slider only in manual or bracketing modes.
if (newThreshMode == ARController.ARToolKitThresholdMode.Manual || newThreshMode == ARController.ARToolKitThresholdMode.Bracketing)
{
// Info about the selected mode
EditorGUILayout.LabelField("", thresholdModeDescriptions[newThreshMode]);

int currentThreshold = arcontroller.VideoThreshold;
//int newThreshold = UnityEngine.Mathf.Clamp(EditorGUILayout.IntField("Threshold: ", currentThreshold), 0, 255);
int newThreshold = EditorGUILayout.IntSlider("Threshold: ", currentThreshold, 0, 255);
if (newThreshold != currentThreshold)
// Show threshold slider only in manual or bracketing modes.
if (newThreshMode == ARController.ARToolKitThresholdMode.Manual || newThreshMode == ARController.ARToolKitThresholdMode.Bracketing)
{
arcontroller.VideoThreshold = newThreshold;

int currentThreshold = arcontroller.VideoThreshold;
//int newThreshold = UnityEngine.Mathf.Clamp(EditorGUILayout.IntField("Threshold: ", currentThreshold), 0, 255);
int newThreshold = EditorGUILayout.IntSlider("Threshold: ", currentThreshold, 0, 255);
if (newThreshold != currentThreshold)
{
Undo.RecordObject(arcontroller, "Set threshold");
arcontroller.VideoThreshold = newThreshold;
}
}
}
}

EditorGUILayout.Separator();

showSquareTrackingOptions = EditorGUILayout.Foldout(showSquareTrackingOptions, "Square Tracking Options");
if (showSquareTrackingOptions)
{

EditorGUILayout.Separator();

int currentTemplateSize = arcontroller.TemplateSize;
int newTemplateSize = EditorGUILayout.IntField("Template size: ", currentTemplateSize);
if (newTemplateSize != currentTemplateSize && newTemplateSize >= 16 && newTemplateSize <= 64)
{
Undo.RecordObject(arcontroller, "Set template size");
arcontroller.TemplateSize = newTemplateSize;
}
int currentTemplateCountMax = arcontroller.TemplateCountMax;
int newTemplateCountMax = EditorGUILayout.IntField("Template count max.: ", currentTemplateCountMax);
if (newTemplateCountMax != currentTemplateCountMax && newTemplateCountMax > 0)
{
Undo.RecordObject(arcontroller, "Set template count max.");
arcontroller.TemplateCountMax = newTemplateCountMax;
}

Expand All @@ -177,6 +180,7 @@ public override void OnInspectorGUI()
ARController.ARToolKitLabelingMode newLabelingMode = (ARController.ARToolKitLabelingMode)EditorGUILayout.EnumPopup("Trackable borders:", currentLabelingMode);
if (newLabelingMode != currentLabelingMode)
{
Undo.RecordObject(arcontroller, "Set labeling mode");
arcontroller.LabelingMode = newLabelingMode;
}

Expand All @@ -185,6 +189,7 @@ public override void OnInspectorGUI()
float newBorderSize = UnityEngine.Mathf.Clamp(EditorGUILayout.FloatField("Border size:", currentBorderSize), 0.0f, 0.5f);
if (newBorderSize != currentBorderSize)
{
Undo.RecordObject(arcontroller, "Set border size");
arcontroller.BorderSize = newBorderSize;
}

Expand All @@ -193,6 +198,7 @@ public override void OnInspectorGUI()
ARController.ARToolKitPatternDetectionMode newPatternDetectionMode = (ARController.ARToolKitPatternDetectionMode)EditorGUILayout.EnumPopup("Pattern detection mode:", currentPatternDetectionMode);
if (newPatternDetectionMode != currentPatternDetectionMode)
{
Undo.RecordObject(arcontroller, "Set pattern detection mode");
arcontroller.PatternDetectionMode = newPatternDetectionMode;
}

Expand All @@ -206,6 +212,7 @@ public override void OnInspectorGUI()
ARController.ARToolKitMatrixCodeType newMatrixCodeType = (ARController.ARToolKitMatrixCodeType)EditorGUILayout.EnumPopup("Matrix code type:", currentMatrixCodeType);
if (newMatrixCodeType != currentMatrixCodeType)
{
Undo.RecordObject(arcontroller, "Set matrix code type");
arcontroller.MatrixCodeType = newMatrixCodeType;
}
}
Expand All @@ -215,17 +222,37 @@ public override void OnInspectorGUI()
ARController.ARToolKitImageProcMode newImageProcMode = (ARController.ARToolKitImageProcMode)EditorGUILayout.EnumPopup("Image processing mode:", currentImageProcMode);
if (newImageProcMode != currentImageProcMode)
{
Undo.RecordObject(arcontroller, "Set image processing mode");
arcontroller.ImageProcMode = newImageProcMode;
}

}

EditorGUILayout.Separator();

show2DTrackingOptions = EditorGUILayout.Foldout(show2DTrackingOptions, "2D Tracking Options");
if (show2DTrackingOptions)
{
int n = EditorGUILayout.IntField("Max. number of markers to track", arcontroller.TwoDMaxMarkersToTrack);
if (n != arcontroller.TwoDMaxMarkersToTrack)
{
Undo.RecordObject(arcontroller, "Set max. number of markers to track");
arcontroller.TwoDMaxMarkersToTrack = n;

}
}

EditorGUILayout.Separator();

showNFTTrackingOptions = EditorGUILayout.Foldout(showNFTTrackingOptions, "NFT Tracking Options");
if (showNFTTrackingOptions)
{
arcontroller.NFTMultiMode = EditorGUILayout.Toggle("Multi-page mode", arcontroller.NFTMultiMode);
bool m = EditorGUILayout.Toggle("Multi-page mode", arcontroller.NFTMultiMode);
if (m != arcontroller.NFTMultiMode)
{
Undo.RecordObject(arcontroller, "Set multi-page mode");
arcontroller.NFTMultiMode = m;
}
}

EditorGUILayout.Separator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public class ARToolKitMenuEditor : MonoBehaviour {
private const string SOURCE_URL = "https://github.com/artoolkitx/artoolkitx";
private const string PLUGIN_SOURCE_URL = "https://github.com/artoolkitx/arunityx";
//private const string TOOLS_URL = "http://artoolkit.org/download-artoolkit-sdk#unity";
private const string VERSION = MENU_PATH_BASE + "/artoolkitX for Unity Version 1.1.2";
private const string VERSION = MENU_PATH_BASE + "/artoolkitX for Unity Version 1.1.3";
private const string WINDOWS_UNITY_MESSAGE = "Thank you for choosing artoolkitX for Unity! " +
"<b>artoolkitX requires the Microsoft C++ Redistributables to be installed on your system.</b>\n" +
"Please select \"{0}\" from the menu above, and install the required packages.";
private const string GET_TOOLS_MESSAGE = "artoolkitX for Unity Version 1.1.2! <b>To make your own markers, you'll need to download our tools.</b>\n" +
private const string GET_TOOLS_MESSAGE = "artoolkitX for Unity Version 1.1.3! <b>To make your own markers, you'll need to download our tools.</b>\n" +
"Please select {0} from menu above to download them.";

static ARToolKitMenuEditor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public abstract class IPluginFunctions
abstract public bool arwGetTrackablePatternImage(int markerID, int patternID, [In, Out] Color[] colors);
abstract public int arwGetMatrixCodeType();
abstract public bool arwGetNFTMultiMode();
abstract public void arwSet2DMaxMarkersToTrack(int maxMarkersToTrack);
abstract public int arwGet2DMaxMarkersToTrack();
abstract public int arwGetPatternDetectionMode();
abstract public bool arwGetProjectionMatrix(float nearPlane, float farPlane, float[] matrix);
abstract public bool arwGetProjectionMatrixStereo(float nearPlane, float farPlane, float[] matrixL, float[] matrixR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class PluginFunctionsARX : IPluginFunctions
private PluginFunctionsLogCallback logCallback = null;
private GCHandle logCallbackGCH;

private static int ARW_TRACKER_OPTION_NFT_MULTIMODE = 0, ///< bool.
private readonly static int ARW_TRACKER_OPTION_NFT_MULTIMODE = 0, ///< bool.
ARW_TRACKER_OPTION_SQUARE_THRESHOLD = 1, ///< Threshold value used for image binarization. int in range [0-255].
ARW_TRACKER_OPTION_SQUARE_THRESHOLD_MODE = 2, ///< Threshold mode used for image binarization. int.
ARW_TRACKER_OPTION_SQUARE_LABELING_MODE = 3, ///< int.
Expand All @@ -67,8 +67,9 @@ public class PluginFunctionsARX : IPluginFunctions
ARW_TRACKER_OPTION_SQUARE_IMAGE_PROC_MODE = 7, ///< int.
ARW_TRACKER_OPTION_SQUARE_DEBUG_MODE = 8, ///< Enables or disable state of debug mode in the tracker. When enabled, a black and white debug image is generated during marker detection. The debug image is useful for visualising the binarization process and choosing a threshold value. bool.
ARW_TRACKER_OPTION_SQUARE_PATTERN_SIZE = 9, ///< Number of rows and columns in square template (pattern) markers. Defaults to AR_PATT_SIZE1, which is 16 in all versions of ARToolKit prior to 5.3. int.
ARW_TRACKER_OPTION_SQUARE_PATTERN_COUNT_MAX = 10/*, ///< Maximum number of square template (pattern) markers that may be loaded at once. Defaults to AR_PATT_NUM_MAX, which is at least 25 in all versions of ARToolKit prior to 5.3. int.
ARW_TRACKER_OPTION_2D_TRACKER_FEATURE_TYPE = 11*/; ///< Feature detector type used in the 2d Tracker - 0 AKAZE, 1 ORB, 2 BRISK, 3 KAZE
ARW_TRACKER_OPTION_SQUARE_PATTERN_COUNT_MAX = 10, ///< Maximum number of square template (pattern) markers that may be loaded at once. Defaults to AR_PATT_NUM_MAX, which is at least 25 in all versions of ARToolKit prior to 5.3. int.
/*ARW_TRACKER_OPTION_2D_TRACKER_FEATURE_TYPE = 11,*/ ///< Feature detector type used in the 2d Tracker - 0 AKAZE, 1 ORB, 2 BRISK, 3 KAZE
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.

override public bool IsConfigured()
{
Expand Down Expand Up @@ -363,6 +364,16 @@ override public bool arwGetNFTMultiMode()
return ARX_pinvoke.arwGetTrackerOptionBool(ARW_TRACKER_OPTION_NFT_MULTIMODE);
}

override public void arwSet2DMaxMarkersToTrack(int maxMarkersToTrack)
{
ARX_pinvoke.arwSetTrackerOptionInt(ARW_TRACKER_OPTION_2D_MAXIMUM_MARKERS_TO_TRACK, maxMarkersToTrack);
}

override public int arwGet2DMaxMarkersToTrack()
{
return ARX_pinvoke.arwGetTrackerOptionInt(ARW_TRACKER_OPTION_2D_MAXIMUM_MARKERS_TO_TRACK);
}

override public int arwAddTrackable(string cfg)
{
return ARX_pinvoke.arwAddTrackable(cfg);
Expand Down
2 changes: 1 addition & 1 deletion Source/Package/ProjectSettings/ProjectSettings.asset
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ PlayerSettings:
16:10: 1
16:9: 1
Others: 1
bundleVersion: 1.1.2
bundleVersion: 1.1.3
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
Expand Down
2 changes: 1 addition & 1 deletion artoolkitx-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.2
1.1.3

0 comments on commit 8370a5b

Please sign in to comment.