Log in or register to post comments

Markers >= 4 not recognized | Vuforia

November 21, 2012 - 7:21am #1

I am creating an Android application based on the FrameMarkers demo application. This works perfectly for markers 0 to 3. However, markers 4 to 511 are not recognized.

Something is wron...


 I have the following code: 

JNIEXPORT int JNICALL
Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_initTracker(JNIEnv *, jobject)
{

    LOG("Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_initTracker"); 

    // Initialize the marker tracker:
 

    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();

    QCAR::Tracker* trackerBase = trackerManager.initTracker(QCAR::Tracker::MARKER_TRACKER);

    QCAR::MarkerTracker* markerTracker = static_cast<QCAR::MarkerTracker*>(trackerBase); 
 

    if (markerTracker == NULL)
    {

        LOG("Failed to initialize MarkerTracker.");
        return 0;
    }
 

    LOG("Successfully initialized MarkerTracker.");
 

    for (int i = 0; i < 512; ++i)
    {
    char markerName[200];
    sprintf (markerName, "m%d", i);
 

    // Create frame markers:
    if (!markerTracker->createFrameMarker(i, markerName, QCAR::Vec2F(50,50)))
    {
 

        LOG("Failed to create frame markers.");

        return 0;
    }

        LOG("Successfully created frame markers.");
    }

    return 1;
}

 

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkersRenderer_renderFrame(JNIEnv *, jobject)
{

    //LOG("Java_com_qualcomm_QCARSamples_FrameMarkers_GLRenderer_renderFrame");
    // Clear color and depth buffer

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Get the state from QCAR and mark the beginning of a rendering section
 

    QCAR::State state = QCAR::Renderer::getInstance().begin();

    // Explicitly render the Video Background

    QCAR::Renderer::getInstance().drawVideoBackground();

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
 

    // Did we find any trackables this frame?

 

    //for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
 

    for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)

    {

        // Get the trackable:

        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);

        QCAR::Matrix44F modelViewMatrix =

            QCAR::Tool::convertPose2GLMatrix(trackable->getPose());
 

        // Choose the texture based on the target name:

        int textureIndex = 0;

        // Check the type of the trackable:

        assert(trackable->getType() == QCAR::Trackable::MARKER);

        const QCAR::Marker* marker = static_cast<const QCAR::Marker*>(trackable);

        textureIndex = marker->getMarkerId();

        assert(textureIndex < textureCount);

        const Texture* const thisTexture = textures[textureIndex];

        // Select which model to draw:

        const GLvoid* vertices = 0;

        const GLvoid* normals = 0;

        const GLvoid* indices = 0;

        const GLvoid* texCoords = 0;

        int numIndices = 0;

 

    int markerId = marker->getMarkerId();

 

        SampleUtils::checkGlError("FrameMarkers render frame");

    }

    glDisable(GL_DEPTH_TEST);

    glDisableVertexAttribArray(vertexHandle);

    glDisableVertexAttribArray(normalHandle);

    glDisableVertexAttribArray(textureCoordHandle);

    QCAR::Renderer::getInstance().end();

Markers >= 4 not recognized | Vuforia

January 14, 2014 - 10:56am #10

Go through the sample code and update any code that refers to the MarkerID 0-3, so to change that to detect different IDs. 

In particular, in FrameMarkerRenderer.java, adjust this code:

switch (marker.getMarkerId())
            {
                case 0:
                    vertices = qObject.getVertices();
                    normals = qObject.getNormals();
                    indices = qObject.getIndices();
                    texCoords = qObject.getTexCoords();
                    numIndices = qObject.getNumObjectIndex();
                    break;
                case 1:
                    vertices = cObject.getVertices();
                    normals = cObject.getNormals();
                    indices = cObject.getIndices();
                    texCoords = cObject.getTexCoords();
                    numIndices = cObject.getNumObjectIndex();
                    break;
                case 2:
                    vertices = aObject.getVertices();
                    normals = aObject.getNormals();
                    indices = aObject.getIndices();
                    texCoords = aObject.getTexCoords();
                    numIndices = aObject.getNumObjectIndex();
                    break;
                default:
                    vertices = rObject.getVertices();
                    normals = rObject.getNormals();
                    indices = rObject.getIndices();
                    texCoords = rObject.getTexCoords();
                    numIndices = rObject.getNumObjectIndex();
                    break;
            }
            
So that it handles your marker ID.
 

 

Markers >= 4 not recognized | Vuforia

January 14, 2014 - 10:43am #9

I am editing Frame marker sample because i want to prove a diferent markerID like framemarker_005, 007, etc. But this sample only detect frame marker 0-3. I have edited loadTextures() method, doLoadTrackersData() method in FrameMarker.java  adding my framemarker to tested and i have change switch cases in FrameMarkerRenderer.java. But when i run the app in my smartphone, the new framemarker haven't been detected. why???

How can i edit that files to prove the app with Markers>=4????

 

Thanks!!

Markers >= 4 not recognized | Vuforia

October 27, 2013 - 9:55am #8

make sure to also update the rendering code in the renderFrame() function...

 

Markers >= 4 not recognized | Vuforia

October 26, 2013 - 10:27am #7
Could someone please tell me why my application keep freezing whenever I hover my smartphone over a marker frame with ID 4, although had already implemented the loop as mentioned? Did I missed out anything?
 
 
==============================
JNIEXPORT int JNICALL
Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_initTracker(JNIEnv *, jobject)
{
    LOG("Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_initTracker");
    
    // Initialize the marker tracker:
    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
    QCAR::Tracker* trackerBase = trackerManager.initTracker(QCAR::Tracker::MARKER_TRACKER);
    QCAR::MarkerTracker* markerTracker = static_cast<QCAR::MarkerTracker*>(trackerBase);
 
    if (markerTracker == NULL)
    {
        LOG("Failed to initialize MarkerTracker.");
        return 0;
    }
 
    for(int i = 0; i<512; i++)
    {
      char markerName[200];
      sprintf (markerName, "m%d", i);
 
      if (!markerTracker->createFrameMarker(i, markerName, QCAR::Vec2F(50,50)))
      {
      LOG("Failed to create frame markers.");
      return 0;
      }
 
    }
 
 
    LOG("Successfully initialized MarkerTracker.");
 
    return 1;
}
 
 
Thank you

Markers >= 4 not recognized | Vuforia

November 26, 2012 - 9:37am #6

On Android you can do the same with this code (which I already posted few posts ago in this same thread);

note that the renderFrame function willl also need to be updated to use more then the first Q C A R letters.

for (int i = 0; i < 512; ++i)
{
char markerName[200];
sprintf (markerName, "m%d", i);

// Create frame markers:
if (!markerTracker->createFrameMarker(i, markerName, QCAR::Vec2F(50,50)))
{

LOG("Failed to create frame markers.");

return 0;
}

LOG("Successfully created frame markers.");
}

Markers >= 4 not recognized | Vuforia

November 26, 2012 - 8:32am #5

I had the same problem.

On iOS go to initTracker method in QCARutils.mm and add as createFrameMarker() calls as needed with the appropriate ids.

Hope this works for you. 

 

David

 

Markers >= 4 not recognized | Vuforia

November 21, 2012 - 5:34pm #4

Are you using the FrameMarkers sample? If so, that sample is only designed to augment those four markers (0-3) with the letters Q.C.A.R. 

Try logging to marker id to confirm whether you are detecting markers w/ values > 3.

Markers >= 4 not recognized | Vuforia

November 21, 2012 - 10:09am #3

With the following code will still not work

// Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumActiveTrackables(); tIdx++)
    {
        // Get the trackable:
        const QCAR::Trackable* trackable = state.getActiveTrackable(tIdx);
        QCAR::Matrix44F modelViewMatrix =
            QCAR::Tool::convertPose2GLMatrix(trackable->getPose());       
     
        // Choose the texture based on the target name:
        int textureIndex = 0;
       
        // Check the type of the trackable:
        assert(trackable->getType() == QCAR::Trackable::MARKER);
        const QCAR::Marker* marker = static_cast<const QCAR::Marker*>(trackable);

        textureIndex = marker->getMarkerId();
       
        assert(textureIndex < textureCount);
        const Texture* const thisTexture = textures[textureIndex];

        // Select which model to draw:
        const GLvoid* vertices = 0;
        const GLvoid* normals = 0;
        const GLvoid* indices = 0;
        const GLvoid* texCoords = 0;
        int numIndices = 0;   
        int markerId = marker->getMarkerId();   

        QCAR::Matrix44F modelViewProjection;

        SampleUtils::translatePoseMatrix(-kLetterTranslate,
                                         -kLetterTranslate,
                                         0.f,
                                         &modelViewMatrix.data[0]);
        SampleUtils::scalePoseMatrix(kLetterScale, kLetterScale, kLetterScale,
                                     &modelViewMatrix.data[0]);
        SampleUtils::multiplyMatrix(&projectionMatrix.data[0],
                                    &modelViewMatrix.data[0],
                                    &modelViewProjection.data[0]);

        glUseProgram(shaderProgramID);
 
        glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, vertices);
        glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, normals);
        glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE,
                              0, texCoords);

        glEnableVertexAttribArray(vertexHandle);
        glEnableVertexAttribArray(normalHandle);
        glEnableVertexAttribArray(textureCoordHandle);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, thisTexture->mTextureID);
        glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
                           (GLfloat*)&modelViewProjection.data[0]);
        glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, indices);

        SampleUtils::checkGlError("FrameMarkers render frame");
    }   
   
    glDisable(GL_DEPTH_TEST);
    glDisableVertexAttribArray(vertexHandle);
    glDisableVertexAttribArray(normalHandle);
    glDisableVertexAttribArray(textureCoordHandle);

    QCAR::Renderer::getInstance().end();   

Markers >= 4 not recognized | Vuforia

November 21, 2012 - 7:36am #2

Hi, maybe you forgot to paste some of the rendering code (I cannot see any glVertexAttribPointer() function call);

Log in or register to post comments