- Sort Posts
- 9 replies
- Last post
Re: Q: extending Trackable or getting grayscaled video frames wi
Re: Q: extending Trackable or getting grayscaled video frames wi
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
Re: Q: extending Trackable or getting grayscaled video frames wi
Re: Q: extending Trackable or getting grayscaled video frames wi
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); }
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
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
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
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