Log in or register to post comments

Getting pixel data from RGB888 image.

December 26, 2013 - 2:43am #1

As you can see i am trying get pixel data center of image from frame data.

 

    for (int i = 0; i<vbFrame.getNumImages(); i++) {
        if (state.getFrame().getImage(i)->getFormat() == QCAR::RGB888) {
            vbImage = state.getFrame().getImage(i);
            
			    const char* vbImageData = (const char*) vbImage->getPixels();

			    int bw = vbImage->getBufferWidth();
			    int bh = vbImage->getBufferHeight();
			    
				// center of image
			    int xx = bw / 2;
			    int yy = bh / 2;
			    
			    int bitsPerComponent = 8;
			    int bitsPerPixel = QCAR::getBitsPerPixel(QCAR::RGB888);
			    int bytesPerRow = vbImage->getBufferWidth() * bitsPerPixel / bitsPerComponent;
			    
			    int byteIndex = ((bytesPerRow * yy) + xx) * bitsPerPixel;
			    
			    tempColor.red   = (vbImageData[byteIndex]);
			    tempColor.green = (vbImageData[byteIndex + 1]);
			    tempColor.blue  = (vbImageData[byteIndex + 2]);
			    
			    NSLog(@"RBG %f %f %f", tempColor.red, tempColor.green, tempColor.blue);
        }
    }

but i can't get expected rgb values like R = {0, 255}, G= {0, 255}, B = {0, 255}.

Here is an example of looking a white surface;

	2013-12-26 12:31:03.435 RBG -111.000000 -111.000000 -111.000000
	2013-12-26 12:31:03.468 RBG -110.000000 -111.000000 -111.000000
	2013-12-26 12:31:03.502 RBG -111.000000 -111.000000 -111.000000
	2013-12-26 12:31:03.535 RBG -111.000000 -111.000000 -113.000000
	2013-12-26 12:31:03.569 RBG -112.000000 -111.000000 -113.000000
	2013-12-26 12:31:03.602 RBG -110.000000 -111.000000 -109.000000

and looking black surface logs;

	2013-12-26 12:31:47.032 RBG -1.000000 -2.000000 -2.000000
	2013-12-26 12:31:47.075 RBG -1.000000 -2.000000 -2.000000
	2013-12-26 12:31:47.117 RBG -3.000000 -3.000000 -3.000000
	2013-12-26 12:31:47.161 RBG -2.000000 -3.000000 -3.000000
	2013-12-26 12:31:47.205 RBG -1.000000 -2.000000 -2.000000

 

 what is it wrong? i don't get it. Help!

Note. IOS project.

Getting pixel data from RGB888 image.

January 2, 2014 - 3:31am #5

The Word::getSize() method returns the size (width and height) of the word bounding box in 3D scene units;

so, since the value is expressed in 3D scene units, it is not going to change with the distance from the viewer;

that's the expected behaviour.

 

 

Getting pixel data from RGB888 image.

December 31, 2013 - 6:36am #4

Thanks. i figured out my mistake.

 

But now i am having problems with word location. 

 

i am trying to reach word location on that image. but not only center of it. below it. 

 

I've tried this; 

            // Returns the corresponding Trackable that this result represents.

            const QCAR::Word& word = wordResult->getTrackable();

            

            // Returns the oriented bounding box in image space of the word.

            const QCAR::Obb2D& obb = wordResult->getObb();

            

            wordBoxSize = word.getSize();



             int margin = 3*wordBoxSize.data[1]/2;

             int xPoint = obb.getCenter().data[0]+margin;

             int yPoint = obb.getCenter().data[1];

 

But it seems word.getSize(); doesn't work properly. i mean, this method fails to deliver when i look that word closer or far. it's giving me value when first detected and not chaning. now i am updating qcar to 2.8.7

 

sorry for bad english grammar

Getting pixel data from RGB888 image.

December 31, 2013 - 6:15am #3

Have you tried something like this:

int bytesPerPixel = 3; // RGB888 means 3 bytes per pixel

int bytesPerRow = bytesPerPixel * bw;

int byteIndex = bytesPerRow * bh/2 +  bytesPerPixel * bw/2;

?

 

Getting pixel data from RGB888 image.

December 26, 2013 - 5:44am #2

i solved my problem.

 

    unsigned char rchar = vbImageData[byteIndex];

    unsigned char gchar = vbImageData[byteIndex + 1];

    unsigned char bchar = vbImageData[byteIndex + 2];

    

    int r = (int)rchar;

    int g = (int)gchar;

    int b = (int)bchar;

 

but i seems i failing to find center of image. 

 

What is wrong here?

    int bw = vbImage->getBufferWidth();

    int bh = vbImage->getBufferHeight();

    

    int xx = bw/2;

    int yy = bh/2;

    

    int bitsPerComponent = 8;

    int bitsPerPixel = QCAR::getBitsPerPixel(QCAR::RGB888);

    int bytesPerRow = vbImage->getBufferWidth() * bitsPerPixel / bitsPerComponent;

    

    int byteIndex = bytesPerRow * xx + yy * bitsPerPixel;

Log in or register to post comments