📄 opencvref_cv.htm
字号:
<hr><h3><a name="decl_cvWarpPerspectiveQMatrix">WarpPerspectiveQMatrix</a></h3>
<p class="Blurb">Calculates perspective transform from 4 corresponding points</p>
<pre>
CvMat* cvWarpPerspectiveQMatrix( const CvPoint2D32f* src,
const CvPoint2D32f* dst,
CvMat* map_matrix );
</pre><p><dl>
<dt>src<dd>Coordinates of 4 quadrangle vertices in the source image.
<dt>dst<dd>Coordinates of the 4 corresponding quadrangle vertices in the destination image.
<dt>map_matrix<dd>Pointer to the destination 3×3 matrix.
</dl><p>
The function <code>cvWarpPerspectiveQMatrix</code> calculates
matrix of perspective transform such that:</p>
<pre>
(t<sub>i</sub>•x'<sub>i</sub>,t<sub>i</sub>•y'<sub>i</sub>,t<sub>i</sub>)<sup>T</sup>=map_matrix•(x<sub>i</sub>,y<sub>i</sub>,1)<sup>T</sup>
</pre>
<p>where <code>dst(i)=(x'<sub>i</sub>,y'<sub>i</sub>), src(i)=(x<sub>i</sub>,y<sub>i</sub>), i=0..3</code>.</p>
<hr><h3><a name="decl_cvRemap">Remap</a></h3>
<p class="Blurb">Applies generic geometrical transformation to the image</p>
<pre>
void cvRemap( const CvArr* src, CvArr* dst,
const CvArr* mapx, const CvArr* mapy,
int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,
CvScalar fillval=cvScalarAll(0) );
</pre><p><dl>
<dt>src<dd>Source image.
<dt>dst<dd>Destination image.
<dt>mapx<dd>The map of x-coordinates (32fC1 image).
<dt>mapy<dd>The map of y-coordinates (32fC1 image).
<dt>flags<dd>A combination of interpolation method and the following optional flag(s):<ul>
<li>CV_WARP_FILL_OUTLIERS - fill all the destination image pixels. If some of them correspond to
outliers in the source image, they are set to <code>fillval</code>.
</ul>
<dt>fillval<dd>A value used to fill outliers.
</dl><p>
The function <code>cvRemap</code> transforms source image using
the specified map:</p>
<pre>
dst(x,y)<-src(mapx(x,y),mapy(x,y))
</pre>
<p>Similar to other geometrical transformations, some interpolation method (specified by user)
is used to extract pixels with non-integer coordinates.
</p>
<hr><h3><a name="decl_cvLogPolar">LogPolar</a></h3>
<p class="Blurb">Remaps image to log-polar space</p>
<pre>
void cvLogPolar( const CvArr* src, CvArr* dst,
CvPoint2D32f center, double M,
int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
</pre><p><dl>
<dt>src<dd>Source image.
<dt>dst<dd>Destination image.
<dt>center<dd>The transformation center, where the output precision is maximal.
<dt>M<dd>Magnitude scale parameter. See below.
<dt>flags<dd>A combination of interpolation method and the following optional flags:<ul>
<li>CV_WARP_FILL_OUTLIERS - fill all the destination image pixels. If some of them correspond to
outliers in the source image, they are set to zeros.
<li>CV_WARP_INVERSE_MAP - indicates that <code>matrix</code> is inverse transform from destination image
to source and, thus, can be used directly for pixel interpolation. Otherwise,
the function finds the inverse transform from <code>map_matrix</code>.
</ul>
<dt>fillval<dd>A value used to fill outliers.
</dl><p>
The function <code>cvLogPolar</code> transforms source image using
the following transformation:</p>
<pre>
Forward transformation (<code>CV_WARP_INVERSE_MAP</code> is not set):
dst(phi,rho)<-src(x,y)
Inverse transformation (<code>CV_WARP_INVERSE_MAP</code> is set):
dst(x,y)<-src(phi,rho),
where rho=M*log(sqrt(x<sup>2</sup>+y<sup>2</sup>))
phi=atan(y/x)
</pre>
<p>The function emulates the human "foveal" vision and can be used for fast scale and rotation-invariant
template matching, for object tracking etc.</p>
<h4>Example. Log-polar transformation.</h4>
<pre>
#include <cv.h>
#include <highgui.h>
int main(int argc, char** argv)
{
IplImage* src;
if( argc == 2 && (src=cvLoadImage(argv[1],1) != 0 )
{
IplImage* dst = cvCreateImage( cvSize(256,256), 8, 3 );
IplImage* src2 = cvCreateImage( cvGetSize(src), 8, 3 );
cvLogPolar( src, dst, cvPoint2D32f(src->width/2,src->height/2), 40, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS );
cvLogPolar( dst, src2, cvPoint2D32f(src->width/2,src->height/2), 40, CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS+CV_WARP_INVERSE_MAP );
cvNamedWindow( "log-polar", 1 );
cvShowImage( "log-polar", dst );
cvNamedWindow( "inverse log-polar", 1 );
cvShowImage( "inverse log-polar", src2 );
cvWaitKey();
}
return 0;
}
</pre>
<p>And this is what the program displays when opencv/samples/c/fruits.jpg is passed to it</p>
<p>
<img align="center" src="pics/logpolar.jpg" width=256 height=256>
<img align="center" src="pics/inv_logpolar.jpg" width=256 height=256>
</p>
<hr><h2><a name="cv_imgproc_morphology">Morphological Operations</a></h2>
<hr><h3><a name="decl_cvCreateStructuringElementEx">CreateStructuringElementEx</a></h3>
<p class="Blurb">Creates structuring element</p>
<pre>
IplConvKernel* cvCreateStructuringElementEx( int cols, int rows, int anchor_x, int anchor_y,
int shape, int* values=NULL );
</pre><p><dl>
<dt>cols<dd>Number of columns in the structuring element.
<dt>rows<dd>Number of rows in the structuring element.
<dt>anchor_x<dd>Relative horizontal offset of the anchor point.
<dt>anchor_y<dd>Relative vertical offset of the anchor point.
<dt>shape<dd>Shape of the structuring element; may have the following values:
<ul>
<li><code>CV_SHAPE_RECT</code>, a rectangular element;
<li><code>CV_SHAPE_CROSS</code>, a cross-shaped element;
<li><code>CV_SHAPE_ELLIPSE</code>, an elliptic element;
<li><code>CV_SHAPE_CUSTOM</code>, a user-defined element. In this case the parameter <code>values</code>
specifies the mask, that is, which neighbors of the pixel must be considered.
</ul>
<dt>values<dd> Pointer to the structuring element data, a plane array, representing
row-by-row scanning of the element matrix. Non-zero values indicate points that
belong to the element. If the pointer is <code>NULL</code>, then all values are considered
non-zero, that is, the element is of a rectangular shape. This parameter is
considered only if the shape is <code>CV_SHAPE_CUSTOM</code> .
</dl><p>
The function <a href="#decl_cv CreateStructuringElementEx">cv CreateStructuringElementEx</a> allocates and fills the structure
<code> IplConvKernel</code>, which can be used as a structuring element in the morphological
operations.</p>
<hr><h3><a name="decl_cvReleaseStructuringElement">ReleaseStructuringElement</a></h3>
<p class="Blurb">Deletes structuring element</p>
<pre>
void cvReleaseStructuringElement( IplConvKernel** element );
</pre><p><dl>
<dt>element<dd>Pointer to the deleted structuring element.
</dl><p>
The function <code>cvReleaseStructuringElement</code> releases the structure <code>IplConvKernel</code>
that is no longer needed. If <code>*element</code> is <code>NULL</code>, the function has no effect.</p>
<hr><h3><a name="decl_cvErode">Erode</a></h3>
<p class="Blurb">Erodes image by using arbitrary structuring element</p>
<pre>
void cvErode( const CvArr* src, CvArr* dst, IplConvKernel* element=NULL, int iterations=1 );
</pre><p><dl>
<dt>src<dd>Source image.
<dt>dst<dd>Destination image.
<dt>element<dd>Structuring element used for erosion. If it is <code>NULL</code>, a 3×3 rectangular
structuring element is used.
<dt>iterations<dd>Number of times erosion is applied.
</dl><p>
The function <code>cvErode</code> erodes the source image using the specified structuring element
that determines the shape of a pixel neighborhood over which the minimum is taken:</p>
<pre>
dst=erode(src,element): dst(x,y)=min<sub>((x',y') in element)</sub>)</sub>src(x+x',y+y')
</pre>
<p>The function supports the in-place mode. Erosion can be applied several (<code>iterations</code>)
times. In case of color image each channel is processed independently.</p>
<hr><h3><a name="decl_cvDilate">Dilate</a></h3>
<p class="Blurb">Dilates image by using arbitrary structuring element</p>
<pre>
void cvDilate( const CvArr* src, CvArr* dst, IplConvKernel* element=NULL, int iterations=1 );
</pre><p><dl>
<dt>src<dd>Source image.
<dt>dst<dd>Destination image.
<dt>element<dd>Structuring element used for erosion. If it is <code>NULL</code>, a 3×3 rectangular
structuring element is used.
<dt>iterations<dd>Number of times erosion is applied.
</dl><p>
The function <code>cvDilate</code> dilates the source image using the specified structuring element
that determines the shape of a pixel neighborhood over which the maximum is taken:</p>
<pre>
dst=dilate(src,element): dst(x,y)=max<sub>((x',y') in element)</sub>)</sub>src(x+x',y+y')
</pre>
<p>The function supports the in-place mode. Dilation can be applied several (<code>iterations</code>)
times. In case of color image each channel is processed independently.</p>
<hr><h3><a name="decl_cvMorphologyEx">MorphologyEx</a></h3>
<p class="Blurb">Performs advanced morphological transformations</p>
<pre>
void cvMorphologyEx( const CvArr* src, CvArr* dst, CvArr* temp,
IplConvKernel* element, int operation, int iterations=1 );
</pre><p><dl>
<dt>src<dd>Source image.
<dt>dst<dd>Destination image.
<dt>temp<dd>Temporary image, required in some cases.
<dt>element<dd>Structuring element.
<dt>operation<dd>Type of morphological operation, one of:<br>
<code>CV_MOP_OPEN</code> - opening<br>
<code>CV_MOP_CLOSE</code> - closing<br>
<code>CV_MOP_GRADIENT</code> - morphological gradient<br>
<code>CV_MOP_TOPHAT</code> - "top hat"<br>
<code>CV_MOP_BLACKHAT</code> - "black hat"<br>
<dt>iterations<dd>Number of times erosion and dilation are applied.
</dl><p>
The function <code>cvMorphologyEx</code> can perform advanced morphological
transformations using erosion and dilation as basic operations.</p>
<pre>
Opening:
dst=open(src,element)=dilate(erode(src,element),element)
Closing:
dst=close(src,element)=erode(dilate(src,element),element)
Morphological gradient:
dst=morph_grad(src,element)=dilate(src,element)-erode(src,element)
"Top hat":
dst=tophat(src,element)=src-open(src,element)
"Black hat":
dst=blackhat(src,element)=close(src,element)-src
</pre>
<p>
The temporary image <code>temp</code> is required for morphological gradient and, in case of in-place
operation, for "top hat" and "black hat".
</p>
<hr><h2><a name="cv_imgproc_filters">Filters and Color Conversion</a></h2>
<hr><h3><a name="decl_cvSmooth">Smooth</a></h3>
<p class="Blurb">Smooths the image in one of several ways</p>
<pre>
void cvSmooth( const CvArr* src, CvArr* dst,
int smoothtype=CV_GAUSSIAN,
int param1=3, int param2=0, double param3=0 );
</pre><p><dl>
<dt>src<dd>The source image.
<dt>dst<dd>The destination image.
<dt>smoothtype<dd>Type of the smoothing:<ul>
<li>CV_BLUR_NO_SCALE (simple blur with no scaling) -
summation over a pixel <code>param1</code>×<code>param2</code> neighborhood.
If the neighborhood size may vary, one may precompute integral image with <a href="#decl_cvIntegral">cvIntegral</a> function.
<li>CV_BLUR (simple blur) - summation over a pixel <code>param1</code>×<code>param2</code> neighborhood with
subsequent scaling by 1/(<code>param1</code>•<code>param2</code>).
<li>CV_GAUSSIAN (gaussian blur) - convolving image with <code>param1</code>×<code>param2</code> Gaussian kernel.
<li>CV_MEDIAN (median blur) - finding median of <code>param1</code>×<code>param1</code> neighborhood (i.e.
the neighborhood is square).
<li>CV_BILATERAL (bilateral filter) - applying bilateral 3x3 filtering with color sigma=<code>param1</code> and
space sigma=<code>param2</code>. Information about bilateral filtering
can be found at <a href="http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html">
http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html</a>
</ul>
<dt>param1<dd>The first parameter of smoothing operation.
<dt>param2<dd>The second parameter of smoothing operation. In case of simple scaled/non-scaled and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -