Android ARToolkit - Marker Position

I am using ARToolkit for Android and am trying to write text over the marker it detected. I want to do this using a simple TextView. So I am using ARToolkit to find the marker.

But how can I find out where in my camera preview the marker is not right (I need coordinates), so that I can, but the TextView is above the marker?

Thanks in advance!

+3


source to share


2 answers


Both comments are correct, ARToolkit returns both projection matrix and transformation matrix. Both are intended to be used with OpenGL and not the standard Android view. The projection matrix must be applied to the camera and the transform must be applied to the object (pose matrix)

If you want to display text, I recommend that you use the Unity plugin and then use the Unity UI components to add a canvas and text attached to a marker. These components are already designed for 3D objects (if you go this way, be sure to set the canvas to "World Space".

Other options you have:



a) Extract the text into a texture and draw it on a Quad, you can do that with the cube example.

b) Do some matrix calculations using both matrix and applied transformations in the TextView on position and rotation using transformation matrix (Android class). While possible, the math involved is quite complex. If you want it to just float while looking at the camera, setTranslationX, Y and Z should be enough.

c) Link the 3D engine with the text-renderer in ARToolkit. I did it with jPCT-AE. While this works, it takes quite a bit of work. I will write about it soon.

+3


source


There is one more option for defining the corner points of the markers. This will require some changes to the shell code and recompilation of the Android binaries.

Paste or clone the goolub artoolkit5 repository and make the following changes:

Add entry to ARMarker.h

float cornerPoints[8];

      

In ARMarkerSquare.cpp, make changes to the updateWithDetectedMarkers method right after the code in which the marker was declared visible, update the corner points:

// Consider marker visible if a match was found.
    if (k != -1) {
        visible = true;
        m_cf = markerInfo[k].cf;
        for (int c = 0; c < 4; c++) {
            cornerPoints[c*2] = markerInfo[k].vertex[c][0];
            cornerPoints[c*2 + 1] = markerInfo[k].vertex[c][1];
        }

      

Add a new ARToolKitWrapperExportedAPI.cpp method to extract corner points:

EXPORT_API bool arwQueryMarkerCornerPoints(int markerUID, float points[8])
{
 ARMarker *marker;

if (!gARTK) return false;
if (!(marker = gARTK->findMarker(markerUID))) {
    gARTK->logv(AR_LOG_LEVEL_ERROR, "arwQueryMarkerCornerPoints(): Couldn't locate marker with UID %d.", markerUID);
    return false;
}
for (int i = 0; i < 8; i++) points[i] = (float)marker->cornerPoints[i];
return marker->visible;

      

}

And add a JNI definition for this:



JNIEXPORT jfloatArray JNICALL JNIFUNCTION(arwQueryMarkerCornerPoints(JNIEnv *env, jobject obj, jint markerUID))
{
float trans[8];

if (arwQueryMarkerCornerPoints(markerUID, trans)) return glArrayToJava(env, trans, 8);
return NULL;

      

}

After all this, I recompile the ARWrapper shared objects in the android directory using the build.sh script and used these new shared objects.

In it NativeInterface.java add the following method:

/**
 * Retrieves the corner points for the specified marker
 *
 * @param markerUID The unique identifier (UID) of the marker to check
 * @return A float array of size 8 containing the corner points starting at top left (x,y) top right, bottom right, bottom left.
 * So
 */
public static native float[] arwQueryMarkerCornerPoints(int markerUID);

      

Finally, add a method to ARToolKit.java:

/**
 * Retrieves the corner points for the specified marker
 *
 * @param markerUID The unique identifier (UID) of the marker to check
 * @return A float array of size 8 containing the corner points starting at top left (x,y) top right, bottom right, bottom left.
 *
 */
public float[] arwQueryMarkerCornerPoints(int markerUID) {
    if (!initedNative) return null;
    return NativeInterface.arwQueryMarkerCornerPoints(markerUID);
}

      

See also:

https://archive.artoolkit.org/community/forums/viewtopic.php?f=26&t=16099

The changes can be seen in this fork too: https://github.com/ekkelenkamp/artoolkit5/tree/marker_corner_points

+1


source







All Articles