Log in or register to post comments

Dynamically Set number of targets

March 29, 2013 - 1:55pm #1

Hi,

 

I can see that in VideoPlayback sample , In VideoPlayBack.Java  and VideoPlayBack.Cpp  number of ragets are given static.

 

Suppose i am loading tagets for server and after loading of content i come to know number of ImageTargets. I can modify it VideoPlayBack.java

but I am facing issues in VideoPlayBack.cpp.

 

Please suggest a solution.

Regards

Vineet Aggarwal

Dynamically Set number of targets

April 18, 2013 - 2:18pm #21

Hi, if you plan to have 8 - 10 videos, you will probably need to load and unload videos (for example, unload a video when you don't need to play it), because otherwise you have good chances to ru out of resources and get a crash;

the reason why I suggested to use std::vector is because it wll handle allocation and re-allocation for you (if your vector changes size), however if you prefer you can also use standard arrays, if that makes it easier to change the sample code,  the only drawback is that you will need to manually handle allocation / deallocation / reallocation of your array.

Anyway, if you want to double-check if you are doing it correctly, this tutorial here may be of help; it does not use arrays or vectors of arbitrary size, but at least it shows what are the parts of the sample code that need to be adjusted to take into account more than the 2 sample videos;

https://developer.vuforia.com/forum/faq/android-how-do-i-add-another-target-video-playback-sample

I hope this can be of help.

 

Dynamically Set number of targets

April 18, 2013 - 9:55am #20

Hi , The maximum no. of videos can be 4.

We are planning to have 8-10 targets.

The no. of videos will be 4 and rest will be 2d Images.

 

Also ,  I was wondering that why you suggest std: vector because it seems i may need to change lot of source code. It would n't be better dynamic allocation of arrays as i am getting the no . of targets from java code.

 

Regards

Vineet Aggarwal

Dynamically Set number of targets

April 18, 2013 - 6:55am #19

Yes, I understand that, but I am wondering how many targets you have at most (max), for instance 5, or rather 10, or more like 20 ?

I ask that because laoding/playing videos can be resource consuming and can lead to crash your app if you have too many videos.

 

Dynamically Set number of targets

April 18, 2013 - 6:33am #18

Hi ,

I am getting targets xml from resource and targets can increase or decrease at run time. Therefore i need to have dynamic targets. I am passing the no. of targets getting from server in initTracker method via java code.

Dynamically Set number of targets

April 18, 2013 - 6:30am #17

Hi, how many targets are you trying to use ?

 

Dynamically Set number of targets

April 18, 2013 - 3:36am #16

Hi Alessandro.

I think i am close in achieving my objective of getting dynamic targets.

1. Please check my initTacker method

 I'm initializing vectors like this. Was getting exception in videoQuadAspectRatio  in setVideoDimensions method. So initialized videoQuadAspectRatio vector too to solve the issue. Similarly i am initalizing modelviewMatrix vector too ( i haven't reached to renderFrame do far)  

 

    for (int i=0; i<VIDEO_TARGET; i++)
    {
    QCAR::Vec2F dimensions;
    dimensions.data[0] = 0.0f;
    dimensions.data[1] = 0.0f;
    targetPositiveDimensions.push_back(dimensions);
    videoPlaybackTextureID.push_back(-1);
    videoQuadAspectRatio.push_back(-1);
    QCAR::Matrix44F dim;
    dim.data[0]= 0.0f;
    dim.data[1]= 0.0f;
    modelViewMatrix.push_back(dim);
    }
 
2.  App crashing in setStatus method ,  Since currentStatus is of enumType MEDIA_STATE vector  so i tried this: 
 
        case 0: currentStatus[target] = MEDIA_STATE::REACHED_END;   break;
        case 1: currentStatus[target] = MEDIA_STATE::PAUSED;        break;
        case 2: currentStatus[target] = MEDIA_STATE::STOPPED;       break;
        case 3: currentStatus[target] = MEDIA_STATE::PLAYING;       break;
        case 4: currentStatus[target] = MEDIA_STATE::READY;         break;
        case 5: currentStatus[target] = MEDIA_STATE::NOT_READY;     break;
        case 6: currentStatus[target] = MEDIA_STATE::ERROR;         break;
        default:currentStatus[target] = MEDIA_STATE::NOT_READY;     break;
 
3. C++ documentation says that  we should n't  use  std::vector<bool> isTracking;

 

Kindly help me.

Dynamically Set number of targets

April 17, 2013 - 8:26am #15

Great! Glad to help.

Dynamically Set number of targets

April 17, 2013 - 7:30am #14

Thanks Alessandro

 

It works.

Dynamically Set number of targets

April 17, 2013 - 7:11am #13

I see. If you declare the targetPositiveDimensions that way:

std::vector<QCAR::Vec2F> targetPositiveDimensions;

then your code should become like this:

 

for (int i=0; i<NUM_TARGETS; i++)
{
     LOG("Success1");
     QCAR::Vec2F dimensions;
     dimensions.data[0] = 0.0f;
     dimensions.data[1] = 0.0f;

     targetPositiveDimensions.push_back( dimensions );

     videoPlaybackTextureID.push_back(-1);
     LOG("Success2");
}

 

 

Dynamically Set number of targets

April 17, 2013 - 5:20am #12

 

Hi Alessendo the app crashes at targetpositivedimensions when i use below code. If i comment target positivedimensions the method runs fro videoplaybacktextureid.
 
There must some problem in my declrations
 
 
for (int i=0; i<NUM_TARGETS; i++)
    {
    LOG("Success1");
     targetPositiveDimensions[i].data[0] = 0.0f;
     targetPositiveDimensions[i].data[1] = 0.0f;
    videoPlaybackTextureID.push_back(-1);
    LOG("Success2");
    }
 
 
Here is my declartions
 
std::vector<QCAR::Vec2F> targetPositiveDimensions;
std::vector<QCAR::Matrix44F> modelViewMatrix;
std::vector<MEDIA_STATE> currentStatus;
std::vector<GLuint> videoPlaybackTextureID;
std::vector<bool> isTracking;
std::vector<float> videoQuadAspectRatio;
std::vector<float> keyframeQuadAspectRatio;
 
Please help.

 

Dynamically Set number of targets

April 17, 2013 - 5:06am #11

Hi Alessandro,

 

Love You. Thanks now issue solved.

Dynamically Set number of targets

April 17, 2013 - 5:01am #10

Hi, sorry, there is also another error in your code, which I only saw now, so this is the correct code:

for (int i=0; i<NUM_TARGETS; i++)
    {
        LOG("Success1");
        targetPositiveDimensions[i].data[0] = 0.0f;
        targetPositiveDimensions[i].data[1] = 0.0f;
        videoPlaybackTextureID.push_back(-1);
        LOG("Success2");
 
    }

 

Dynamically Set number of targets

April 17, 2013 - 4:44am #9

Hi Alessandro

Thanks

 

The error now changes  to 

incompatible types in assignment of 'float' to 'float [2]'

 

 

     targetPositiveDimensions[0].data = 0.0f;
    targetPositiveDimensions[1].data = 0.0f;
    videoPlaybackTextureID.push_back(-1);

Dynamically Set number of targets

April 17, 2013 - 4:19am #8

Hi,

it seems this code is causing that error:

targetPositiveDimensions[0].data = 0.0;
targetPositiveDimensions[1].data = 0.0;

Replace 0.0 with 0.0f  and it should be OK.

Dynamically Set number of targets

April 17, 2013 - 4:09am #7

Hi Alessendro,

Thanks

I have started using std:vector .  I changed the arrays to vectors . I got targets from my java code  in initTracking Method. But i 'm facing issue in initialization of targetPositiveDimensions.

1. Please let me know my approch is correct

2. I am  getting error -  incompatible types in assignment of 'double' to 'float [2]'

 
Here is my code
 
 
Java_com_tpg_humancircuit_VideoPlayback_initTracker(JNIEnv *env, jobject obj)
{
    LOG("Java_com_tpg_humancircuit_VideoPlayback_initTracker");

    jclass activityClass = env->GetObjectClass(obj);

    jmethodID getTotalTargetCountMethodID = env->GetMethodID(activityClass,
                                                          "getNumTargets", "()I");
    jmethodID getVideoTargetCountMethodID = env->GetMethodID(activityClass,
                                                          "getVideoTargets", "()I");
    VIDEO_TARGET = env->CallIntMethod(obj, getVideoTargetCountMethodID);

    NUM_TARGETS = env->CallIntMethod(obj, getTotalTargetCountMethodID);

    if (VIDEO_TARGET ==1)
      {
          LOG("video targets 1");
      }

    if (NUM_TARGETS ==3)
    {
    	LOG("targets 3");
    }


    // Initialize the image tracker:
    QCAR::TrackerManager& trackerManager = QCAR::TrackerManager::getInstance();
    QCAR::Tracker* tracker = trackerManager.initTracker(QCAR::Tracker::IMAGE_TRACKER);
    if (tracker == NULL)
    {
        LOG("Failed to initialize ImageTracker.");
        return 0;
    }

    for (int i=0; i<NUM_TARGETS; i++)
    {
    	LOG("Success1");
    	targetPositiveDimensions[0].data = 0.0;
        targetPositiveDimensions[1].data = 0.0;
    	videoPlaybackTextureID.push_back(-1);
    	LOG("Success2");

    }

    LOG("Successfully initialized ImageTracker.");
    return 1;
}

 

 

Please help.

Dynamically Set number of targets

April 16, 2013 - 6:19am #6

Hi, glad that it is solved.

Concerning your question:

Do I have to dynamically allocate all these dynamically

Yes (i.e. you can create std::vector for each of them for instance)

 

 

Dynamically Set number of targets

April 16, 2013 - 5:37am #5

Hi It's working now ,

The STL issues seems to be solved.

Do I have to dynamically allocate all these dynamically

 

MEDIA_STATE currentStatus[NUM_TARGETS];

QCAR::Vec2F targetPositiveDimensions[NUM_TARGETS];

float videoQuadAspectRatio[NUM_TARGETS];

float keyframeQuadAspectRatio[NUM_TARGETS];

QCAR::Matrix44F modelViewMatrix[NUM_TARGETS];

bool isTracking[NUM_TARGETS];

QCAR::Vec2F targetPositiveDimensions[NUM_TARGETS];

 

in initRendering 

 

i get the number of targets from java method.

Dynamically Set number of targets

April 2, 2013 - 4:42am #4

Hi,

have you tried using APP_STL:=stlport_shared

instead of stlport_static 

?

 

Dynamically Set number of targets

April 1, 2013 - 7:30am #3

Hi,

 

I tried to use std: vector but nd build gives me following error :  fatal:error: vector: No such file or directory

 

Included 

#include <vector> in VideoPlayback.cpp

 

Application.mk

 

# Build both ARMv5TE and ARMv7-A machine code.
 
APP_ABI := armeabi armeabi-v7a 
 
# Set target Android API level to the application's minimum SDK version.
 
APP_PLATFORM := android-8
APP_STL := stlport_static
 
Please help me out.
 
Regards
Vineet Aggarwal

Dynamically Set number of targets

March 30, 2013 - 2:46am #2

Hi, 

you could pass the number of targets from Java to C++ via a native method,

then in C++ you could use an std::vector instead of a simple array to dynamically create and fill the list of targets.

 

Log in or register to post comments