📄 opencvref_cv.htm
字号:
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>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:
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 <a href="#paper_ford98">Color Space Conversions (<b>[Ford98]</b>)</a>
document at Charles Poynton site.
<p></p>
<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>
<p>
<table border=0 width=400>
<tr>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
</tr><tr>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td bgcolor="pink"><font size=5 color="#0000ff" ><p align="center">B</font></td>
<td bgcolor="pink"><font size=5 color="#008000" ><p align="center">G</font></td>
<td><font size=5 color="#0000ff"><p align="center">B</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
</tr><tr>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
</tr><tr>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#0000ff"><p align="center">B</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#0000ff"><p align="center">B</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
</tr><tr>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#ff0000"><p align="center">R</font></td>
</tr><tr>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#0000ff"><p align="center">B</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
<td><font size=5 color="#0000ff"><p align="center">B</font></td>
<td><font size=5 color="#008000"><p align="center">G</font></td>
</tr>
</table>
</p><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> and C<sub>2</sub> 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>
</ul>
</p>
<hr><h3><a name="decl_cvThreshold">Threshold</a></h3>
<p class="Blurb">Applies fixed-level threshold to array elements</p>
<pre>
void cvThreshold( const CvArr* src, CvArr* dst, double threshold,
double max_value, int threshold_type );
</pre><p><dl>
<dt>src<dd>Source array (single-channel, 8-bit of 32-bit floating point).
<dt>dst<dd>Destination array; must be either the same type as <code>src</code> or 8-bit.
<dt>threshold<dd>Threshold value.
<dt>max_value<dd>Maximum value to use with <code>CV_THRESH_BINARY</code> and
<code>CV_THRESH_BINARY_INV</code> thresholding types.
<dt>threshold_type<dd>Thresholding type (see the discussion)
</dl><p>
The function <code>cvThreshold</code> applies fixed-level thresholding to single-channel array.
The function is typically used to get bi-level (binary) image out of grayscale image
(<a href="opencvref_cxcore.htm#decl_cvCmpS">cvCmpS</a>
could be also used for this purpose) or for removing a noise, i.e. filtering out pixels with too small or too large values.
There are several types of thresholding the function supports that are determined by <code>threshold_type</code>:</p>
<pre>
threshold_type=CV_THRESH_BINARY:
dst(x,y) = max_value, if src(x,y)>threshold
0, otherwise
threshold_type=CV_THRESH_BINARY_INV:
dst(x,y) = 0, if src(x,y)>threshold
max_value, otherwise
threshold_type=CV_THRESH_TRUNC:
dst(x,y) = threshold, if src(x,y)>threshold
src(x,y), otherwise
threshold_type=CV_THRESH_TOZERO:
dst(x,y) = src(x,y), if src(x,y)>threshold
0, otherwise
threshold_type=CV_THRESH_TOZERO_INV:
dst(x,y) = 0, if src(x,y)>threshold
src(x,y), otherwise
</pre>
<p>And this is the visual description of thresholding types:</p>
<p>
<image align="center" src="pics/threshold.png">
</p>
</p>
<hr><h3><a name="decl_cvAdaptiveThreshold">AdaptiveThreshold</a></h3>
<p class="Blurb">Applies adaptive threshold to array</p>
<pre>
void cvAdaptiveThreshold( const CvArr* src, CvArr* dst, double max_value,
int adaptive_method=CV_ADAPTIVE_THRESH_MEAN_C,
int threshold_type=CV_THRESH_BINARY,
int block_size=3, double param1=5 );
</pre><p><dl>
<dt>src<dd>Source image.
<dt>dst<dd>Destination image.
<dt>max_value<dd>Maximum value that is used with <code>CV_THRESH_BINARY</code> and <code>CV_THRESH_BINARY_INV</code>.
<dt>adaptive_method<dd>Adaptive thresholding algorithm to use: <code>CV_ADAPTIVE_THRESH_MEAN_C</code>
or <code>CV_ADAPTIVE_THRESH_GAUSSIAN_C</code> (see the discussion).
<dt>threshold_type<dd>Thresholding type; must be one of
<ul>
<li><code>CV_THRESH_BINARY,</code>
<li><code>CV_THRESH_BINARY_INV</code>
</ul>
<dt>block_size<dd>The size of a pixel neighborhood that is used to calculate a threshold value for the pixel:
3, 5, 7, ...
<dt>param1<dd>The method-dependent parameter.
For the methods <code>CV_ADAPTIVE_THRESH_MEAN_C</code> and <code>CV_ADAPTIVE_THRESH_GAUSSIAN_C</code>
it is a constant subtracted from mean or weighted mean (see the discussion), though it may be negative.
</dl><p>
The function <code>cvAdaptiveThreshold</code> transforms grayscale image to binary image according to
the formulae:</p>
<pre>
threshold_type=<code>CV_THRESH_BINARY</code>:
dst(x,y) = max_value, if src(x,y)>T(x,y)
0, otherwise
threshold_type=<code>CV_THRESH_BINARY_INV</code>:
dst(x,y) = 0, if src(x,y)>T(x,y)
max_value, otherwise
</pre>
<p>where T<sub>I</sub> is a threshold calculated individually for each pixel.</p>
<p>
For the method <code>CV_ADAPTIVE_THRESH_MEAN_C</code> it is a mean of <code>block_size</code> × <code>block_size</code>
pixel neighborhood, subtracted by <code>param1</code>.</p><p>
For the method <code>CV_ADAPTIVE_THRESH_GAUSSIAN_C</code> it is a weighted sum (gaussian) of
<code>block_size</code> × <code>block_size</code> pixel neighborhood, subtracted by <code>param1</code>.</p>
<hr><h2><a name="cv_imgproc_pyramids">Pyramids and the Applications</a></h2>
<hr><h3><a name="decl_cvPyrDown">PyrDown</a></h3>
<p class="Blurb">Downsamples image</p>
<pre>
void cvPyrDown( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 );
</pre><p><dl>
<dt>src<dd>The source image.
<dt>dst<dd>The destination image, should have 2x smaller width and height than the source.
<dt>filter<dd>Type of the filter used for convolution; only <code>CV_GAUSSIAN_5x5</code> is
currently supported.
</dl><p>
The function <code>cvPyrDown</code> performs downsampling step of Gaussian pyramid
decomposition. First it convolves source image with the specified filter and
then downsamples the image by rejecting even rows and columns.</p>
<hr><h3><a name="decl_cvPyrUp">PyrUp</a></h3>
<p class="Blurb">Upsamples image</p>
<pre>
void cvPyrUp( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 );
</pre><p><dl>
<dt>src<dd>The source image.
<dt>dst<dd>The destination image, should have 2x smaller width and height than the source.
<dt>filter<dd>Type of the filter used for convolution; only <code>CV_GAUSSIAN_5x5</code> is
currently supported.
</dl><p>
The function <code>cvPyrUp</code> performs up-sampling step of Gaussian pyramid decomposition.
First it upsamples the source image by injecting even zero rows and columns and
then convolves result with the specified filter multiplied by 4 for
interpolation. So the destination image is four times larger than the source
image.</p>
<hr><h2><a name="cv_imgproc_ccomp">Image Segmentation, Connected Components and Contour Retrieval</a></h2>
<hr><h3><a name="decl_CvConnectedComp">CvConnectedComp</a></h3>
<p class="Blurb">Connected component</p>
<pre>
typedef struct CvConnectedComp
{
double area; /* area of the segmented component */
float value; /* gray scale value of the segmented component */
CvRect rect; /* ROI of the segmented component */
} CvConnectedComp;
</pre>
<hr><h3><a name="decl_cvFloodFill">FloodFill</a></h3>
<p class="Blurb">Fills a connected component with given color</p>
<pre>
void cvFloodFill( CvArr* image, CvPoint seed_point, CvScalar new_val,
CvScalar lo_diff=cvScalarAll(0), CvScalar up_diff=cvScalarAll(0),
CvConnectedComp* comp=NULL, int flags=4, CvArr* mask=NULL );
#define CV_FLOODFILL_FIXED_RANGE (1 << 16)
#define CV_FLOODFILL_MASK_ONLY (1 << 17)
</pre><p><dl>
<dt>image<dd>Input 1- or 3-channel, 8-bit or floating-point image.
It is modified by the function unless CV_FLOODFILL_MASK_ONLY flag is set (see below).
<dt>seed_point<dd>The starting point.
<dt>new_val<dd>New value of repainted domain pixels.
<dt>lo_diff<dd>Maximal lower brightness/color difference between the currently observed pixel and one of its
neighbor belong to the component or seed pixel to add the pixel to component.
In case of 8-bit color images it is packed value.
<dt>up_diff<dd>Maximal upper brightness/color difference between the currently observed pixel and one of its
neighbor belong to the component or seed pixel to add the pixel to component.
In case of 8-bit color images it is packed value.
<dt>comp<dd>Pointer to structure the function fills with the information about the
repainted domain.
<dt>flags<dd>The operation flags. Lower bits contain connectivity value, 4 (by default) or 8,
used within the function. Connectivity determines which neighbors of a pixel are considered.
Upper bits can be 0 or combination of the following flags:<ul>
<li>CV_FLOODFILL_FIXED_RANGE - if set the difference between the current pixel and seed pixel is considered,
otherwise difference between neighbor pixels is considered (the range is floating).
<li>CV_FLOODFILL_MASK_ONLY - if set, the function does not fill the image (<code>new_val</code> is ignored),
but the fills mask (that must be non-NULL in this case).
</ul>
<dt>mask<dd>Operation mask, should be singe-channel 8-bit image, 2 pixels wider and 2 pixels taller than
<code>image</code>. If not NULL, the fu
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -