简体   繁体   English

如何计算找到的标记rajawali vuforia?

[英]How to count found markers rajawali vuforia?

I am trying to get the number of found markers on rajawali vuforia. 我正在尝试获取在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 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 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. 对于循环中每个帧中的每个当前检测到的标记,将调用foundFrameMarker In order to count found markers, you should add an int variable to your renderer for counting them. 为了计算找到的标记,您应该在渲染器中添加一个int变量以对其进行计数。 Reset it at the beginning of the render loop ( onRenderFrame ), and increment it inside foundFrameMarker : 在渲染循环( onRenderFrame )的开始处将其重置,并在foundFrameMarker内部将其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. @yakobom的答案解决了问题,但是它重复计数每帧,因此我添加了一些代码:我在onCreate(...)的活动类上初始化了另一个int以获取mMarkerCount达到的max计数,我添加了一个刷新每秒将其设置为TextFeild并重置最大值。

in the Activity class in the onCreate: 在onCreate的Activity类中:

    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;

    ...

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM