<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Kuba,<br>
<br>
First, you can check if your device allow both RGB output mode, if so
you can try change the output to RGB mode.<br>
<br>
If your device doesn't support RGB output, then you need to some
hacking to get it to work. Here are some directions:<br>
<br>
1. Open the igstkWebcamWinVideoImager.cxx class, around line 278:<br>
memcpy(frame->GetImagePtr(),<br>
(unsigned char*)m_Cvframe->imageData,<br>
frameDims[0]*frameDims[1]*frameDims[2]);<br>
This where, we import the frame data from OpenCV to IGSTK<br>
<br>
2. You can try use CvtColor to convert the color space in OpenCV
(detailed documentation is pasted below)<br>
or you can try iterate through that memory space and perform the
conversion, which might be less efficient.<br>
You can find the conversion function here on wiki:<br>
<a
href="http://en.wikipedia.org/wiki/YUV#Converting_between_Y.27UV_and_RGB">http://en.wikipedia.org/wiki/YUV#Converting_between_Y.27UV_and_RGB</a><br>
<br>
Let me know how it goes. The VideoGrabber code is still in the
experimental stage. You are welcome to submit your hacks back into the
repository.<br>
<br>
Patrick<br>
<br>
<br>
*************************************************************************************************************************************************************************************<br>
>From OpenCV manual page:<br>
<a
href="http://www.seas.upenn.edu/%7Ebensapp/opencvdocs/ref/opencvref_cv.htm">http://www.seas.upenn.edu/~bensapp/opencvdocs/ref/opencvref_cv.htm</a><br>
*************************************************************************************************************************************************************************************<br>
<span class="Apple-style-span"
style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; font-size: medium;">
<h3
style="color: rgb(0, 0, 240); margin-bottom: 0pt; font-family: Helvetica;"><a
name="decl_cvCvtColor">CvtColor</a></h3>
<p class="Blurb"
style="margin-top: 0pt; color: rgb(0, 0, 0); font-style: italic; font-weight: bold; font-family: Helvetica; font-size: 13px;">Converts
image from one color space to another</p>
<pre>void cvCvtColor( const CvArr* src, CvArr* dst, int code );
</pre>
<dl>
<dt style="font-family: monospace;">src</dt>
<dd>The source 8-bit (8u), 16-bit (16u) or single-precision
floating-point (32f) image.</dd>
<dt style="font-family: monospace;">dst</dt>
<dd>The destination image of the same data type as the source one.
The number of channels may be different.</dd>
<dt style="font-family: monospace;">code</dt>
<dd>Color conversion operation that can be specifed using
CV_<src_color_space>2<dst_color_space> constants (see
below).</dd>
</dl>
<p>The function<span class="Apple-converted-space"> </span><code>cvCvtColor</code><span
class="Apple-converted-space"> </span>converts input image from one
color space to another. The function ignores<code>colorModel</code><span
class="Apple-converted-space"> </span>and<span
class="Apple-converted-space"> </span><code>channelSeq</code><span
class="Apple-converted-space"> </span>fields of<span
class="Apple-converted-space"> </span><code>IplImage</code><span
class="Apple-converted-space"> </span>header, so the source image
color space should be specified correctly (including order of the
channels in case of RGB space, e.g. BGR means 24-bit format with B<sub>0</sub><span
class="Apple-converted-space"> </span>G<sub>0</sub><span
class="Apple-converted-space"> </span>R<sub>0</sub><span
class="Apple-converted-space"> </span>B<sub>1</sub><span
class="Apple-converted-space"> </span>G<sub>1</sub><span
class="Apple-converted-space"> </span>R<sub>1</sub><span
class="Apple-converted-space"> </span>... layout, whereas RGB means
24-bit format with R<sub>0</sub><span class="Apple-converted-space"> </span>G<sub>0</sub><span
class="Apple-converted-space"> </span>B<sub>0</sub><span
class="Apple-converted-space"> </span>R<sub>1</sub><span
class="Apple-converted-space"> </span>G<sub>1</sub><span
class="Apple-converted-space"> </span>B<sub>1</sub><span
class="Apple-converted-space"> </span>... layout).</p>
<p>The conventional range for R,G,B channel values is:</p>
<ul>
<li>0..255 for 8-bit images</li>
<li>0..65535 for 16-bit images and</li>
<li>0..1 for floating-point images.</li>
</ul>
Of course, in case of linear transformations the range can be
arbitrary, but in order to get correct results in case of non-linear
transformations, the input image should be scaled if necessary.
<p>The function can do the following transformations:</p>
<ul>
<li>Transformations within RGB space like adding/removing alpha
channel, reversing the channel order, conversion to/from 16-bit RGB
color (R5:G6:B5 or R5:G5:B5) color, as well as conversion to/from
grayscale using:
<pre>RGB[A]->Gray: Y<-0.299*R + 0.587*G + 0.114*B
Gray->RGB[A]: R<-Y G<-Y B<-Y A<-0
</pre>
</li>
<li>RGB<=>CIE XYZ.Rec 709 with D65 white point (<code>CV_BGR2XYZ,
CV_RGB2XYZ, CV_XYZ2BGR, CV_XYZ2RGB</code>):
<pre>|X| |0.412453 0.357580 0.180423| |R|
|Y| <- |0.212671 0.715160 0.072169|*|G|
|Z| |0.019334 0.119193 0.950227| |B|
|R| | 3.240479 -1.53715 -0.498535| |X|
|G| <- |-0.969256 1.875991 0.041556|*|Y|
|B| | 0.055648 -0.204043 1.057311| |Z|
X, Y and Z cover the whole value range (in case of floating-point images Z may exceed 1).
</pre>
</li>
<li>RGB<=>YCrCb JPEG (a.k.a. YCC) (<code>CV_BGR2YCrCb,
CV_RGB2YCrCb, CV_YCrCb2BGR, CV_YCrCb2RGB</code>)
<pre>Y <- 0.299*R + 0.587*G + 0.114*B
Cr <- (R-Y)*0.713 + delta
Cb <- (B-Y)*0.564 + delta
R <- Y + 1.403*(Cr - delta)
G <- Y - 0.344*(Cr - delta) - 0.714*(Cb - delta)
B <- Y + 1.773*(Cb - delta),
{ 128 for 8-bit images,
where delta = { 32768 for 16-bit images
{ 0.5 for floating-point images
Y, Cr and Cb cover the whole value range.
</pre>
</li>
<li>RGB<=>HSV (<code>CV_BGR2HSV, CV_RGB2HSV, CV_HSV2BGR,
CV_HSV2RGB</code>)
<pre>// In case of 8-bit and 16-bit images
// R, G and B are converted to floating-point format and scaled to fit 0..1 range
V <- max(R,G,B)
S <- (V-min(R,G,B))/V if V≠0, 0 otherwise
(G - B)*60/S, if V=R
H <- 180+(B - R)*60/S, if V=G
240+(R - G)*60/S, if V=B
if H<0 then H<-H+360
On output 0≤V≤1, 0≤S≤1, 0≤H≤360.
The values are then converted to the destination data type:
8-bit images:
V <- V*255, S <- S*255, H <- H/2 (to fit to 0..255)
16-bit images (currently not supported):
V <- V*65535, S <- S*65535, H <- H
32-bit images:
H, S, V are left as is
</pre>
</li>
<li>RGB<=>HLS (<code>CV_BGR2HLS, CV_RGB2HLS, CV_HLS2BGR,
CV_HLS2RGB</code>)
<pre>// In case of 8-bit and 16-bit images
// R, G and B are converted to floating-point format and scaled to fit 0..1 range
V<sub>max</sub> <- max(R,G,B)
V<sub>min</sub> <- min(R,G,B)
L <- (V<sub>max</sub> + V<sub>min</sub>)/2
S <- (V<sub>max</sub> - V<sub>min</sub>)/(V<sub>max</sub> + V<sub>min</sub>) if L < 0.5
(V<sub>max</sub> - V<sub>min</sub>)/(2 - (V<sub>max</sub> + V<sub>min</sub>)) if L ≥ 0.5
(G - B)*60/S, if V<sub>max</sub>=R
H <- 180+(B - R)*60/S, if V<sub>max</sub>=G
240+(R - G)*60/S, if V<sub>max</sub>=B
if H<0 then H<-H+360
On output 0≤L≤1, 0≤S≤1, 0≤H≤360.
The values are then converted to the destination data type:
8-bit images:
L <- L*255, S <- S*255, H <- H/2
16-bit images (currently not supported):
L <- L*65535, S <- S*65535, H <- H
32-bit images:
H, L, S are left as is
</pre>
</li>
<li>RGB<=>CIE L*a*b* (<code>CV_BGR2Lab, CV_RGB2Lab, CV_Lab2BGR,
CV_Lab2RGB</code>)
<pre>// In case of 8-bit and 16-bit images
// R, G and B are converted to floating-point format and scaled to fit 0..1 range
// convert R,G,B to CIE XYZ
|X| |0.412453 0.357580 0.180423| |R|
|Y| <- |0.212671 0.715160 0.072169|*|G|
|Z| |0.019334 0.119193 0.950227| |B|
X <- X/Xn, where Xn = 0.950456
Z <- Z/Zn, where Zn = 1.088754
L <- 116*Y<sup>1/3</sup> for Y>0.008856
L <- 903.3*Y for Y<=0.008856
a <- 500*(f(X)-f(Y)) + delta
b <- 200*(f(Y)-f(Z)) + delta
where f(t)=t<sup>1/3</sup> for t>0.008856
f(t)=7.787*t+16/116 for t<=0.008856
where delta = 128 for 8-bit images,
0 for floating-point images
On output 0≤L≤100, -127≤a≤127, -127≤b≤127
The values are then converted to the destination data type:
8-bit images:
L <- L*255/100, a <- a + 128, b <- b + 128
16-bit images are currently not supported
32-bit images:
L, a, b are left as is
</pre>
</li>
<li>RGB<=>CIE L*u*v* (<code>CV_BGR2Luv, CV_RGB2Luv, CV_Luv2BGR,
CV_Luv2RGB</code>)
<pre>// In case of 8-bit and 16-bit images
// R, G and B are converted to floating-point format and scaled to fit 0..1 range
// convert R,G,B to CIE XYZ
|X| |0.412453 0.357580 0.180423| |R|
|Y| <- |0.212671 0.715160 0.072169|*|G|
|Z| |0.019334 0.119193 0.950227| |B|
L <- 116*Y<sup>1/3</sup>-16 for Y>0.008856
L <- 903.3*Y for Y<=0.008856
u' <- 4*X/(X + 15*Y + 3*Z)
v' <- 9*Y/(X + 15*Y + 3*Z)
u <- 13*L*(u' - u<sub>n</sub>), where u<sub>n</sub>=0.19793943
v <- 13*L*(v' - v<sub>n</sub>), where v<sub>n</sub>=0.46831096
On output 0≤L≤100, -134≤u≤220, -140≤v≤122
The values are then converted to the destination data type:
8-bit images:
L <- L*255/100, u <- (u + 134)*255/354, v <- (v + 140)*255/256
16-bit images are currently not supported
32-bit images:</pre>
</li>
<li>
<pre>
L, u, v are left as is
</pre>
The above formulae for converting RGB to/from various color spaces have
been taken from multiple sources on Web, primarily from<span
class="Apple-converted-space"> </span><a href="#paper_ford98">Color
Space Conversions (<b>[Ford98]</b>)</a><span
class="Apple-converted-space"> </span>document at Charles Poynton site.</li>
<li>Bayer=>RGB (<code>CV_BayerBG2BGR, CV_BayerGB2BGR,
CV_BayerRG2BGR, CV_BayerGR2BGR,<br>
CV_BayerBG2RGB, CV_BayerGB2RGB, CV_BayerRG2RGB, CV_BayerGR2RGB</code>)
<p>Bayer pattern is widely used in CCD and CMOS cameras. It allows
to get color picture out of a single plane where R,G and B pixels
(sensors of a particular component) are interleaved like this:</p>
<table width="400" border="0">
<tbody>
<tr>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
</tr>
<tr>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td bgcolor="pink">
<p align="center"><font color="#0000ff" size="5">B</font></p>
</td>
<td bgcolor="pink">
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#0000ff" size="5">B</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
</tr>
<tr>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
</tr>
<tr>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#0000ff" size="5">B</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#0000ff" size="5">B</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
</tr>
<tr>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#ff0000" size="5">R</font></p>
</td>
</tr>
<tr>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#0000ff" size="5">B</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
<td>
<p align="center"><font color="#0000ff" size="5">B</font></p>
</td>
<td>
<p align="center"><font color="#008000" size="5">G</font></p>
</td>
</tr>
</tbody>
</table>
<p>The output RGB components of a pixel are interpolated from 1, 2
or 4 neighbors of the pixel having the same color. There are several
modifications of the above pattern that can be achieved by shifting the
pattern one pixel left and/or one pixel up. The two letters C<sub>1</sub><span
class="Apple-converted-space"> </span>and C<sub>2</sub><span
class="Apple-converted-space"> </span>in the conversion constants
CV_BayerC<sub>1</sub>C<sub>2</sub>2{BGR|RGB} indicate the particular
pattern type - these are components from the second row, second and
third columns, respectively. For example, the above pattern has very
popular "BG" type.</p>
</li>
</ul>
</span><br>
<br>
On 5/30/2010 10:47 AM, KubaP wrote:
<blockquote cite="mid:20100530174745.F0A72763C3A@f10.poczta.interia.pl"
type="cite">
<pre wrap="">Hi,
I would like to capture video from the camera in real time.
I work with an example VideoFrameGrabberAndViewerWebcamWin (sandbox, WIndows),
but I have a problem with the format of pixels:
Program works with RGB , but the device provides e.g. YUV. How convert format YUV to RGB?
Thanks in advance for any help.
Kuba.P
----------------------------------------------------------------------
Kup wlasne mieszkanie za 72 tys. zl.
Sprawdz najlepsze oferty >>> <a class="moz-txt-link-freetext" href="http://linkint.pl/f26c8">http://linkint.pl/f26c8</a>
_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>
Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>
Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://public.kitware.com/cgi-bin/mailman/listinfo/igstk-users">http://public.kitware.com/cgi-bin/mailman/listinfo/igstk-users</a>
</pre>
</blockquote>
</body>
</html>