Topic locked

OpenCV + Vuforia

August 26, 2012 - 9:38pm #1

Hi , i would like to all opencv libraries to the existing ImageTargets sample. Any suggestions??? 

OpenCV + Vuforia

September 3, 2014 - 9:23am #17

Yes, that is fixed indeed in latest 3.0. 

You're welcome.

 

OpenCV + Vuforia

September 3, 2014 - 8:59am #16

It's fixed with the new release! Thank you! :D

OpenCV + Vuforia

May 28, 2014 - 3:54am #15

In the meantime you can use the C++ API to achieve the same (which is not affected by the issue);  if you look at the ImageTargetsNative-2-8-x sample, in ImageTargets.cpp (under the JNI folder) you can find a good example of how to use the QCAR_onUpdate() callback, and you can grab the Frame from the state as shown in the code snippet below

Note: a full tutorial about this approach is available here:

https://developer.vuforia.com/forum/faq/android-how-can-i-access-camera-image

C++ code example:

class ImageTargets_UpdateCallback : public QCAR::UpdateCallback
{   
    virtual void QCAR_onUpdate(QCAR::State& state)
    {
    	QCAR::Frame frame = state.getFrame();
    	int ni = frame.getNumImages();
    	LOG(" native code - QCAR_onUpdate: Num Images %d", ni);

OpenCV + Vuforia

May 28, 2014 - 2:14am #14

That means that I have to wait until the upcoming release of Vuforia for full usage of this function (state.getFrame())?

I think that making it work for more than 2 minutes it would be nice for the proto I'm making. Do you use Vuforia for Android too? (non native code)

I will clean all the additional libraries that are not crucial to get better performance. 

Any other advise for increasing the "running" time? I really need to make it work as soon as possible :)

Thank you very much!

 

OpenCV + Vuforia

May 28, 2014 - 1:56am #13

Thanks for the device details, although it seems this is not device specific issue.

I was able to reproduce a crash like yours using the ImageTargets sample when calling < state.getFrame() > at every frame in onQCARUpdate() for a certain time;   the crash however occurred after running this consecuiely for more than 2 minutes (not just 6 seconds  ...... I guess in your case the simultaneous use / linking of additional libraries might make this happen much quicker due to overall heavier memory usage of the app).

Anyway, the issue has already been  fixed for the upcoming release of Vuforia SDK, which should come to the public sometime soon (although I cannot give any exact official dates at present).

 

 

OpenCV + Vuforia

May 28, 2014 - 1:07am #12

Ok, thank you. I am trying to run it on a Nexus 5 with Kitkat 4.4.2 if its helpfull for something.

 

OpenCV + Vuforia

May 28, 2014 - 12:58am #11

Ok, let me look at this, I will try it out and get back to you...

OpenCV + Vuforia

May 27, 2014 - 11:58am #10

Yes it crush only calling state.getFrame() inside onQCARUpdate() , even in the example of VuforiaSamples . It crashing in about 6-7 seconds 

 

@Override
	public void onQCARUpdate(State state) {
    	
    	Frame frame =state.getFrame();
    //	Image image = frame.getImage(0);
    

 

OpenCV + Vuforia

May 27, 2014 - 9:42am #9

So, you are saying that even by just using the state.getFrame() call inside the onQCARUpdate() is resulting in a crash after some seconds ?

BTW: 

are you calling it from within the onQCARUpdate() ?

 

OpenCV + Vuforia

May 27, 2014 - 4:53am #8

well, i want to convert that images to a Mat. How can i release the reference to image?  

I have simplified that part of code to only:

 	Image imageRGB565 = null;
        Frame frame = state.getFrame();
       
        /*Log.e("Frame Extraccio", "OK ");   
        
        for (int i = 0; i < frame.getNumImages(); ++i) {
            Image image = frame.getImage(i);
            if (image.getFormat() == PIXEL_FORMAT.RGB565) {
                imageRGB565 = image;
                Log.e("Imatge Extraccio", "OK ");   
                break;
            }
        }
        */

 

How can i release that frame? 

If i only call state.getFrame() it also fails (same error) . Any idea?

Thank you!

OpenCV + Vuforia

May 27, 2014 - 1:58am #7

Sounds like you might be retaining some references to multiple images (e.g. every time you grab an image, at each new frame or so, what do you do with that image ?  is it referenced by some other pointers in your app or in the library and maybe the reference is never "released" ?)  if that's the casem that would explain the memory leak... but you'll need to debug it within your application framework.

 

OpenCV + Vuforia

May 27, 2014 - 1:42am #6

Hi! 

I am working in an Android project that involves OpenCV + Vuforia(java)

My goal is to extract from Vuforia a Mat with the image that is being displayed any time for working with it in OpenCV

I use this structure that it's described in some posts here

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Image imageRGB565 = null;
 
        Frame frame = state.getFrame();
 
        Log.e("Frame Extraccio", "OK ");  
 
        for (int i = 0; i < frame.getNumImages(); ++i) {
 
            Image image = frame.getImage(i);
 
            if (image.getFormat() == PIXEL_FORMAT.RGB565) {
 
                imageRGB565 = image;
 
                Log.e("Imatge Extraccio", "OK ");  
 
                break;
 
            }
 
        }

However I have memory leaks when the app is running. It crashes in about 10 seconds with that error:

05-26 10:23:38.024: E/IMemory(15709): cannot map BpMemoryHeap (binder=0xbc1c68f0), size=8847360, fd=54 (Out of memory)
 
 
As i said before my goal is to extract a Mat from vuforia "view". For that reason I have also tried to extract a bitmap as it's also in some posts here with the
method
 

 private Bitmap grabPixels(int x, int y, int w, int h)

I call this method on "onDrawFrame" but it makes the app not running on real time an it has delays on the view. 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public void onDrawFrame(GL10 gl) {
 
if (!mIsActive)
 
            return;       
 
//Extract Bitmap
 
//bitmapExtracted = grabPixels(0, 0, mViewWidth, mViewHeight);
 
// Call our function to render content
 
        renderFrame();
 
}

 

Any idea why is crushing the first part I described? Or any idea how I can make my app running on real time with Mat extracted?

 

Thank you very much! 

 

Gerard

OpenCV + Vuforia

November 14, 2012 - 11:01am #5

@ ravitejas3:

you can integrate opencv with Vuforia sample apps, if you want to; that would be basically a matter of adding an additional library dependency to your project; 

so it should not be too difficult, as harism also pointed out.

Then, once you've linked the library, in the ImageTargets.cpp code, if you want to call some OpenCV functions to process the camera frame buffer,

you will need to access the Frame object from the QCAR::State object; the Frame class then has some methods to retrieve the image buffer (check the API reference for a complete overview of the Frame class API);

Once you have your frame image data (pixel buffer), you should be able to process it with the OpenCV functions.

 

OpenCV + Vuforia

November 14, 2012 - 4:09am #4

Hi, my guess would be that this is not doable. You can include OpenCV library into your Vuforia project quite obviously but doing anything meaningful with it might be impossible. Rationale for this would be that both libraries require Camera instance and AFAIK it's not possible to share it with both.

OpenCV + Vuforia

November 14, 2012 - 12:53am #3

maybe he want combine fast cv with imagetarget or another sample in vuforia

OpenCV + Vuforia

August 27, 2012 - 2:57pm #2

Hello,

I do not think I understand the question. 

-Peter

Topic locked