Welcome, Guest. Please Login.
Surveyor Corporation Surveyor SRV-1
Home Help Search Login

Surveyor Robotics Forum

Welcome to the user support forum for Surveyor SRV-1 robots, SRV-1 robot controllers and SVS stereo vision systems. To register for this forum, please send an email to support@surveyor.com which includes your desired forum user name, your registration email address, and a brief explanation of why you wish to join, and we will create a forum account for you.

Please note that there is a Search button in the forum toolbar for forum topics. Another effective search method for the entire surveyor.com site is to use Google, e.g. "xyz site://www.surveyor.com" where "xyz" is the search topic.



Pages: 1
Send Topic Print
YUV <=> RGB conversion (Read 7977 times)
admin
YaBB Administrator
*****




Posts: 3676
YUV <=> RGB conversion
01/15/09 at 7:13am
 
One of the forum users found this very helpful site for converting between RGB and YUV -
    http://www.mikekohn.net/file_formats/yuv_rgb_converter.php
 
A simplified version of the converter is posted here -
     http://www.surveyor.com/blackfin/yuv.html
 
A good description of YUV color space is found here -
    http://en.wikipedia.org/wiki/YUV
 

Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
AndreiSk
Full Member
***




Posts: 168
Re: YUV <=> RGB conversion
Reply #1 - 01/23/09 at 2:13pm
 
Here is small sample if somebody not want to dig it.
void yuv2rgb() {
     // This code partially based on code from http://www.mikekohn.net/stuff/image_processing.php#download
     unsigned char *frameBuffer;
     unsigned int idxFrame, xx, yy;
     int y, u, v, r, g, b, u1, uv1, v1, y1;
 
     // Current frame buffer
     frameBuffer = (unsigned char *)FRAME_BUF;
     // Format is U Y1 V Y2, where Y1 and Y2 is brightness for pixels #1 and #2.  
     // U and V are common for both pixels.
     for(yy = 0; yy < imgHeight; yy++) {
           // Step each two pixels
           for(xx = 0; xx < imgWidth; xx += 2) {            
                 idxFrame = index(xx, yy);
                 // Common part for both pixels
                 u = frameBuffer[idxFrame];                  // U component
                 v = frameBuffer[idxFrame + 2];      // V component
 
                 // Start YUV -> RGB conversion
                 u -= 128;
                 v -= 128;
                 v1 = (5727 * v);
                 uv1 = -(1617 * u) - (2378 * v);
                 u1 = (8324 * u);
 
                 // Pixel #1
                 y = frameBuffer[idxFrame + 1];                        
                 
                 y1 = y << 12;
                 r = (y1 + v1) >> 12;
                 g = (y1 + uv1) >> 12;
                 b = (y1 + u1) >> 12;
                 if (r > 255) r = 255;
                 else if (r < 0) r = 0;
                 if (g > 255) g = 255;
                 else if (g < 0) g = 0;
                 if (b > 255) b = 255;
                 else if (b < 0) b = 0;
                 
                 // Use (rgb) for pixel #1
                 //putchar(r); putchar(g); putchar(b);
 
 
 
                 // Pixel #2
                 y = frameBuffer[idxFrame + 3];
                 
                 y1 = y << 12;
                 r = (y1 + v1) >> 12;
                 g = (y1 + uv1) >> 12;
                 b = (y1 + u1) >> 12;
                 if (r > 255) r = 255;
                 else if (r < 0) r = 0;
                 if (g > 255) g = 255;
                 else if (g < 0) g = 0;
                 if (b > 255) b = 255;
                 else if (b < 0) b = 0;
 
                 // Use (rgb) for pixel #2
                 //putchar(r); putchar(g); putchar(b);
           }
     }
}
Back to top
 
 
  IP Logged
Lefteris
Senior Member
****




Posts: 274
Re: YUV <=> RGB conversion
Reply #2 - 01/23/09 at 2:24pm
 
If you want to work on RGB values you can change a register in the OV965 camera and it will return in RGB format instead of YUV. I don't think there is any reason to do it software-wise.
Back to top
 
 

http://www.realintelligence.net - The real intelligence project || http://lefteris.realintelligence.net - My blog
  IP Logged
shawnjgoff
Full Member
***


an electrical
engineer in the
making

Posts: 132
Re: YUV <=> RGB conversion
Reply #3 - 01/23/09 at 3:12pm
 
I wonder if you switch that register if vc, vb, blob() etc. will work the same (except using rgb values, of course)... I suspect they will since the color values are still 3 8-bit values - I don't think it matters beyond that as far as the code goes.
Back to top
 
« Last Edit: 01/23/09 at 3:13pm by shawnjgoff »  
WWW   IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: YUV <=> RGB conversion
Reply #4 - 01/23/09 at 4:09pm
 
The blob search would work find with RGB, especially if the data is in BGRG order (GBR 4:2:2).  Otherwise, you'll have to make some changes to the pixel indexing, but the basic search function is unchanged once blob_mask[] is populated.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
uniHBinf
YaBB Newbies
*




Posts: 19
Re: YUV <=> RGB conversion
Reply #5 - 04/25/10 at 9:26am
 
How exactly can you change the register to RGB?
Back to top
 
 
  IP Logged
admin
YaBB Administrator
*****




Posts: 3676
Re: YUV <=> RGB conversion
Reply #6 - 04/25/10 at 10:31am
 
We haven't actually done this with the Omnivision sensors, so I don't have a programming example to show you.
Back to top
 
 

SRV-1 Development Team
Surveyor Corporation
Email WWW   IP Logged
Pages: 1
Send Topic Print