簡體   English   中英

如何計算找到的標記rajawali vuforia?

[英]How to count found markers rajawali vuforia?

我正在嘗試獲取在rajawali vuforia上找到的標記的數量。

雖然我們有方法:

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

如何使用這些方法來計算發現的標記數? 還是有另一種方法來獲得計數?

對於循環中每個幀中的每個當前檢測到的標記,將調用foundFrameMarker 為了計算找到的標記,您應該在渲染器中添加一個int變量以對其進行計數。 在渲染循環( onRenderFrame )的開始處將其重置,並在foundFrameMarker內部將其foundFrameMarker

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

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

@yakobom的答案解決了問題,但是它重復計數每幀,因此我添加了一些代碼:我在onCreate(...)的活動類上初始化了另一個int以獲取mMarkerCount達到的max計數,我添加了一個刷新每秒將其設置為TextFeild並重置最大值。

在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();

在“渲染器”類中:

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