Java 数值计算 (四) OpenCV
(2016-04-10 21:49:46)分类: Java |
OpenCV 3.0.0 java API:
http://docs.opencv.org/java/3.0.0/
http://docs.opencv.org/3.1.0/d3/d63/classcv_1_1Mat.html#gsc.tab=0
Mat:
静态方法:
static Mat diag(Mat
d)
// 对角矩阵 单列
static Mat eye(int rows, int cols, int
type)
// 构造单位矩阵形状的矩阵,可以不是方阵
static Mat eye(Size size, int
type)
// 构造单位矩阵形状的矩阵,可以不是方阵
static Mat ones(int rows, int cols, int
type)
// 构造全是1的矩阵
static Mat ones(Size size, int
type)
// 构造全是1的矩阵
static Mat zeros(int rows, int cols, int
type)
// 构造全是0的矩阵
static Mat zeros(Size size, int
type)
// 构造全是0的矩阵
构造方法:
Mat()
Mat(int rows, int cols, int
type)
Mat(int rows, int cols, int type, Scalar
s)
Mat(long addr)
Mat(Mat m, Range rowRange)
Mat(Mat m, Range rowRange, Range
colRange)
Mat(Mat m, Rect roi)
Mat(Size size, int type)
Mat(Size size, int type, Scalar s)
void create(int rows, int cols, int
type)
// 如果尺寸够,则直接返回,否则释放旧的,创建新的
void create(Size size, int type)
属性:
int
cols()
// 矩阵行数
int
rows()
// 矩阵列数
int
height()
// 图片高度 = cols()
int
width()
// 图片宽度 = rows()
int
dims()
// 矩阵维数 >=2
int
channels() //
矩阵元素通道数 1 或者 3
long dataAddr()
Size size()
int
depth()
// 元素深度标识
long total()
int type()
long getNativeObjAddr()
long
elemSize()
// 矩阵元素字节数大小 如3 = channels() * elemSize1()
long
elemSize1()
// 矩阵元素每个通路的字节数大小 如1
boolean
empty()
// 元素取值赋值
矩阵克隆:
矩阵运算:
Mat
diag()
// 主对角矩阵,一维, 当元素相同时,叫标量阵,当都是1时,是单位阵
Mat diag(int d)
at
inv()
// 矩阵求逆,非奇异性矩阵可逆
Mat inv(int
method)
Mat cross(Mat
m)
// 两个向量的差乘积
Mat mul(Mat
m)
// 元素层面的乘积计算
Mat mul(Mat m, double
scale)
// 元素层面的乘积计算, scale, 放大系数
double dot(Mat
m)
// 两矩阵点积, 各项乘积的和
Mat t()
// 转置 (transpose)
矩阵转置:
矩阵A (m*n) 的转置: B(n*m) = A^T, 其中,aij = bji。
性质: (A+-)^T = A^T +- B^T,
(A*B)^T = B^T * A^T
java.lang.String toString()
java.lang.String dump()
Core:
元素运算:
static void absdiff(Mat src1, Mat src2, Mat
dst)
// 元素级差绝对值
static void absdiff(Mat src1, Scalar src2, Mat
dst)
// 元素级差绝对值
static void max(Mat src1, Mat src2, Mat
dst)
static void max(Mat src1, Scalar src2, Mat
dst)
static void min(Mat src1, Mat src2, Mat
dst)
static void min(Mat src1, Scalar src2, Mat
dst)
static void compare(Mat src1, Mat src2, Mat dst, int
cmpop)
static void compare(Mat src1, Scalar src2, Mat dst, int
cmpop)
static void add(Mat src1, Mat src2, Mat
dst)
static void add(Mat src1, Mat src2, Mat dst, Mat
mask)
static void add(Mat src1, Mat src2, Mat dst, Mat mask, int
dtype)
static void add(Mat src1, Scalar src2, Mat
dst)
static void add(Mat src1, Scalar src2, Mat dst, Mat
mask)
static void add(Mat src1, Scalar src2, Mat dst, Mat mask, int
dtype)
伸缩相加
static void scaleAdd(Mat src1, double alpha, Mat src2, Mat
dst)
按权重相加, (src1 * alpha + src2 * beta + gamma. )
static void addWeighted(Mat src1, double alpha, Mat src2,
double beta, double gamma, Mat dst)
static void addWeighted(Mat src1, double alpha, Mat src2,
double beta, double gamma, Mat dst, int
dtype)
static void subtract(Mat src1, Mat src2, Mat
dst)
static void subtract(Mat src1, Mat src2, Mat dst, Mat
mask)
static void subtract(Mat src1, Mat src2, Mat dst, Mat mask,
int dtype)
static void subtract(Mat src1, Scalar src2, Mat
dst)
static void subtract(Mat src1, Scalar src2, Mat dst, Mat
mask)
static void subtract(Mat src1, Scalar src2, Mat dst, Mat mask,
int dtype)
static void multiply(Mat src1, Mat src2, Mat
dst)
// 元素级乘法
static void multiply(Mat src1, Mat src2, Mat dst, double
scale)
static void multiply(Mat src1, Mat src2, Mat dst, double
scale, int dtype)
static void multiply(Mat src1, Scalar src2, Mat
dst)
static void multiply(Mat src1, Scalar src2, Mat dst, double
scale)
static void multiply(Mat src1, Scalar src2, Mat dst, double
scale, int dtype)
static void divide(Mat src1, Mat src2, Mat
dst)
// 元素级除法
static void divide(Mat src1, Mat src2, Mat dst, double
scale)
static void divide(Mat src1, Mat src2, Mat dst, double scale,
int dtype)
static void divide(Mat src1, Scalar src2, Mat
dst)
static void divide(Mat src1, Scalar src2, Mat dst, double
scale)
static void divide(Mat src1, Scalar src2, Mat dst, double
scale, int dtype)
static void divide(double scale, Mat src2, Mat
dst)
static void divide(double scale, Mat src2, Mat dst, int
dtype)
static void bitwise_and(Mat src1, Mat src2, Mat
dst)
// 元素级位操作
static void bitwise_and(Mat src1, Mat src2, Mat dst, Mat
mask)
static void bitwise_not(Mat src, Mat
dst)
static void bitwise_not(Mat src, Mat dst, Mat
mask)
static void bitwise_or(Mat src1, Mat src2, Mat
dst)
static void bitwise_or(Mat src1, Mat src2, Mat dst, Mat
mask)
static void bitwise_xor(Mat src1, Mat src2, Mat
dst)
static void bitwise_xor(Mat src1, Mat src2, Mat dst, Mat
mask)
static void cartToPolar(Mat x, Mat y, Mat magnitude, Mat
angle)
// x,y 向量长度和夹角
static void cartToPolar(Mat x, Mat y, Mat magnitude, Mat
angle, boolean angleInDegrees)
x,y 向量长度
static void magnitude(Mat x, Mat y, Mat
magnitude)
x,y 向量夹角
static void phase(Mat x, Mat y, Mat
angle)
static void phase(Mat x, Mat y, Mat angle, boolean
angleInDegrees)
极坐标到一般坐标
static void polarToCart(Mat magnitude, Mat angle, Mat x, Mat
y)
static void polarToCart(Mat magnitude, Mat angle, Mat x, Mat
y, boolean angleInDegrees)
平方根,对数,指数,立方根,幂
static void sqrt(Mat src, Mat dst)
static void log(Mat src, Mat dst)
static void exp(Mat src, Mat dst)
static float cubeRoot(float val)
static void pow(Mat src, double power, Mat
dst)
矩阵合并
static void vconcat(java.util.List src, Mat dst)
static void hconcat(java.util.List src, Mat
dst)
static void merge(java.util.List mv, Mat
dst)
矩阵分解
static void split(Mat m, java.util.List
mv)
重复
static void repeat(Mat src, int ny, int nx, Mat
dst)
矩阵运算
矩阵对角初始化
static void setIdentity(Mat mtx)
static void setIdentity(Mat mtx, Scalar
s)
用随机数构造矩阵
static void randShuffle(Mat dst)
static void randShuffle(Mat dst, double
iterFactor)
用正态分布的随机数构造矩阵
static void randu(Mat dst, double low, double
high)
static void randn(Mat dst, double mean, double
stddev)
矩阵乘法:
static void gemm(Mat src1, Mat src2, double alpha, Mat src3,
double beta, Mat dst)
static void gemm(Mat src1, Mat src2, double alpha, Mat src3,
double beta, Mat dst, int flags)
计算行列式:
static double determinant(Mat mtx)
矩阵转换
static void transform(Mat src, Mat dst, Mat
m)
矩阵转置
static void transpose(Mat src, Mat
dst)
逆矩阵
static double invert(Mat src, Mat dst)
static double invert(Mat src, Mat dst, int
flags)
计算 马哈拉诺比斯距离
static double Mahalanobis(Mat v1, Mat v2, Mat
icovar)
计算矩阵的“迹”,即对角元素和
static Scalar trace(Mat mtx)
一个矩阵是否在另两个矩阵之间
static void inRange(Mat src, Scalar lowerb, Scalar upperb, Mat
dst)
// 范数
//
Core.NORM_INF
绝对值最大
//
Core.NORM_L1
绝对值值和
//
Core.NORM_L2
绝对值平方和开方
static double norm(Mat src1)
static double norm(Mat src1, int
normType)
static double norm(Mat src1, int normType, Mat
mask)
static double norm(Mat src1, Mat src2)
static double norm(Mat src1, Mat src2, int
normType)
static double norm(Mat src1, Mat src2, int normType, Mat
mask)
static void normalize(Mat src, Mat
dst)
static void normalize(Mat src, Mat dst, double alpha, double
beta, int norm_type)
static void normalize(Mat src, Mat dst, double alpha, double
beta, int norm_type, int dtype)
static void normalize(Mat src, Mat dst, double alpha, double
beta, int norm_type, int dtype, Mat mask)
计算矩阵和转置矩阵乘积
static void mulTransposed(Mat src, Mat dst, boolean
aTa)
static void mulTransposed(Mat src, Mat dst, boolean aTa, Mat
delta, double scale)
static void mulTransposed(Mat src, Mat dst, boolean aTa, Mat
delta, double scale, int dtype)
计算特征值及特征向量
static boolean eigen(Mat src, Mat
eigenvalues)
static boolean eigen(Mat src, Mat eigenvalues, Mat
eigenvectors)
均值
static Scalar mean(Mat
src)
// 计算均值
static Scalar mean(Mat src, Mat
mask) //
计算均值
static void meanStdDev(Mat src, MatOfDouble mean, MatOfDouble
stddev) // 计算均值和标准差
static void meanStdDev(Mat src, MatOfDouble mean, MatOfDouble
stddev, Mat mask) //
计算均值和
简单最近邻查找器
static void batchDistance(Mat src1, Mat src2, Mat dist, int
dtype, Mat nidx)
static void batchDistance(Mat src1, Mat src2, Mat dist, int
dtype, Mat nidx, int normType, int K)
static void batchDistance(Mat src1, Mat src2, Mat dist, int
dtype, Mat nidx, int normType, int K, Mat
mask, int update, boolean crosscheck)
static int borderInterpolate(int p, int len, int
borderType)
计算协方差矩阵
static void calcCovarMatrix(Mat samples, Mat covar, Mat mean,
int flags)
static void calcCovarMatrix(Mat samples, Mat covar, Mat mean,
int flags, int ctype)
透视变换
static void perspectiveTransform(Mat src, Mat dst, Mat
m)
static boolean checkRange(Mat a)
static boolean checkRange(Mat a, boolean quiet, double minVal,
double maxVal)
static void completeSymm(Mat mtx)
static void completeSymm(Mat mtx, boolean
lowerToUpper)
static void convertScaleAbs(Mat src, Mat
dst)
static void convertScaleAbs(Mat src, Mat dst, double alpha,
double beta)
static void copyMakeBorder(Mat src, Mat dst, int top, int
bottom, int left, int right, int
borderType)
static void copyMakeBorder(Mat src, Mat dst, int top, int
bottom, int left, int right, int borderType, Scalar
value)
static int countNonZero(Mat src)
正向或反向余弦变换
static void dct(Mat src, Mat dst)
static void dct(Mat src, Mat dst, int
flags)
反向离散正弦变换
static void idct(Mat src, Mat dst)
static void idct(Mat src, Mat dst, int
flags)
离散傅里叶变换
static void dft(Mat src, Mat dst)
static void dft(Mat src, Mat dst, int flags, int
nonzeroRows)
static int getOptimalDFTSize(int
vecsize)
反向离散傅里叶变换
static void idft(Mat src, Mat dst)
static void idft(Mat src, Mat dst, int flags, int
nonzeroRows)
元素傅里叶谱乘积
static void mulSpectrums(Mat a, Mat b, Mat c, int
flags)
static void mulSpectrums(Mat a, Mat b, Mat c, int flags,
boolean conjB)
static void extractChannel(Mat src, Mat dst, int
coi)
static float fastAtan2(float y, float
x)
static void findNonZero(Mat src, Mat
idx)
static void flip(Mat src, Mat dst, int
flipCode)
把矩阵转成向量
static void reduce(Mat src, Mat dst, int dim, int
rtype)
static void reduce(Mat src, Mat dst, int dim, int rtype, int
dtype)
线性方程组求解
static boolean solve(Mat src1, Mat src2, Mat
dst)
static boolean solve(Mat src1, Mat src2, Mat dst, int
flags)
static int solveCubic(Mat coeffs, Mat
roots)
static double solvePoly(Mat coeffs, Mat
roots)
static double solvePoly(Mat coeffs, Mat roots, int
maxIters)
计算机相关
static java.lang.String
getBuildInformation()
static long getCPUTickCount()
static int getNumberOfCPUs()
static long getTickCount()
static double getTickFrequency()
static void insertChannel(Mat src, Mat dst, int
coi)
K均值
static double kmeans(Mat data, int K, Mat bestLabels,
TermCriteria criteria, int attempts, int
flags)
static double kmeans(Mat data, int K, Mat bestLabels,
TermCriteria criteria, int attempts, int flags, Mat
centers)
奇异性值分解(SVD Singular
Value Decomposition)
static void SVBackSubst(Mat w, Mat u, Mat vt, Mat rhs, Mat
dst)
static void SVDecomp(Mat src, Mat w, Mat u, Mat
vt)
static void SVDecomp(Mat src, Mat w, Mat u, Mat vt, int
flags)
排序
static void sort(Mat src, Mat dst, int
flags)
static void sortIdx(Mat src, Mat dst, int
flags)
查找表 Look Up Table
static void LUT(Mat src, Mat lut, Mat
dst)
static Core.MinMaxLocResult minMaxLoc(Mat
src)
static Core.MinMaxLocResult minMaxLoc(Mat src, Mat
mask)
static void mixChannels(java.util.List src, java.util.List
dst, MatOfInt fromTo)
static void patchNaNs(Mat a)
static void patchNaNs(Mat a, double
val)
static void PCABackProject(Mat data, Mat mean, Mat
eigenvectors, Mat result)
static void PCACompute(Mat data, Mat mean, Mat
eigenvectors)
static void PCACompute(Mat data, Mat mean, Mat eigenvectors,
double retainedVariance)
static void PCACompute(Mat data, Mat mean, Mat eigenvectors,
int maxComponents)
static void PCAProject(Mat data, Mat mean, Mat eigenvectors,
Mat result)
static double PSNR(Mat src1, Mat src2)
static void setErrorVerbosity(boolean
verbose)
static Scalar sumElems(Mat src)
Mat 与 Java类型之间转换
org.opencv.utils.Converters
static void Mat_to_vector_char(Mat m, java.util.List bs)
static void Mat_to_vector_DMatch(Mat m, java.util.List matches)
static void Mat_to_vector_double(Mat m, java.util.List ds)
static void Mat_to_vector_float(Mat m, java.util.List fs)
static void Mat_to_vector_int(Mat m, java.util.List is)
static void Mat_to_vector_KeyPoint(Mat m, java.util.List kps)
static void Mat_to_vector_Mat(Mat m, java.util.List mats)
static void Mat_to_vector_Point(Mat m, java.util.List pts)
static void Mat_to_vector_Point2d(Mat m, java.util.List pts)
static void Mat_to_vector_Point2f(Mat m, java.util.List pts)
static void Mat_to_vector_Point3(Mat m, java.util.List pts)
static void Mat_to_vector_Point3d(Mat m, java.util.List pts)
static void Mat_to_vector_Point3f(Mat m, java.util.List pts)
static void Mat_to_vector_Point3i(Mat m, java.util.List pts)
static void Mat_to_vector_Rect(Mat m, java.util.List rs)
static void Mat_to_vector_uchar(Mat m, java.util.List us)
static void Mat_to_vector_vector_char(Mat m, java.util.List> llb)
static void Mat_to_vector_vector_DMatch(Mat m, java.util.List lvdm)
static void Mat_to_vector_vector_KeyPoint(Mat m, java.util.List kps)
static void Mat_to_vector_vector_Point(Mat m, java.util.List pts)
static void Mat_to_vector_vector_Point2f(Mat m, java.util.List pts)
static void Mat_to_vector_vector_Point3f(Mat m, java.util.List pts)
static void Mat_to_vector_DMatch(Mat m, java.util.List matches)
static void Mat_to_vector_double(Mat m, java.util.List ds)
static void Mat_to_vector_float(Mat m, java.util.List fs)
static void Mat_to_vector_int(Mat m, java.util.List is)
static void Mat_to_vector_KeyPoint(Mat m, java.util.List kps)
static void Mat_to_vector_Mat(Mat m, java.util.List mats)
static void Mat_to_vector_Point(Mat m, java.util.List pts)
static void Mat_to_vector_Point2d(Mat m, java.util.List pts)
static void Mat_to_vector_Point2f(Mat m, java.util.List pts)
static void Mat_to_vector_Point3(Mat m, java.util.List pts)
static void Mat_to_vector_Point3d(Mat m, java.util.List pts)
static void Mat_to_vector_Point3f(Mat m, java.util.List pts)
static void Mat_to_vector_Point3i(Mat m, java.util.List pts)
static void Mat_to_vector_Rect(Mat m, java.util.List rs)
static void Mat_to_vector_uchar(Mat m, java.util.List us)
static void Mat_to_vector_vector_char(Mat m, java.util.List> llb)
static void Mat_to_vector_vector_DMatch(Mat m, java.util.List lvdm)
static void Mat_to_vector_vector_KeyPoint(Mat m, java.util.List kps)
static void Mat_to_vector_vector_Point(Mat m, java.util.List pts)
static void Mat_to_vector_vector_Point2f(Mat m, java.util.List pts)
static void Mat_to_vector_vector_Point3f(Mat m, java.util.List pts)
static Mat vector_char_to_Mat(java.util.List bs)
static Mat vector_DMatch_to_Mat(java.util.List matches)
static Mat vector_double_to_Mat(java.util.List ds)
static Mat vector_float_to_Mat(java.util.List fs)
static Mat vector_int_to_Mat(java.util.List is)
static Mat vector_KeyPoint_to_Mat(java.util.List kps)
static Mat vector_Mat_to_Mat(java.util.List mats)
static Mat vector_Point_to_Mat(java.util.List pts)
static Mat vector_Point_to_Mat(java.util.List pts, int typeDepth)
static Mat vector_Point2d_to_Mat(java.util.List pts)
static Mat vector_Point2f_to_Mat(java.util.List pts)
static Mat vector_Point3_to_Mat(java.util.List pts, int typeDepth)
static Mat vector_Point3d_to_Mat(java.util.List pts)
static Mat vector_Point3f_to_Mat(java.util.List pts)
static Mat vector_Point3i_to_Mat(java.util.List pts)
static Mat vector_Rect_to_Mat(java.util.List rs)
static Mat vector_uchar_to_Mat(java.util.List bs)
static Mat vector_vector_char_to_Mat(java.util.List lvb, java.util.List mats)
static Mat vector_vector_DMatch_to_Mat(java.util.List lvdm, java.util.List mats)
static Mat vector_vector_KeyPoint_to_Mat(java.util.List kps, java.util.List mats)
static Mat vector_vector_Point_to_Mat(java.util.List pts, java.util.List mats)
static Mat vector_vector_Point2f_to_Mat(java.util.List pts, java.util.List mats)
static Mat vector_vector_Point3f_to_Mat(java.util.List pts, java.util.List mats)
static Mat vector_DMatch_to_Mat(java.util.List matches)
static Mat vector_double_to_Mat(java.util.List ds)
static Mat vector_float_to_Mat(java.util.List fs)
static Mat vector_int_to_Mat(java.util.List is)
static Mat vector_KeyPoint_to_Mat(java.util.List kps)
static Mat vector_Mat_to_Mat(java.util.List mats)
static Mat vector_Point_to_Mat(java.util.List pts)
static Mat vector_Point_to_Mat(java.util.List pts, int typeDepth)
static Mat vector_Point2d_to_Mat(java.util.List pts)
static Mat vector_Point2f_to_Mat(java.util.List pts)
static Mat vector_Point3_to_Mat(java.util.List pts, int typeDepth)
static Mat vector_Point3d_to_Mat(java.util.List pts)
static Mat vector_Point3f_to_Mat(java.util.List pts)
static Mat vector_Point3i_to_Mat(java.util.List pts)
static Mat vector_Rect_to_Mat(java.util.List rs)
static Mat vector_uchar_to_Mat(java.util.List bs)
static Mat vector_vector_char_to_Mat(java.util.List lvb, java.util.List mats)
static Mat vector_vector_DMatch_to_Mat(java.util.List lvdm, java.util.List mats)
static Mat vector_vector_KeyPoint_to_Mat(java.util.List kps, java.util.List mats)
static Mat vector_vector_Point_to_Mat(java.util.List pts, java.util.List mats)
static Mat vector_vector_Point2f_to_Mat(java.util.List pts, java.util.List mats)
static Mat vector_vector_Point3f_to_Mat(java.util.List pts, java.util.List mats)
后一篇:线性代数及应用【一】