Log in or register to post comments

Q: extending Trackable or getting grayscaled video frames without trackable classes

October 20, 2010 - 8:56pm #1

I want to implement my own tracking algorithm.
Could you please give me guidance to extend Trackable or to get video frames effectively without using subclasses of Trackable?

Thanks.

Re: Q: extending Trackable or getting grayscaled video frames wi

December 22, 2010 - 6:30am #10

What are your trying to accomplish? You could make a copy of the pixel buffer and make changes, then bind it as a texture and render it yourself (using OpenGL). Look into the following OpenGL methods for more information:

glGenTextures
glBindTexture
glTexImage2D

- Kim

Re: Q: extending Trackable or getting grayscaled video frames wi

December 22, 2010 - 12:45am #9

make a copy of the pixel buffer and make changes?? but how to render after make changes? It seems no function to change the pixels in the blackground

Re: Q: extending Trackable or getting grayscaled video frames wi

December 18, 2010 - 7:46am #8

The Image that comes from the tracker is read-only. That said, you can certainly make a copy of the pixel buffer and make changes to do your own work. You won't be able to feed the modified image back to the tracker though.

If you'd like to get an RGB888 version of the image, you can use the setFrameFormat method in QCAR.h to register for a RGB888 version. Note that this will deliver an RGB888 version each frame, which comes with a bit of overhead. If you only need this format on occasion (such as for a screenshot) it might be better to do the conversion from RBG565 yourself, using the method I showed above.

If you're asking how to convert a RGB888 pixel to a RGB565 one, I believe this is the method (just the opposite of what we did before):

int R, G, B;  // these should have color values
short pixel565 =
    ((R << 8) & (0x1F << 11)) |
    ((G << 3) & (0x3F << 5)) |
    ((B >> 3) & 0x1F);

Again, remove those semicolons after the ampersands...

- Kim

Re: Q: extending Trackable or getting grayscaled video frames wi

December 17, 2010 - 9:57pm #7

I've read Image.h, I hope to find a setPixel() function to process the image in my own algorithm. Of course, I didn't find it. Is there a way to set the pixel value?
If so,I also want to know how to convert short to rgb565

Re: Q: extending Trackable or getting grayscaled video frames wi

December 15, 2010 - 2:52pm #6

Thanks for the quick reply. I'll try this out tomorrow and inform you if I succeed!

- Edit -

Confirmed this works! Thanks again!

Re: Q: extending Trackable or getting grayscaled video frames wi

December 15, 2010 - 11:35am #5

Try this out:

if (image->getFormat() == QCAR::RGB565)
{
    // for rbg565, the pixels are stored as an array of shorts
    const short* pixels = (const short*) image->getPixels();
    
    // get the first pixel, as a test case
    short pixel = pixels[0];
    
    // convert rbg565 short value to r, g, b int values
    int R = (pixel & (0x1F << 11)) >> 8;
    int G = (pixel & (0x3F << 5)) >> 3;
    int B = (pixel & 0x1F) << 3;
    
    LOG("R: %d, G: %d, B: %d", R, G, B);
}

Hmm, be sure to remove those semicolons after the ampersands... The auto-format feature is messing with us.

It looks like the first pixel is in the upper right hand corner of the screen. Watch the log output as you move that corner to objects of different colors, lightness and darkness.

- Kim

Re: Q: extending Trackable or getting grayscaled video frames wi

December 15, 2010 - 8:14am #4

Hello

I'm wondering how I can get the RGB values from the const void * getPixels() callback. I've tried casting the const to different types of arrays without success. Does anyone know how to do this for the QCAR::RGB565 format?

QCAR::State state = QCAR::Renderer::getInstance().begin();
QCAR::Frame frame = state.getFrame();

for (int i = 0; i < frame.getNumImages(); i++)
{
	const QCAR::Image* image = frame.getImage(i);
	int width = image->getWidth();
	int height = image->getHeight();
	
	if(image->getFormat() == QCAR::RGB565)
	{				
		/**
			Something
		**/
				
		int R = ........;
		int G = ........;
		int B = ........;
	}
}

Greetings,

Casper

Re: Q: extending Trackable or getting grayscaled video frames wi

October 21, 2010 - 8:17am #3

Thank you very much.

Re: Q: extending Trackable or getting grayscaled video frames wi

October 21, 2010 - 5:23am #2

I can help you with getting grayscale video frames from the system. The State object contains the camera frame and active trackables that correspond to that frame. You can get the current state object in one of two ways:

1) As shown in the samples, you receive the current state object when you call QCAR::Renderer::getInstance().begin()

2) Implement the UpdateCallback interface and register an object with QCAR::registerCallback. The QCAR_onUpdate method will return a state object right after tracking finishes.

From the State object you can get the Frame object, which contains various representations of the camera snapshot as Images. Cycle through the available images, calling getFormat to find the one you want. The pixel formats are defined in QCAR.h.

As a last note, you can register for various camera image formats using QCAR::setFrameFormat.

- Kim

Log in or register to post comments