How to count found markers rajawali vuforia?

169 views Asked by At

I am trying to get the number of found markers on rajawali vuforia.

while we have the methods:

1- protected void foundFrameMarker(final int markerId, Vector3 position,Quaternion orientation) {} // this method is called when found any marker until the marker disappeared

2- public void noFrameMarkersFound() {} // this method is called when no markers appeared or found

How to use these methods to get count of found markers? Or is there another way to get the count?

2

There are 2 answers

0
yakobom On BEST ANSWER

foundFrameMarker is called for each currently detected marker in a loop, every frame. In order to count found markers, you should add an int variable to your renderer for counting them. Reset it at the beginning of the render loop (onRenderFrame), and increment it inside foundFrameMarker:

public void onRenderFrame(GL10 gl) {
   ... 
   mMarkerCount = 0;
   ...
 }

 protected void foundFrameMarker(int markerId, Vector3 position, Quaternion orientation) {
   mMarkerCount++;
   ...
 }
1
Mohammed Issa On

@yakobom answer's solved the problem but it repeats counting every frame so I added some code: I initialized another int to get the max count that mMarkerCount reachs, on the activity class in the onCreate(...) I added a timer that refresh every second to set it into a TextFeild and to reset the max.

in the Activity class in the onCreate:

    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                while (!isInterrupted()) {
                    Thread.sleep(1000);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            te.setText(mRenderer.max+"");
                            mRenderer.max=0;
                        }
                    });
                }
            } catch (InterruptedException e) {
            }
        }
    };

    t.start();

at the Renderer class:

protected void foundFrameMarker(int markerId, Vector3 position,
        Quaternion orientation) {

    ...

    mMarkerCount++;

    if (mMarkerCount > max)
        max = mMarkerCount;

    ...

}