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?
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++;
...
}
@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;
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.