Log in or register to post comments

How to measure time duration?

March 17, 2013 - 4:51am #1

Hi,

I am working ImageTargets AR. I want to measure time duration between target appeared in camera preview and target identified. I want to know the methods fired during these two events?

Please help

Thanks in advance

How to measure time duration?

April 3, 2013 - 8:43am #12

You're welcome.

How to measure time duration?

April 3, 2013 - 7:45am #11

Thanks a lot for your support.

Thank you again

 

regards

NBA69

How to measure time duration?

March 27, 2013 - 11:34pm #10

Hi,

I suggest you to take a look at this article, which provides a nice and simple example (with code) of how to call a function in Java from the C++ code using JNI:

https://developer.vuforia.com/forum/faq/android-how-can-i-update-my-ui-response-tracking-events

 

How to measure time duration?

March 27, 2013 - 10:47pm #9

Hi,

Please tell me, is this correct ?

 

JNIEXPORT void JNICALL
Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_renderFrame(JNIEnv *, jobject)

{
    //LOG("Java_com_qualcomm_QCARSamples_ImageTargets_GLRenderer_renderFrame");

// other code

 // Did we find any trackables this frame?
    for(int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
    {
        else
        {
            textureIndex = 2;
        }

// My code starts here:
        struct timeval tv;
        gettimeofday(&tv, NULL);
        void SetData(state.getNumTrackableResults(), tv.tv_sec, tv.tv_usec);

// rest of the other code

.....

}

}

Finally writing In ImageTargets.java

void SetData(...)

{ ... }

 

Is this a correct approach to send my information to Java code?

How to compile .cpp and .java?

 

Please help

Thanks in advance

How to measure time duration?

March 19, 2013 - 2:12am #8

Ok, this is what I would do:

add this code at the beginning of ImageTargets.cpp:

 

unsigned long getCurrentTimeMilliseconds()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    unsigned long s = tv.tv_sec * 1000;
    unsigned long us = tv.tv_usec / 1000;
    return s + us;
}

 

then call the getCurrentTimeMilliseconds() function from your native renderFrame() function;
 
then, if you want to pass the time and other info up to the Java code, the easiest is to define a method in Java, like for example:
 
void setCurrentTimeAndOtherInfo(float time, int someInteger, String someString) {

    // set time, someInteger and someString into your "custom" object, for instance:

    myObject.time = time;
    myObject.someInteger = someInteger;
    myObject.someString = someString;
}

 

 
Then, you can call the Java method setCurrentTimeAndOtherInfo() from the native C++ code (i.e. from your renderFrame);
for an example of how to call such a Java method from C++ using JNI, have a look at the code in this little tutorial:

How to measure time duration?

March 18, 2013 - 10:59pm #7

Hi, thanks again

Basically I want to measure the time elapsed between target entered into camera frame and time when target accurately detected and POST this information to REST WCF cloud service.

So, I am thinking to get both timings and other info (from my project) from native code.

I have written REST web service client for Android.

 

My idea is like this:

1) Get current time and information from methods like renderFrame() by changing (if possible) return type from void to say some struct object.

2) Return and store this struct object.

3) Write HttpWebService client code in TargetsRenderer.java.

4) POST this object from WCF REST client on Android mobile.

PROBLEM:

So, just want to know how to perform step 1 & 2 in native code.

 

Please help

Thanks in advance

How to measure time duration?

March 18, 2013 - 7:05am #6

If you need to get the time in Java (as I understand from your message), you don't need to go down to native code;

you can just measure time in the onDrawFrame() method in ImageTargetsRenderer.java;

to do that, in Java it's quite easy; you can use System.currentTimeMliis() or otherwise the Android method elapsedRealTime:

see also this page:

http://developer.android.com/reference/android/os/SystemClock.html

 

How to measure time duration?

March 18, 2013 - 6:38am #5

Hi,

 

1) Can I write getCurrentTimeMilliseconds() like below:

JNIEXPORT unsigned long JNICALL Java_com_qualcomm_QCARSamples_ImageTargets_ImageTargetsRenderer_getCurrentTimeMilliseconds()

{

struct timeval tv;

gettimeofday(&tv, NULL);

unsigned long s = tv.tv_sec * 1000;

unsigned long us = tv.tv_usec / 1000;

return s + us;

}

OR

I need to simply write like this:

In ImageTargets.cpp =>                      public unsigned long getCurrentTimeMilliseconds()

In ImageTargetsRenderer.java  =>                public native unsigned long getCurrentTimeMilliseconds();

 

Problem: It gives error that multiple markers at this line. This method requires a body instead of a semicolon by Eclipse?

OR

2) Changing signature of renderFrame() from void renderFrame() to unsigned long renderFrame() and collecting necessary info in the renderFrame() and returning in Java class is correct or not?

 

Please help

 

Thanks in advance

How to measure time duration?

March 18, 2013 - 3:29am #4

Hi, you could use this function (put it in ImageTargets.cpp):

unsigned long getCurrentTimeMilliseconds()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    unsigned long s = tv.tv_sec * 1000;
    unsigned long us = tv.tv_usec / 1000;
    return s + us;
}

Then you could call that function from your renderFrame() function, and measure the time difference between two consecutive calls to renderFrame()

 

How to measure time duration?

March 18, 2013 - 12:44am #3

Hi,

Can you provide some sample native code for measuring time for camera preview frame or any other sample native code.

 

Thanks in advance

How to measure time duration?

March 17, 2013 - 8:12am #2

Hi, you can identify the time at which a target is detected by looking at the renderFrame() function (see code "state.getNumTrackableResult()" ), where you can get the list of currently tracked targets; if a target appear in that list and it was not there before, it means it has just been detected;

however there is no "event" to indentify the time when the target "enters the camera preview", as Vuforia simply does not know about the target presence (in the camera preview) until the time when it detects it and starts tracking it.

One possibility is maybe to start measuring time elapsed since the first time that renderFrame() is called.

 

Log in or register to post comments