opencv学习:
在opencv中API 矩阵(数组)可行操作:
1.计算数组中所有元素的绝对值和;
Scalar cv::cuda::absSum(InputArray src,
InputArray mask = noArray()
)
Returns the sum of absolute values for matrix elements
Parameters
src Source image of any depth except for CV_64F .
mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
2.两个数组差值的绝对值;
void cv::absdiff(InputArraysrc1,
InputArray src2,
OutputArray dst
)
between an array and a scalar.
Calculates the per-element absolute difference between two arrays or Parameters
src1 first input array or a scalar.
src2 second input array or a scalar.
dst output array that has the same size and type as input array
3.两个数组的元素级的加运算;
void cv::add(InputArraysrc1,
InputArray src2,
OutputArray dst,
InputArray mask = noArray(),
int dtype = -1
)
two arrays or an array and a scalar.
Calculates the per-element sum of Parameters:
src1 first input array or a scalar.
src2 second input array or a scalar.
dst output array that has the same size and number of channels as the input array(s); the depth is defined by dtype or src1/src2.
mask optional operation mask - 8-bit single channel array, that specifies elements of the output array to be changed
dtype optional depth of the output array (see the discussion below).
4.两个数组元素的加权相加运算;
void cv::addWeighted(InputArraysrc1,
double alpha,
InputArray src2,
double beta,
double gamma,
OutputArray dst,
int dtype = -1
)
Calculates the weighted sum of two array.
dst = src1*alpha + src2*beta + gamma;
Parameters
src1 first input array.
alpha weight of the first array elements.
src2 second input array of the same size and channel number as src1.
beta weight of the second array elements.
gamma scalar added to each sum.
dst output array that has the same size and number of channels as the input arrays.
dtype optional depth of the output array; when both input arrays have the same depth, dtype can be set to -1, which will be equivalent to src1.depth().
详细介绍链接如下:
5.计算数组中所有元素的平均值;
没有找到API,不过我可以提供一种用API的思路,那就是先用API求和在除以数组长度
6.计算数组中所有元素的绝对值和标准差
在opencv3.0中没有找到可以直接调用的API,在网上可以找到分解的代码
7.计算一组n维空间向量的协方差;
void cv::calcCovarMatrix(InputArray samples,
OutputArray covar,
InputOutputArray mean,
int flags,
int ctype = CV_64F
)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts
Parameters
samples samples stored as rows/columns of a single matrix.
covar output covariance matrix of the type ctype and square size.
mean input or output (depending on the flags) array as the average value of the input vectors.
flags operation flags as a combination of cv::CovarFlags
ctype type of the matrixl; it equals 'CV_64F' by default.
详细介绍:点击打开链接
8.对两个数组中的所有元素运用设置的比较操作;
void cv::compare(InputArray src1,
InputArray src2,
OutputArray dst,
int cmpop
)
Performs the per-element comparison of two arrays or an array and scalar value.
Parameters
src1 first input array or a scalar; when it is an array, it must have a single channel.
src2 second input array or a scalar; when it is an array, it must have a single channel.
dst output array of type ref CV_8U that has the same size and the same number of channels as the input arrays.
cmpop a flag, that specifies correspondence between the arrays (cv::CmpTypes)
9.计算可选的缩放值的绝对值之后再转换数组元素的类型;
void cv::convertScaleAbs(InputArray src,
OutputArray dst,
double alpha = 1,
double beta = 0
)
Scales, calculates absolute values, and converts the result to 8-bit.
Parameters
src | input array. |
dst | output array. |
alpha | optional scale factor. |
beta | optional delta added to the scaled values. |
10.计算数组中非0 个数;
int cv::countNonZero(InputArray src)
11.计算两个三维向量的向量积;
没有找到API 网上写 dst = src1 * src2 要满足矩阵相乘的规则;
12.将数组的通道从一个原色空间转换到另外一个颜色空间;
void cv::cvtColor ( InputArray src,
OutputArray dst,
int code,
int dstCn = 0
)
Converts an image from one color space to another.
Parameters
src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point.
dst output image of the same size and depth as src.
code color space conversion code (see cv::ColorConversionCodes).
dstCn number of channels in the destination image; if the parameter is 0, the number of the channels is derived automatically from src and code.
13.计算方阵的行列式;
double cvDet(const CvArr * mat)
14.用另外一个数组对一个数组进行元素级的除法运算;
void cvDiv(const CvArr * src1,
const CvArr * src2,
CvArr * dst,
double scale = 1
)
dst(idx) = src1(idx) * scale / src2(idx) or dst(idx) = scale / src2(idx) if src1 == 0
15.计算两个向量的点积;
double cvDotProduct(const CvArr * src1,
const CvArr * src2
)
Parameters
src1 The first source array
src2 The second source array
16.计算方阵的特征值和特征向量;
void cvEigenVV(CvArr * mat,
CvArr * evects,
CvArr * evals,
double eps = 0,
int lowindex = -1,
int highindex = -1
)
17.围绕选定轴翻转;
void cvFlip(const CvArr * src,
CvArr * dst = NULL,
int flip_mode = 0
)
18.矩阵乘法;
void cvGEMM(const CvArr * src1,
const CvArr * src2,
double alpha,
const CvArr * src3,
double beta,
CvArr * dst,
int tABC = 0
)
19.从一个数组的列中复制元素;
CvMat* cvGetCol(const CvArr * arr,
CvMat * submat,
int col
)
Parameters
arr Input array
submat Pointer to the resulting sub-array header
col Zero-based index of the selected column
20.从数据相邻的多列中复制元素值;
CvMat* cvGetCols(const CvArr * arr,
CvMat * submat,
int start_col,
int end_col
)
Parameters
arr Input array
submat Pointer to the resulting sub-array header
start_col Zero-based index of the starting column (inclusive) of the span
end_col Zero-based index of the ending column (exclusive) of the span
21.复制数组中对角线上的所有元素;
CvMat* cvGetDiag | ( | const CvArr * | arr, |
CvMat * | submat, | ||
int | diag = 0 | ||
) |
CvMat* cvGetDiag | ( | const CvArr * | arr, |
CvMat * | submat, | ||
int | diag = 0 | ||
) |
Parameters
arr | Input array |
submat | Pointer to the resulting sub-array header |
diag | Index of the array diagonal. Zero value corresponds to the main diagonal, -1 corresponds to the diagonal above the main, 1 corresponds to the diagonal below the main, and so forth. |
22.返回数组的维数;
int cvGetDims(const CvArr * arr,
int * sizes = NULL
)
Parameters
arr Input array
sizes Optional output vector of the array dimension sizes. For 2d arrays the number of rows (height) goes first, number of columns (width) next.
23:.返回一个数组所有维的大小;
int cvGetDimSize(const CvArr * arr,
int index
)
Parameters
arr Input array
index Zero-based dimension index (for matrices 0 means number of rows, 1 means number of columns; for images 0 means height, 1 means width)
24.从一个数组的行中复制元素;
CvMat* cvGetRow(const CvArr * arr,
CvMat * submat,
int row
)
Parameters
arr Input array
submat Pointer to the resulting sub-array header
row Zero-based index of the selected row
25.从一个数组的多个相邻行中复制元素;
CvMat* cvGetRows(const CvArr * arr,
CvMat * submat,
int start_row,
int end_row
)
Parameters
arr Input array
submat Pointer to the resulting sub-array header
start_row Zero-based index of the starting column (inclusive) of the span
end_row Zero-based index of the ending column (exclusive) of the span
26.得到二维数组的尺寸;
CvSize cvGetSize(const CvArr * arr)
27.将源图像复制到目标图像的中间;
void cv::copyMakeBorder | ( | InputArray | src, |
OutputArray | dst, | ||
int | top, | ||
int | bottom, | ||
int | left, | ||
int | right, | ||
int | borderType, | ||
const Scalar & | value = Scalar() | ||
) |
src | Source image. |
dst | Destination image of the same type as src and the size Size(src.cols+left+right, src.rows+top+bottom) . |
top | |
bottom | |
left | |
right | Parameter specifying how many pixels in each direction from the source image rectangle to extrapolate. For example, top=1, bottom=1, left=1, right=1 mean that 1 pixel-wide border needs to be built. |
borderType | Border type. See borderInterpolate for details. |
value | Border value if borderType==BORDER_CONSTANT . |
28.检查一个数组的元素是否在另外两个数组中的值的范围;
void cvInRange(const CvArr * src,
const CvArr * lower,
const CvArr * upper,
CvArr * dst
)
dst(idx) = lower(idx) <= src(idx) < upper(idx)
29.检查一个数组的元素的值是否在另外两个标量的范围内;
void cvInRangeS(const CvArr * src,
CvScalar lower,
CvScalar upper,
CvArr * dst
)
dst(idx) = lower <= src(idx) < upper
有点失误,莫名其妙就把图像处理混合进来了