📄 opencv image processing and computer vision reference manual.mht
字号:
const CvArr* image, CvPoint pt1, CvPoint pt2,
void* buffer, int connectivity=3D8 );
</PRE>
<P>
<DL>
<DT>image
<DD>Image to sample the line from.=20
<DT>pt1
<DD>Starting the line point.=20
<DT>pt2
<DD>Ending the line point.=20
<DT>buffer
<DD>Buffer to store the line points; must have enough size to store =
max(=20
|<CODE>pt2.x</CODE>-<CODE>pt1.x</CODE>|+1,=20
|<CODE>pt2.y</CODE>-<CODE>pt1.y</CODE>|+1 )</CODE> points in case of=20
8-connected line and=20
=
|<CODE>pt2.x</CODE>-<CODE>pt1.x</CODE>|+|<CODE>pt2.y</CODE>-<CODE>pt1.y</=
CODE>|+1=20
in case of 4-connected line.=20
<DT>connectivity
<DD>The line connectivity, 4 or 8. </DD></DL>
<P>The function <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvSampleLine">cvSampleLine</A>=20
implements a particular case of application of line iterators. The =
function=20
reads all the image points lying on the line between <CODE>pt1</CODE> =
and=20
<CODE>pt2</CODE>, including the ending points, and stores them into the=20
buffer.</P>
<HR>
<H3><A name=3Ddecl_cvGetRectSubPix>GetRectSubPix</A></H3>
<P class=3DBlurb>Retrieves pixel rectangle from image with sub-pixel =
accuracy</P><PRE>void cvGetRectSubPix( const CvArr* src, CvArr* dst, =
CvPoint2D32f center );
</PRE>
<P>
<DL>
<DT>src
<DD>Source image.=20
<DT>dst
<DD>Extracted rectangle.=20
<DT>center
<DD>Floating point coordinates of the extracted rectangle center =
within the=20
source image. The center must be inside the image. </DD></DL>
<P>The function <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvGetRectSubPix">cvGetRectSubPix</A>=20
extracts pixels from <CODE>src</CODE>:</P><PRE>dst(x, y) =3D src(x + =
center.x - (width(dst)-1)*0.5, y + center.y - (height(dst)-1)*0.5)
</PRE>
<P>where the values of pixels at non-integer coordinates are retrieved =
using=20
bilinear interpolation. Every channel of multiple-channel images is =
processed=20
independently. Whereas the rectangle center must be inside the image, =
the whole=20
rectangle may be partially occluded. In this case, the replication =
border mode=20
is used to get pixel values beyond the image boundaries. </P>
<HR>
<H3><A name=3Ddecl_cvGetQuadrangleSubPix>GetQuadrangleSubPix</A></H3>
<P class=3DBlurb>Retrieves pixel quadrangle from image with sub-pixel =
accuracy</P><PRE>void cvGetQuadrangleSubPix( const CvArr* src, CvArr* =
dst, const CvMat* map_matrix,
int fill_outliers=3D0, CvScalar =
fill_value=3DcvScalarAll(0) );
</PRE>
<P>
<DL>
<DT>src
<DD>Source image.=20
<DT>dst
<DD>Extracted quadrangle.=20
<DT>map_matrix
<DD>The transformation 3 =A1=C1 2 matrix =
[<CODE>A</CODE>|<CODE>b</CODE>] (see the=20
discussion).=20
<DT>fill_outliers
<DD>The flag indicating whether to interpolate values of pixel taken =
from=20
outside of the source image using replication mode=20
(<CODE>fill_outliers</CODE>=3D0) or set them a fixed value=20
(<CODE>fill_outliers</CODE>=3D1).=20
<DT>fill_value
<DD>The fixed value to set the outlier pixels to if=20
<CODE>fill_outliers</CODE>=3D1. </DD></DL>
<P>The function <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvGetQuadrangleSubPix">cvGetQuadrangleSubPix<=
/A>=20
extracts pixels from <CODE>src</CODE> at sub-pixel accuracy and stores =
them to=20
<CODE>dst</CODE> as follows:</P><PRE>dst(x+width(dst)/2, =
y+height(dst)/2)=3D src( A<SUB>11</SUB>x+A<SUB>12</SUB>y+b<SUB>1</SUB>, =
A<SUB>21</SUB>x+A<SUB>22</SUB>y+b<SUB>2</SUB>),
where <CODE>A</CODE> and <CODE>b</CODE> are taken from =
<CODE>map_matrix</CODE>
| A<SUB>11</SUB> A<SUB>12</SUB> b<SUB>1</SUB> |
map_matrix =3D | |
| A<SUB>21</SUB> A<SUB>22</SUB> b<SUB>2</SUB> |
</PRE>
<P>where the values of pixels at non-integer coordinates =
A•(x,y)<SUP>T</SUP>+b=20
are retrieved using bilinear interpolation. Every channel of =
multiple-channel=20
images is processed independently.</P>
<H4>Example. Using cvGetQuadrangleSubPix for image =
rotation.</H4><PRE>#include "cv.h"
#include "highgui.h"
#include "math.h"
int main( int argc, char** argv )
{
IplImage* src;
/* the first command line parameter must be image file name */
if( argc=3D=3D2 && (src =3D cvLoadImage(argv[1], -1))!=3D0)
{
IplImage* dst =3D cvCloneImage( src );
int delta =3D 1;
int angle =3D 0;
cvNamedWindow( "src", 1 );
cvShowImage( "src", src );
for(;;)
{
float m[6];
double factor =3D (cos(angle*CV_PI/180.) + 1.1)*3;
CvMat M =3D cvMat( 2, 3, CV_32F, m );
int w =3D src->width;
int h =3D src->height;
m[0] =3D (float)(factor*cos(-angle*2*CV_PI/180.));
m[1] =3D (float)(factor*sin(-angle*2*CV_PI/180.));
m[2] =3D w*0.5f;
m[3] =3D -m[1];
m[4] =3D m[0];
m[5] =3D h*0.5f;
cvGetQuadrangleSubPix( src, dst, &M, 1, cvScalarAll(0));
cvNamedWindow( "dst", 1 );
cvShowImage( "dst", dst );
if( cvWaitKey(5) =3D=3D 27 )
break;
angle =3D (angle + delta) % 360;
}
}
return 0;
}
</PRE>
<HR>
<H3><A name=3Ddecl_cvResize>Resize</A></H3>
<P class=3DBlurb>Resizes image</P><PRE>void cvResize( const CvArr* src, =
CvArr* dst, int interpolation=3DCV_INTER_LINEAR );
</PRE>
<P>
<DL>
<DT>src
<DD>Source image.=20
<DT>dst
<DD>Destination image.=20
<DT>interpolation
<DD>Interpolation method:
<UL>
<LI>CV_INTER_NN - nearest-neigbor interpolation,=20
<LI>CV_INTER_LINEAR - bilinear interpolation (used by default)=20
<LI>CV_INTER_AREA - resampling using pixel area relation. It is =
preferred=20
method for image decimation that gives moire-free results. In case =
of=20
zooming it is similar to <CODE>CV_INTER_NN</CODE> method.=20
<LI>CV_INTER_CUBIC - bicubic interpolation. </LI></UL></DD></DL>
<P>The function <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvResize">cvResize</A>=20
resizes image <CODE>src</CODE> so that it fits exactly to =
<CODE>dst</CODE>. If=20
ROI is set, the function consideres the ROI as supported as usual.</P>
<HR>
<H3><A name=3Ddecl_cvWarpAffine>WarpAffine</A></H3>
<P class=3DBlurb>Applies affine transformation to the image</P><PRE>void =
cvWarpAffine( const CvArr* src, CvArr* dst, const CvMat* map_matrix,
int flags=3DCV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,
CvScalar fillval=3DcvScalarAll(0) );
</PRE>
<P>
<DL>
<DT>src
<DD>Source image.=20
<DT>dst
<DD>Destination image.=20
<DT>map_matrix
<DD>2=A1=C13 transformation matrix.=20
<DT>flags
<DD>A combination of interpolation method and the following optional =
flags:
<UL>
<LI>CV_WARP_FILL_OUTLIERS - fill all the destimation image pixels. =
If some=20
of them correspond to outliers in the source image, they are set to=20
<CODE>fillval</CODE>.=20
<LI>CV_WARP_INVERSE_MAP - indicates that <CODE>matrix</CODE> is =
inverse=20
transform from destination image to source and, thus, can be used =
directly=20
for pixel interpolation. Otherwise, the function finds the inverse =
transform=20
from <CODE>map_matrix</CODE>. </LI></UL>
<DT>fillval
<DD>A value used to fill outliers. </DD></DL>
<P>The function <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvWarpAffine">cvWarpAffine</A>=20
transforms source image using the specified =
matrix:</P><PRE>dst(x&apos;,y&apos;)<-src(x,y)
(x&apos;,y&apos;)<SUP>T</SUP>=3Dmap_matrix•(x,y,1)<SUP>T</S=
UP>+b if CV_WARP_INVERSE_MAP is not set,
(x, =
y)<SUP>T</SUP>=3Dmap_matrix•(x&apos;,y&apos,1)<SUP>T</SUP>+=
b otherwise
</PRE>
<P>The function is similar to <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvGetQuadrangleSubPix">cvGetQuadrangleSubPix<=
/A>=20
but they are not exactly the same. <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvWarpAffine">cvWarpAffine</A>=20
requires input and output image have the same data type, has larger =
overhead (so=20
it is not quite suitable for small images) and can leave part of =
destination=20
image unchanged. While <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvGetQuadrangleSubPix">cvGetQuadrangleSubPix<=
/A>=20
may extract quadrangles from 8-bit images into floating-point buffer, =
has=20
smaller overhead and always changes the whole destination image content. =
</P>
<P>To transform a sparse set of points, use <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvTransform">cvTransform</A>=20
function from cxcore.</P>
<HR>
<H3><A name=3Ddecl_cv2DRotationMatrix>2DRotationMatrix</A></H3>
<P class=3DBlurb>Calculates affine matrix of 2d rotation</P><PRE>CvMat* =
cv2DRotationMatrix( CvPoint2D32f center, double angle,
double scale, CvMat* map_matrix );
</PRE>
<P>
<DL>
<DT>center
<DD>Center of the rotation in the source image.=20
<DT>angle
<DD>The rotation angle in degrees. Positive values mean =
couter-clockwise=20
rotation (the coordiate origin is assumed at top-left corner).=20
<DT>scale
<DD>Isotropic scale factor.=20
<DT>map_matrix
<DD>Pointer to the destination 2=A1=C13 matrix. </DD></DL>
<P>The function <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cv2DRotationMatrix">cv2DRotationMatrix</A>=20
calculates matrix:</P><PRE>[ =A6=C1 =A6=C2 | (1-=A6=C1)*center.x - =
=A6=C2*center.y ]
[ -=A6=C2 =A6=C1 | =A6=C2*center.x + (1-=A6=C1)*center.y ]
where =A6=C1=3Dscale*cos(angle), =A6=C2=3Dscale*sin(angle)
</PRE>
<P>The transformation maps the rotation center to itself. If this is not =
the=20
purpose, the shift should be adjusted.</P>
<HR>
<H3><A name=3Ddecl_cvWarpPerspective>WarpPerspective</A></H3>
<P class=3DBlurb>Applies perspective transformation to the =
image</P><PRE>void cvWarpPerspective( const CvArr* src, CvArr* dst, =
const CvMat* map_matrix,
int =
flags=3DCV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,
CvScalar fillval=3DcvScalarAll(0) );
</PRE>
<P>
<DL>
<DT>src
<DD>Source image.=20
<DT>dst
<DD>Destination image.=20
<DT>map_matrix
<DD>3=A1=C13 transformation matrix.=20
<DT>flags
<DD>A combination of interpolation method and the following optional =
flags:
<UL>
<LI>CV_WARP_FILL_OUTLIERS - fill all the destimation image pixels. =
If some=20
of them correspond to outliers in the source image, they are set to=20
<CODE>fillval</CODE>.=20
<LI>CV_WARP_INVERSE_MAP - indicates that <CODE>matrix</CODE> is =
inverse=20
transform from destination image to source and, thus, can be used =
directly=20
for pixel interpolation. Otherwise, the function finds the inverse =
transform=20
from <CODE>map_matrix</CODE>. </LI></UL>
<DT>fillval
<DD>A value used to fill outliers. </DD></DL>
<P>The function <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvWarpPerspective">cvWarpPerspective</A>=20
transforms source image using the specified =
matrix:</P><PRE>dst(x&apos;,y&apos;)<-src(x,y)
(tx&apos;,ty&apos;,t)<SUP>T</SUP>=3Dmap_matrix•(x,y,1)<SUP>=
T</SUP>+b if CV_WARP_INVERSE_MAP is not set,
(tx, ty, =
t)<SUP>T</SUP>=3Dmap_matrix•(x&apos;,y&apos,1)<SUP>T</SUP>+=
b otherwise
</PRE>
<P>For a sparse set of points use <A=20
href=3D"http://www.assuredigit.com/incoming/sourcecode/opencv/chinese_doc=
s/ref/opencvref_cv.htm#decl_cvPerspectiveTransform">cvPerspectiveTransfor=
m</A>=20
function from cxcore.</P>
<HR>
<H3><A =
name=3Ddecl_cvWarpPerspectiveQMatrix>WarpPerspectiveQMatrix</A></H3>
<P class=3DBlurb>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.=20
<DT>dst
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -