attempts to 1, initialize labels each time using a custom algorithm, pass
them with the (flags
= KMEANS_USE_INITIAL_LABELS
)
flag, and then choose the best (most-compact) clustering.
Note:
data
- Data for clustering. An array of N-Dimensional points with float
coordinates is needed. Examples of this array can be:
Mat points(count, 2, CV_32F);
Mat points(count, 1, CV_32FC2);
Mat points(1, count, CV_32FC2);
std.vector points(sampleCount);
K
- Number of clusters to split the set by.bestLabels
- a bestLabelscriteria
- The algorithm termination criteria, that is, the maximum
number of iterations and/or the desired accuracy. The accuracy is specified
as criteria.epsilon
. As soon as each of the cluster centers
moves by less than criteria.epsilon
on some iteration, the
algorithm stops.attempts
- Flag to specify the number of times the algorithm is executed
using different initial labellings. The algorithm returns the labels that
yield the best compactness (see the last function parameter).flags
- Flag that can take the following values:
kmeans++
center initialization by
Arthur and Vassilvitskii [Arthur2007].
KMEANS_*_CENTERS
flag to specify
the exact method.
public static double kmeans(Mat data, int K, Mat bestLabels, TermCriteria criteria, int attempts, int flags, Mat centers)
Finds centers of clusters and groups input samples around the clusters.
The function kmeans
implements a k-means algorithm that finds
the centers of cluster_count
clusters and groups the input
samples around the clusters. As an output, labels_i contains a
0-based cluster index for the sample stored in the i^(th) row of the
samples
matrix.
The function returns the compactness measure that is computed as
sum _i|samples _i - centers _(labels _i)| ^2
after every attempt. The best (minimum) value is chosen and the corresponding
labels and the compactness value are returned by the function.
Basically, you can use only the core of the function, set the number of
attempts to 1, initialize labels each time using a custom algorithm, pass
them with the (flags
= KMEANS_USE_INITIAL_LABELS
)
flag, and then choose the best (most-compact) clustering.
Note:
data
- Data for clustering. An array of N-Dimensional points with float
coordinates is needed. Examples of this array can be:
Mat points(count, 2, CV_32F);
Mat points(count, 1, CV_32FC2);
Mat points(1, count, CV_32FC2);
std.vector points(sampleCount);
K
- Number of clusters to split the set by.bestLabels
- a bestLabelscriteria
- The algorithm termination criteria, that is, the maximum
number of iterations and/or the desired accuracy. The accuracy is specified
as criteria.epsilon
. As soon as each of the cluster centers
moves by less than criteria.epsilon
on some iteration, the
algorithm stops.attempts
- Flag to specify the number of times the algorithm is executed
using different initial labellings. The algorithm returns the labels that
yield the best compactness (see the last function parameter).flags
- Flag that can take the following values:
kmeans++
center initialization by
Arthur and Vassilvitskii [Arthur2007].
KMEANS_*_CENTERS
flag to specify
the exact method.
centers
- Output matrix of the cluster centers, one row per each cluster
center.public static void line(Mat img, Point pt1, Point pt2, Scalar color)
Draws a line segment connecting two points.
The function line
draws the line segment between
pt1
and pt2
points in the image. The line is
clipped by the image boundaries. For non-antialiased lines with integer
coordinates, the 8-connected or 4-connected Bresenham algorithm is used.
Thick lines are drawn with rounding endings.
Antialiased lines are drawn using Gaussian filtering. To specify the line
color, you may use the macro CV_RGB(r, g, b)
.
img
- Image.pt1
- First point of the line segment.pt2
- Second point of the line segment.color
- Line color.public static void line(Mat img, Point pt1, Point pt2, Scalar color, int thickness)
Draws a line segment connecting two points.
The function line
draws the line segment between
pt1
and pt2
points in the image. The line is
clipped by the image boundaries. For non-antialiased lines with integer
coordinates, the 8-connected or 4-connected Bresenham algorithm is used.
Thick lines are drawn with rounding endings.
Antialiased lines are drawn using Gaussian filtering. To specify the line
color, you may use the macro CV_RGB(r, g, b)
.
img
- Image.pt1
- First point of the line segment.pt2
- Second point of the line segment.color
- Line color.thickness
- Line thickness.public static void line(Mat img, Point pt1, Point pt2, Scalar color, int thickness, int lineType, int shift)
Draws a line segment connecting two points.
The function line
draws the line segment between
pt1
and pt2
points in the image. The line is
clipped by the image boundaries. For non-antialiased lines with integer
coordinates, the 8-connected or 4-connected Bresenham algorithm is used.
Thick lines are drawn with rounding endings.
Antialiased lines are drawn using Gaussian filtering. To specify the line
color, you may use the macro CV_RGB(r, g, b)
.
img
- Image.pt1
- First point of the line segment.pt2
- Second point of the line segment.color
- Line color.thickness
- Line thickness.lineType
- Type of the line:
shift
- Number of fractional bits in the point coordinates.public static void log(Mat src, Mat dst)
Calculates the natural logarithm of every array element.
The function log
calculates the natural logarithm of the
absolute value of every element of the input array:
dst(I) = log|src(I)| if src(I) != 0 ; C otherwise
where C
is a large negative number (about -700 in the current
implementation).
The maximum relative error is about 7e-6
for single-precision
input and less than 1e-10
for double-precision input. Special
values (NaN, Inf) are not handled.
src
- input array.dst
- output array of the same size and type as src
.cartToPolar(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
pow(org.opencv.core.Mat, double, org.opencv.core.Mat)
,
sqrt(org.opencv.core.Mat, org.opencv.core.Mat)
,
magnitude(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
polarToCart(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
exp(org.opencv.core.Mat, org.opencv.core.Mat)
,
phase(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
public static void LUT(Mat src, Mat lut, Mat dst)
Performs a look-up table transform of an array.
The function LUT
fills the output array with values from the
look-up table. Indices of the entries are taken from the input array. That
is, the function processes each element of src
as follows:
dst(I) <- lut(src(I) + d)
where
d = 0 if src has depth CV_8U; 128 if src has depth CV_8S
src
- input array of 8-bit elements.lut
- look-up table of 256 elements; in case of multi-channel input
array, the table should either have a single channel (in this case the same
table is used for all channels) or the same number of channels as in the
input array.dst
- output array of the same size and number of channels as
src
, and the same depth as lut
.Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
convertScaleAbs(org.opencv.core.Mat, org.opencv.core.Mat, double, double)
public static void LUT(Mat src, Mat lut, Mat dst, int interpolation)
Performs a look-up table transform of an array.
The function LUT
fills the output array with values from the
look-up table. Indices of the entries are taken from the input array. That
is, the function processes each element of src
as follows:
dst(I) <- lut(src(I) + d)
where
d = 0 if src has depth CV_8U; 128 if src has depth CV_8S
src
- input array of 8-bit elements.lut
- look-up table of 256 elements; in case of multi-channel input
array, the table should either have a single channel (in this case the same
table is used for all channels) or the same number of channels as in the
input array.dst
- output array of the same size and number of channels as
src
, and the same depth as lut
.interpolation
- a interpolationMat.convertTo(org.opencv.core.Mat, int, double, double)
,
convertScaleAbs(org.opencv.core.Mat, org.opencv.core.Mat, double, double)
public static void magnitude(Mat x, Mat y, Mat magnitude)
Calculates the magnitude of 2D vectors.
The function magnitude
calculates the magnitude of 2D vectors
formed from the corresponding elements of x
and y
arrays:
dst(I) = sqrt(x(I)^2 + y(I)^2)
x
- floating-point array of x-coordinates of the vectors.y
- floating-point array of y-coordinates of the vectors; it must have
the same size as x
.magnitude
- output array of the same size and type as x
.cartToPolar(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
phase(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
sqrt(org.opencv.core.Mat, org.opencv.core.Mat)
,
polarToCart(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
public static double Mahalanobis(Mat v1, Mat v2, Mat icovar)
Calculates the Mahalanobis distance between two vectors.
The function Mahalanobis
calculates and returns the weighted
distance between two vectors:
d(vec1, vec2)= sqrt(sum_(i,j)(icovar(i,j)*(vec1(I)-vec2(I))*(vec1(j)-vec2(j))))
The covariance matrix may be calculated using the "calcCovarMatrix" function
and then inverted using the "invert" function (preferably using the
DECOMP_SVD
method, as the most accurate).
v1
- a v1v2
- a v2icovar
- inverse covariance matrix.public static void max(Mat src1, Mat src2, Mat dst)
Calculates per-element maximum of two arrays or an array and a scalar.
The functions max
calculate the per-element maximum of two
arrays:
dst(I)= max(src1(I), src2(I))
or array and a scalar:
dst(I)= max(src1(I), value)
In the second variant, when the input array is multi-channel, each channel is
compared with value
independently.
The first 3 variants of the function listed above are actually a part of "MatrixExpressions". They return an expression object that can be further either transformed/ assigned to a matrix, or passed to a function, and so on.
src1
- first input array.src2
- second input array of the same size and type as src1
.dst
- output array of the same size and type as src1
.compare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
inRange(org.opencv.core.Mat, org.opencv.core.Scalar, org.opencv.core.Scalar, org.opencv.core.Mat)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
,
min(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void max(Mat src1, Scalar src2, Mat dst)
Calculates per-element maximum of two arrays or an array and a scalar.
The functions max
calculate the per-element maximum of two
arrays:
dst(I)= max(src1(I), src2(I))
or array and a scalar:
dst(I)= max(src1(I), value)
In the second variant, when the input array is multi-channel, each channel is
compared with value
independently.
The first 3 variants of the function listed above are actually a part of "MatrixExpressions". They return an expression object that can be further either transformed/ assigned to a matrix, or passed to a function, and so on.
src1
- first input array.src2
- second input array of the same size and type as src1
.dst
- output array of the same size and type as src1
.compare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
inRange(org.opencv.core.Mat, org.opencv.core.Scalar, org.opencv.core.Scalar, org.opencv.core.Mat)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
,
min(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static Scalar mean(Mat src)
Calculates an average (mean) of array elements.
The function mean
calculates the mean value M
of
array elements, independently for each channel, and return it:
N = sum(by: I: mask(I) != 0) 1 M_c = (sum(by: I: mask(I) != 0)(mtx(I)_c))/N
When all the mask elements are 0's, the functions return Scalar.all(0)
.
src
- input array that should have from 1 to 4 channels so that the
result can be stored in "Scalar_".countNonZero(org.opencv.core.Mat)
,
meanStdDev(org.opencv.core.Mat, org.opencv.core.MatOfDouble, org.opencv.core.MatOfDouble, org.opencv.core.Mat)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
public static Scalar mean(Mat src, Mat mask)
Calculates an average (mean) of array elements.
The function mean
calculates the mean value M
of
array elements, independently for each channel, and return it:
N = sum(by: I: mask(I) != 0) 1 M_c = (sum(by: I: mask(I) != 0)(mtx(I)_c))/N
When all the mask elements are 0's, the functions return Scalar.all(0)
.
src
- input array that should have from 1 to 4 channels so that the
result can be stored in "Scalar_".mask
- optional operation mask.countNonZero(org.opencv.core.Mat)
,
meanStdDev(org.opencv.core.Mat, org.opencv.core.MatOfDouble, org.opencv.core.MatOfDouble, org.opencv.core.Mat)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
public static void meanStdDev(Mat src, MatOfDouble mean, MatOfDouble stddev)
Calculates a mean and standard deviation of array elements.
The function meanStdDev
calculates the mean and the standard
deviation M
of array elements independently for each channel and
returns it via the output parameters:
N = sum(by: I, mask(I) != 0) 1 mean _c = (sum_(I: mask(I) != 0) src(I)_c)/(N) stddev _c = sqrt((sum_(I: mask(I) != 0)(src(I)_c - mean _c)^2)/(N))
When all the mask elements are 0's, the functions return mean=stddev=Scalar.all(0)
.
Note: The calculated standard deviation is only the diagonal of the complete
normalized covariance matrix. If the full matrix is needed, you can reshape
the multi-channel array M x N
to the single-channel array
M*N x mtx.channels()
(only possible when the matrix is
continuous) and then pass the matrix to "calcCovarMatrix".
src
- input array that should have from 1 to 4 channels so that the
results can be stored in "Scalar_" 's.mean
- output parameter: calculated mean value.stddev
- output parameter: calculateded standard deviation.countNonZero(org.opencv.core.Mat)
,
calcCovarMatrix(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int, int)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
,
mean(org.opencv.core.Mat, org.opencv.core.Mat)
public static void meanStdDev(Mat src, MatOfDouble mean, MatOfDouble stddev, Mat mask)
Calculates a mean and standard deviation of array elements.
The function meanStdDev
calculates the mean and the standard
deviation M
of array elements independently for each channel and
returns it via the output parameters:
N = sum(by: I, mask(I) != 0) 1 mean _c = (sum_(I: mask(I) != 0) src(I)_c)/(N) stddev _c = sqrt((sum_(I: mask(I) != 0)(src(I)_c - mean _c)^2)/(N))
When all the mask elements are 0's, the functions return mean=stddev=Scalar.all(0)
.
Note: The calculated standard deviation is only the diagonal of the complete
normalized covariance matrix. If the full matrix is needed, you can reshape
the multi-channel array M x N
to the single-channel array
M*N x mtx.channels()
(only possible when the matrix is
continuous) and then pass the matrix to "calcCovarMatrix".
src
- input array that should have from 1 to 4 channels so that the
results can be stored in "Scalar_" 's.mean
- output parameter: calculated mean value.stddev
- output parameter: calculateded standard deviation.mask
- optional operation mask.countNonZero(org.opencv.core.Mat)
,
calcCovarMatrix(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int, int)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
,
mean(org.opencv.core.Mat, org.opencv.core.Mat)
public static void merge(java.util.List<Mat> mv, Mat dst)
Creates one multichannel array out of several single-channel ones.
The functions merge
merge several arrays to make a single
multi-channel array. That is, each element of the output array will be a
concatenation of the elements of the input arrays, where elements of i-th
input array are treated as mv[i].channels()
-element vectors.
The function "split" does the reverse operation. If you need to shuffle channels in some other advanced way, use "mixChannels".
mv
- input array or vector of matrices to be merged; all the matrices in
mv
must have the same size and the same depth.dst
- output array of the same size and the same depth as
mv[0]
; The number of channels will be the total number of
channels in the matrix array.Mat.reshape(int, int)
,
mixChannels(java.util.List<org.opencv.core.Mat>, java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt)
,
split(org.opencv.core.Mat, java.util.List<org.opencv.core.Mat>)
public static void min(Mat src1, Mat src2, Mat dst)
Calculates per-element minimum of two arrays or an array and a scalar.
The functions min
calculate the per-element minimum of two
arrays:
dst(I)= min(src1(I), src2(I))
or array and a scalar:
dst(I)= min(src1(I), value)
In the second variant, when the input array is multi-channel, each channel is
compared with value
independently.
The first three variants of the function listed above are actually a part of "MatrixExpressions". They return the expression object that can be further either transformed/assigned to a matrix, or passed to a function, and so on.
src1
- first input array.src2
- second input array of the same size and type as src1
.dst
- output array of the same size and type as src1
.max(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
compare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
inRange(org.opencv.core.Mat, org.opencv.core.Scalar, org.opencv.core.Scalar, org.opencv.core.Mat)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
public static void min(Mat src1, Scalar src2, Mat dst)
Calculates per-element minimum of two arrays or an array and a scalar.
The functions min
calculate the per-element minimum of two
arrays:
dst(I)= min(src1(I), src2(I))
or array and a scalar:
dst(I)= min(src1(I), value)
In the second variant, when the input array is multi-channel, each channel is
compared with value
independently.
The first three variants of the function listed above are actually a part of "MatrixExpressions". They return the expression object that can be further either transformed/assigned to a matrix, or passed to a function, and so on.
src1
- first input array.src2
- second input array of the same size and type as src1
.dst
- output array of the same size and type as src1
.max(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
compare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
inRange(org.opencv.core.Mat, org.opencv.core.Scalar, org.opencv.core.Scalar, org.opencv.core.Mat)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
public static Core.MinMaxLocResult minMaxLoc(Mat src)
Finds the global minimum and maximum in an array.
The functions minMaxLoc
find the minimum and maximum element
values and their positions. The extremums are searched across the whole array
or, if mask
is not an empty array, in the specified array
region.
The functions do not work with multi-channel arrays. If you need to find minimum or maximum elements across all the channels, use "Mat.reshape" first to reinterpret the array as single-channel. Or you may extract the particular channel using either "extractImageCOI", or "mixChannels", or "split".
src
- input single-channel array.compare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
min(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
mixChannels(java.util.List<org.opencv.core.Mat>, java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt)
,
Mat.reshape(int, int)
,
split(org.opencv.core.Mat, java.util.List<org.opencv.core.Mat>)
,
max(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
inRange(org.opencv.core.Mat, org.opencv.core.Scalar, org.opencv.core.Scalar, org.opencv.core.Mat)
public static Core.MinMaxLocResult minMaxLoc(Mat src, Mat mask)
Finds the global minimum and maximum in an array.
The functions minMaxLoc
find the minimum and maximum element
values and their positions. The extremums are searched across the whole array
or, if mask
is not an empty array, in the specified array
region.
The functions do not work with multi-channel arrays. If you need to find minimum or maximum elements across all the channels, use "Mat.reshape" first to reinterpret the array as single-channel. Or you may extract the particular channel using either "extractImageCOI", or "mixChannels", or "split".
src
- input single-channel array.mask
- optional mask used to select a sub-array.compare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
min(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
mixChannels(java.util.List<org.opencv.core.Mat>, java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt)
,
Mat.reshape(int, int)
,
split(org.opencv.core.Mat, java.util.List<org.opencv.core.Mat>)
,
max(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
inRange(org.opencv.core.Mat, org.opencv.core.Scalar, org.opencv.core.Scalar, org.opencv.core.Mat)
public static void mixChannels(java.util.List<Mat> src, java.util.List<Mat> dst, MatOfInt fromTo)
Copies specified channels from input arrays to the specified channels of output arrays.
The functions mixChannels
provide an advanced mechanism for
shuffling image channels.
"split" and "merge" and some forms of "cvtColor" are partial cases of
mixChannels
.
In the example below, the code splits a 4-channel RGBA image into a 3-channel
BGR (with R and B channels swapped) and a separate alpha-channel image:
// C++ code:
Mat rgba(100, 100, CV_8UC4, Scalar(1,2,3,4));
Mat bgr(rgba.rows, rgba.cols, CV_8UC3);
Mat alpha(rgba.rows, rgba.cols, CV_8UC1);
// forming an array of matrices is a quite efficient operation,
// because the matrix data is not copied, only the headers
Mat out[] = { bgr, alpha };
// rgba[0] -> bgr[2], rgba[1] -> bgr[1],
// rgba[2] -> bgr[0], rgba[3] -> alpha[0]
int from_to[] = { 0,2, 1,1, 2,0, 3,3 };
mixChannels(&rgba, 1, out, 2, from_to, 4);
Note: Unlike many other new-style C++ functions in OpenCV (see the
introduction section and "Mat.create"), mixChannels
requires
the output arrays to be pre-allocated before calling the function.
src
- input array or vector of matricesl; all of the matrices must have
the same size and the same depth.dst
- output array or vector of matrices; all the matrices *must be
allocated*; their size and depth must be the same as in src[0]
.fromTo
- array of index pairs specifying which channels are copied and
where; fromTo[k*2]
is a 0-based index of the input channel in
src
, fromTo[k*2+1]
is an index of the output
channel in dst
; the continuous channel numbering is used: the
first input image channels are indexed from 0
to
src[0].channels()-1
, the second input image channels are indexed
from src[0].channels()
to src[0].channels() +
src[1].channels()-1
, and so on, the same scheme is used for the output
image channels; as a special case, when fromTo[k*2]
is negative,
the corresponding output channel is filled with zero.merge(java.util.List<org.opencv.core.Mat>, org.opencv.core.Mat)
,
split(org.opencv.core.Mat, java.util.List<org.opencv.core.Mat>)
,
Imgproc.cvtColor(org.opencv.core.Mat, org.opencv.core.Mat, int, int)
public static void mulSpectrums(Mat a, Mat b, Mat c, int flags)
Performs the per-element multiplication of two Fourier spectrums.
The function mulSpectrums
performs the per-element
multiplication of the two CCS-packed or complex matrices that are results of
a real or complex Fourier transform.
The function, together with "dft" and "idft", may be used to calculate
convolution (pass conjB=false
) or correlation (pass
conjB=true
) of two arrays rapidly. When the arrays are complex,
they are simply multiplied (per element) with an optional conjugation of the
second-array elements. When the arrays are real, they are assumed to be
CCS-packed (see "dft" for details).
a
- a ab
- a bc
- a cflags
- operation flags; currently, the only supported flag is
DFT_ROWS
, which indicates that each row of src1
and
src2
is an independent 1D Fourier spectrum. If you do not want
to use this flag, then simply add a "0" as value.public static void mulSpectrums(Mat a, Mat b, Mat c, int flags, boolean conjB)
Performs the per-element multiplication of two Fourier spectrums.
The function mulSpectrums
performs the per-element
multiplication of the two CCS-packed or complex matrices that are results of
a real or complex Fourier transform.
The function, together with "dft" and "idft", may be used to calculate
convolution (pass conjB=false
) or correlation (pass
conjB=true
) of two arrays rapidly. When the arrays are complex,
they are simply multiplied (per element) with an optional conjugation of the
second-array elements. When the arrays are real, they are assumed to be
CCS-packed (see "dft" for details).
a
- a ab
- a bc
- a cflags
- operation flags; currently, the only supported flag is
DFT_ROWS
, which indicates that each row of src1
and
src2
is an independent 1D Fourier spectrum. If you do not want
to use this flag, then simply add a "0" as value.conjB
- optional flag that conjugates the second input array before the
multiplication (true) or not (false).public static void multiply(Mat src1, Mat src2, Mat dst)
Calculates the per-element scaled product of two arrays.
The function multiply
calculates the per-element product of two
arrays:
dst(I)= saturate(scale * src1(I) * src2(I))
There is also a "MatrixExpressions" -friendly variant of the first function. See "Mat.mul".
For a not-per-element matrix product, see "gemm".
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.dst
- output array of the same size and type as src1
.divide(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double, int)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateSquare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.accumulate(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
subtract(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateProduct(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void multiply(Mat src1, Mat src2, Mat dst, double scale)
Calculates the per-element scaled product of two arrays.
The function multiply
calculates the per-element product of two
arrays:
dst(I)= saturate(scale * src1(I) * src2(I))
There is also a "MatrixExpressions" -friendly variant of the first function. See "Mat.mul".
For a not-per-element matrix product, see "gemm".
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.dst
- output array of the same size and type as src1
.scale
- optional scale factor.divide(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double, int)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateSquare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.accumulate(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
subtract(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateProduct(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void multiply(Mat src1, Mat src2, Mat dst, double scale, int dtype)
Calculates the per-element scaled product of two arrays.
The function multiply
calculates the per-element product of two
arrays:
dst(I)= saturate(scale * src1(I) * src2(I))
There is also a "MatrixExpressions" -friendly variant of the first function. See "Mat.mul".
For a not-per-element matrix product, see "gemm".
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.dst
- output array of the same size and type as src1
.scale
- optional scale factor.dtype
- a dtypedivide(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double, int)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateSquare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.accumulate(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
subtract(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateProduct(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void multiply(Mat src1, Scalar src2, Mat dst)
Calculates the per-element scaled product of two arrays.
The function multiply
calculates the per-element product of two
arrays:
dst(I)= saturate(scale * src1(I) * src2(I))
There is also a "MatrixExpressions" -friendly variant of the first function. See "Mat.mul".
For a not-per-element matrix product, see "gemm".
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.dst
- output array of the same size and type as src1
.divide(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double, int)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateSquare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.accumulate(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
subtract(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateProduct(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void multiply(Mat src1, Scalar src2, Mat dst, double scale)
Calculates the per-element scaled product of two arrays.
The function multiply
calculates the per-element product of two
arrays:
dst(I)= saturate(scale * src1(I) * src2(I))
There is also a "MatrixExpressions" -friendly variant of the first function. See "Mat.mul".
For a not-per-element matrix product, see "gemm".
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.dst
- output array of the same size and type as src1
.scale
- optional scale factor.divide(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double, int)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateSquare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.accumulate(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
subtract(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateProduct(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void multiply(Mat src1, Scalar src2, Mat dst, double scale, int dtype)
Calculates the per-element scaled product of two arrays.
The function multiply
calculates the per-element product of two
arrays:
dst(I)= saturate(scale * src1(I) * src2(I))
There is also a "MatrixExpressions" -friendly variant of the first function. See "Mat.mul".
For a not-per-element matrix product, see "gemm".
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.dst
- output array of the same size and type as src1
.scale
- optional scale factor.dtype
- a dtypedivide(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, double, int)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateSquare(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.accumulate(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
subtract(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
Imgproc.accumulateProduct(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void mulTransposed(Mat src, Mat dst, boolean aTa)
Calculates the product of a matrix and its transposition.
The function mulTransposed
calculates the product of
src
and its transposition:
dst = scale(src - delta)^T(src - delta)
if aTa=true
, and
dst = scale(src - delta)(src - delta)^T
otherwise. The function is used to calculate the covariance matrix. With zero
delta, it can be used as a faster substitute for general matrix product
A*B
when B=A'
src
- input single-channel matrix. Note that unlike "gemm", the function
can multiply not only floating-point matrices.dst
- output square matrix.aTa
- Flag specifying the multiplication ordering. See the description
below.calcCovarMatrix(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int, int)
,
repeat(org.opencv.core.Mat, int, int, org.opencv.core.Mat)
,
reduce(org.opencv.core.Mat, org.opencv.core.Mat, int, int, int)
,
gemm(org.opencv.core.Mat, org.opencv.core.Mat, double, org.opencv.core.Mat, double, org.opencv.core.Mat, int)
public static void mulTransposed(Mat src, Mat dst, boolean aTa, Mat delta, double scale)
Calculates the product of a matrix and its transposition.
The function mulTransposed
calculates the product of
src
and its transposition:
dst = scale(src - delta)^T(src - delta)
if aTa=true
, and
dst = scale(src - delta)(src - delta)^T
otherwise. The function is used to calculate the covariance matrix. With zero
delta, it can be used as a faster substitute for general matrix product
A*B
when B=A'
src
- input single-channel matrix. Note that unlike "gemm", the function
can multiply not only floating-point matrices.dst
- output square matrix.aTa
- Flag specifying the multiplication ordering. See the description
below.delta
- Optional delta matrix subtracted from src
before
the multiplication. When the matrix is empty (delta=noArray()
),
it is assumed to be zero, that is, nothing is subtracted. If it has the same
size as src
, it is simply subtracted. Otherwise, it is
"repeated" (see "repeat") to cover the full src
and then
subtracted. Type of the delta matrix, when it is not empty, must be the same
as the type of created output matrix. See the dtype
parameter
description below.scale
- Optional scale factor for the matrix product.calcCovarMatrix(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int, int)
,
repeat(org.opencv.core.Mat, int, int, org.opencv.core.Mat)
,
reduce(org.opencv.core.Mat, org.opencv.core.Mat, int, int, int)
,
gemm(org.opencv.core.Mat, org.opencv.core.Mat, double, org.opencv.core.Mat, double, org.opencv.core.Mat, int)
public static void mulTransposed(Mat src, Mat dst, boolean aTa, Mat delta, double scale, int dtype)
Calculates the product of a matrix and its transposition.
The function mulTransposed
calculates the product of
src
and its transposition:
dst = scale(src - delta)^T(src - delta)
if aTa=true
, and
dst = scale(src - delta)(src - delta)^T
otherwise. The function is used to calculate the covariance matrix. With zero
delta, it can be used as a faster substitute for general matrix product
A*B
when B=A'
src
- input single-channel matrix. Note that unlike "gemm", the function
can multiply not only floating-point matrices.dst
- output square matrix.aTa
- Flag specifying the multiplication ordering. See the description
below.delta
- Optional delta matrix subtracted from src
before
the multiplication. When the matrix is empty (delta=noArray()
),
it is assumed to be zero, that is, nothing is subtracted. If it has the same
size as src
, it is simply subtracted. Otherwise, it is
"repeated" (see "repeat") to cover the full src
and then
subtracted. Type of the delta matrix, when it is not empty, must be the same
as the type of created output matrix. See the dtype
parameter
description below.scale
- Optional scale factor for the matrix product.dtype
- Optional type of the output matrix. When it is negative, the
output matrix will have the same type as src
. Otherwise, it will
be type=CV_MAT_DEPTH(dtype)
that should be either
CV_32F
or CV_64F
.calcCovarMatrix(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int, int)
,
repeat(org.opencv.core.Mat, int, int, org.opencv.core.Mat)
,
reduce(org.opencv.core.Mat, org.opencv.core.Mat, int, int, int)
,
gemm(org.opencv.core.Mat, org.opencv.core.Mat, double, org.opencv.core.Mat, double, org.opencv.core.Mat, int)
public static double norm(Mat src1)
Calculates an absolute array norm, an absolute difference norm, or a relative difference norm.
The functions norm
calculate an absolute norm of
src1
(when there is no src2
):
norm = forkthree(|src1|_(L_(infty)) = max _I|src1(I)|)(if normType = NORM_INF)<BR>(|src1|_(L_1) = sum _I|src1(I)|)(if normType = NORM_L1)<BR>(|src1|_(L_2) = sqrt(sum_I src1(I)^2))(if normType = NORM_L2)
or an absolute or relative difference norm if src2
is there:
norm = forkthree(|src1-src2|_(L_(infty)) = max _I|src1(I) - src2(I)|)(if normType = NORM_INF)<BR>(|src1 - src2|_(L_1) = sum _I|src1(I) - src2(I)|)(if normType = NORM_L1)<BR>(|src1 - src2|_(L_2) = sqrt(sum_I(src1(I) - src2(I))^2))(if normType = NORM_L2)
or
norm = forkthree((|src1-src2|_(L_(infty)))/(|src2|_(L_(infty))))(if normType = NORM_RELATIVE_INF)<BR>((|src1-src2|_(L_1))/(|src2|_(L_1)))(if normType = NORM_RELATIVE_L1)<BR>((|src1-src2|_(L_2))/(|src2|_(L_2)))(if normType = NORM_RELATIVE_L2)
The functions norm
return the calculated norm.
When the mask
parameter is specified and it is not empty, the
norm is calculated only over the region specified by the mask.
A multi-channel input arrays are treated as a single-channel, that is, the results for all channels are combined.
src1
- first input array.public static double norm(Mat src1, int normType)
Calculates an absolute array norm, an absolute difference norm, or a relative difference norm.
The functions norm
calculate an absolute norm of
src1
(when there is no src2
):
norm = forkthree(|src1|_(L_(infty)) = max _I|src1(I)|)(if normType = NORM_INF)<BR>(|src1|_(L_1) = sum _I|src1(I)|)(if normType = NORM_L1)<BR>(|src1|_(L_2) = sqrt(sum_I src1(I)^2))(if normType = NORM_L2)
or an absolute or relative difference norm if src2
is there:
norm = forkthree(|src1-src2|_(L_(infty)) = max _I|src1(I) - src2(I)|)(if normType = NORM_INF)<BR>(|src1 - src2|_(L_1) = sum _I|src1(I) - src2(I)|)(if normType = NORM_L1)<BR>(|src1 - src2|_(L_2) = sqrt(sum_I(src1(I) - src2(I))^2))(if normType = NORM_L2)
or
norm = forkthree((|src1-src2|_(L_(infty)))/(|src2|_(L_(infty))))(if normType = NORM_RELATIVE_INF)<BR>((|src1-src2|_(L_1))/(|src2|_(L_1)))(if normType = NORM_RELATIVE_L1)<BR>((|src1-src2|_(L_2))/(|src2|_(L_2)))(if normType = NORM_RELATIVE_L2)
The functions norm
return the calculated norm.
When the mask
parameter is specified and it is not empty, the
norm is calculated only over the region specified by the mask.
A multi-channel input arrays are treated as a single-channel, that is, the results for all channels are combined.
src1
- first input array.normType
- type of the norm (see the details below).public static double norm(Mat src1, int normType, Mat mask)
Calculates an absolute array norm, an absolute difference norm, or a relative difference norm.
The functions norm
calculate an absolute norm of
src1
(when there is no src2
):
norm = forkthree(|src1|_(L_(infty)) = max _I|src1(I)|)(if normType = NORM_INF)<BR>(|src1|_(L_1) = sum _I|src1(I)|)(if normType = NORM_L1)<BR>(|src1|_(L_2) = sqrt(sum_I src1(I)^2))(if normType = NORM_L2)
or an absolute or relative difference norm if src2
is there:
norm = forkthree(|src1-src2|_(L_(infty)) = max _I|src1(I) - src2(I)|)(if normType = NORM_INF)<BR>(|src1 - src2|_(L_1) = sum _I|src1(I) - src2(I)|)(if normType = NORM_L1)<BR>(|src1 - src2|_(L_2) = sqrt(sum_I(src1(I) - src2(I))^2))(if normType = NORM_L2)
or
norm = forkthree((|src1-src2|_(L_(infty)))/(|src2|_(L_(infty))))(if normType = NORM_RELATIVE_INF)<BR>((|src1-src2|_(L_1))/(|src2|_(L_1)))(if normType = NORM_RELATIVE_L1)<BR>((|src1-src2|_(L_2))/(|src2|_(L_2)))(if normType = NORM_RELATIVE_L2)
The functions norm
return the calculated norm.
When the mask
parameter is specified and it is not empty, the
norm is calculated only over the region specified by the mask.
A multi-channel input arrays are treated as a single-channel, that is, the results for all channels are combined.
src1
- first input array.normType
- type of the norm (see the details below).mask
- optional operation mask; it must have the same size as
src1
and CV_8UC1
type.public static double norm(Mat src1, Mat src2)
Calculates an absolute array norm, an absolute difference norm, or a relative difference norm.
The functions norm
calculate an absolute norm of
src1
(when there is no src2
):
norm = forkthree(|src1|_(L_(infty)) = max _I|src1(I)|)(if normType = NORM_INF)<BR>(|src1|_(L_1) = sum _I|src1(I)|)(if normType = NORM_L1)<BR>(|src1|_(L_2) = sqrt(sum_I src1(I)^2))(if normType = NORM_L2)
or an absolute or relative difference norm if src2
is there:
norm = forkthree(|src1-src2|_(L_(infty)) = max _I|src1(I) - src2(I)|)(if normType = NORM_INF)<BR>(|src1 - src2|_(L_1) = sum _I|src1(I) - src2(I)|)(if normType = NORM_L1)<BR>(|src1 - src2|_(L_2) = sqrt(sum_I(src1(I) - src2(I))^2))(if normType = NORM_L2)
or
norm = forkthree((|src1-src2|_(L_(infty)))/(|src2|_(L_(infty))))(if normType = NORM_RELATIVE_INF)<BR>((|src1-src2|_(L_1))/(|src2|_(L_1)))(if normType = NORM_RELATIVE_L1)<BR>((|src1-src2|_(L_2))/(|src2|_(L_2)))(if normType = NORM_RELATIVE_L2)
The functions norm
return the calculated norm.
When the mask
parameter is specified and it is not empty, the
norm is calculated only over the region specified by the mask.
A multi-channel input arrays are treated as a single-channel, that is, the results for all channels are combined.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.public static double norm(Mat src1, Mat src2, int normType)
Calculates an absolute array norm, an absolute difference norm, or a relative difference norm.
The functions norm
calculate an absolute norm of
src1
(when there is no src2
):
norm = forkthree(|src1|_(L_(infty)) = max _I|src1(I)|)(if normType = NORM_INF)<BR>(|src1|_(L_1) = sum _I|src1(I)|)(if normType = NORM_L1)<BR>(|src1|_(L_2) = sqrt(sum_I src1(I)^2))(if normType = NORM_L2)
or an absolute or relative difference norm if src2
is there:
norm = forkthree(|src1-src2|_(L_(infty)) = max _I|src1(I) - src2(I)|)(if normType = NORM_INF)<BR>(|src1 - src2|_(L_1) = sum _I|src1(I) - src2(I)|)(if normType = NORM_L1)<BR>(|src1 - src2|_(L_2) = sqrt(sum_I(src1(I) - src2(I))^2))(if normType = NORM_L2)
or
norm = forkthree((|src1-src2|_(L_(infty)))/(|src2|_(L_(infty))))(if normType = NORM_RELATIVE_INF)<BR>((|src1-src2|_(L_1))/(|src2|_(L_1)))(if normType = NORM_RELATIVE_L1)<BR>((|src1-src2|_(L_2))/(|src2|_(L_2)))(if normType = NORM_RELATIVE_L2)
The functions norm
return the calculated norm.
When the mask
parameter is specified and it is not empty, the
norm is calculated only over the region specified by the mask.
A multi-channel input arrays are treated as a single-channel, that is, the results for all channels are combined.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.normType
- type of the norm (see the details below).public static double norm(Mat src1, Mat src2, int normType, Mat mask)
Calculates an absolute array norm, an absolute difference norm, or a relative difference norm.
The functions norm
calculate an absolute norm of
src1
(when there is no src2
):
norm = forkthree(|src1|_(L_(infty)) = max _I|src1(I)|)(if normType = NORM_INF)<BR>(|src1|_(L_1) = sum _I|src1(I)|)(if normType = NORM_L1)<BR>(|src1|_(L_2) = sqrt(sum_I src1(I)^2))(if normType = NORM_L2)
or an absolute or relative difference norm if src2
is there:
norm = forkthree(|src1-src2|_(L_(infty)) = max _I|src1(I) - src2(I)|)(if normType = NORM_INF)<BR>(|src1 - src2|_(L_1) = sum _I|src1(I) - src2(I)|)(if normType = NORM_L1)<BR>(|src1 - src2|_(L_2) = sqrt(sum_I(src1(I) - src2(I))^2))(if normType = NORM_L2)
or
norm = forkthree((|src1-src2|_(L_(infty)))/(|src2|_(L_(infty))))(if normType = NORM_RELATIVE_INF)<BR>((|src1-src2|_(L_1))/(|src2|_(L_1)))(if normType = NORM_RELATIVE_L1)<BR>((|src1-src2|_(L_2))/(|src2|_(L_2)))(if normType = NORM_RELATIVE_L2)
The functions norm
return the calculated norm.
When the mask
parameter is specified and it is not empty, the
norm is calculated only over the region specified by the mask.
A multi-channel input arrays are treated as a single-channel, that is, the results for all channels are combined.
src1
- first input array.src2
- second input array of the same size and the same type as
src1
.normType
- type of the norm (see the details below).mask
- optional operation mask; it must have the same size as
src1
and CV_8UC1
type.public static void normalize(Mat src, Mat dst)
Normalizes the norm or value range of an array.
The functions normalize
scale and shift the input array elements
so that
| dst|_(L_p)= alpha
(where p=Inf, 1 or 2) when normType=NORM_INF
, NORM_L1
,
or NORM_L2
, respectively; or so that
min _I dst(I)= alpha, max _I dst(I)= beta
when normType=NORM_MINMAX
(for dense arrays only).
The optional mask specifies a sub-array to be normalized. This means that the
norm or min-n-max are calculated over the sub-array, and then this sub-array
is modified to be normalized. If you want to only use the mask to calculate
the norm or min-max but modify the whole array, you can use "norm" and
"Mat.convertTo".
In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, the range transformation for sparse matrices is not allowed since it can shift the zero level.
src
- input array.dst
- output array of the same size as src
.Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
public static void normalize(Mat src, Mat dst, double alpha, double beta, int norm_type)
Normalizes the norm or value range of an array.
The functions normalize
scale and shift the input array elements
so that
| dst|_(L_p)= alpha
(where p=Inf, 1 or 2) when normType=NORM_INF
, NORM_L1
,
or NORM_L2
, respectively; or so that
min _I dst(I)= alpha, max _I dst(I)= beta
when normType=NORM_MINMAX
(for dense arrays only).
The optional mask specifies a sub-array to be normalized. This means that the
norm or min-n-max are calculated over the sub-array, and then this sub-array
is modified to be normalized. If you want to only use the mask to calculate
the norm or min-max but modify the whole array, you can use "norm" and
"Mat.convertTo".
In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, the range transformation for sparse matrices is not allowed since it can shift the zero level.
src
- input array.dst
- output array of the same size as src
.alpha
- norm value to normalize to or the lower range boundary in case
of the range normalization.beta
- upper range boundary in case of the range normalization; it is
not used for the norm normalization.norm_type
- a norm_typeMat.convertTo(org.opencv.core.Mat, int, double, double)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
public static void normalize(Mat src, Mat dst, double alpha, double beta, int norm_type, int dtype)
Normalizes the norm or value range of an array.
The functions normalize
scale and shift the input array elements
so that
| dst|_(L_p)= alpha
(where p=Inf, 1 or 2) when normType=NORM_INF
, NORM_L1
,
or NORM_L2
, respectively; or so that
min _I dst(I)= alpha, max _I dst(I)= beta
when normType=NORM_MINMAX
(for dense arrays only).
The optional mask specifies a sub-array to be normalized. This means that the
norm or min-n-max are calculated over the sub-array, and then this sub-array
is modified to be normalized. If you want to only use the mask to calculate
the norm or min-max but modify the whole array, you can use "norm" and
"Mat.convertTo".
In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, the range transformation for sparse matrices is not allowed since it can shift the zero level.
src
- input array.dst
- output array of the same size as src
.alpha
- norm value to normalize to or the lower range boundary in case
of the range normalization.beta
- upper range boundary in case of the range normalization; it is
not used for the norm normalization.norm_type
- a norm_typedtype
- when negative, the output array has the same type as
src
; otherwise, it has the same number of channels as
src
and the depth =CV_MAT_DEPTH(dtype)
.Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
public static void normalize(Mat src, Mat dst, double alpha, double beta, int norm_type, int dtype, Mat mask)
Normalizes the norm or value range of an array.
The functions normalize
scale and shift the input array elements
so that
| dst|_(L_p)= alpha
(where p=Inf, 1 or 2) when normType=NORM_INF
, NORM_L1
,
or NORM_L2
, respectively; or so that
min _I dst(I)= alpha, max _I dst(I)= beta
when normType=NORM_MINMAX
(for dense arrays only).
The optional mask specifies a sub-array to be normalized. This means that the
norm or min-n-max are calculated over the sub-array, and then this sub-array
is modified to be normalized. If you want to only use the mask to calculate
the norm or min-max but modify the whole array, you can use "norm" and
"Mat.convertTo".
In case of sparse matrices, only the non-zero values are analyzed and transformed. Because of this, the range transformation for sparse matrices is not allowed since it can shift the zero level.
src
- input array.dst
- output array of the same size as src
.alpha
- norm value to normalize to or the lower range boundary in case
of the range normalization.beta
- upper range boundary in case of the range normalization; it is
not used for the norm normalization.norm_type
- a norm_typedtype
- when negative, the output array has the same type as
src
; otherwise, it has the same number of channels as
src
and the depth =CV_MAT_DEPTH(dtype)
.mask
- optional operation mask.Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
public static void patchNaNs(Mat a)
public static void patchNaNs(Mat a, double val)
public static void PCAComputeVar(Mat data, Mat mean, Mat eigenvectors, double retainedVariance)
public static void perspectiveTransform(Mat src, Mat dst, Mat m)
Performs the perspective matrix transformation of vectors.
The function perspectiveTransform
transforms every element of
src
by treating it as a 2D or 3D vector, in the following way:
(x, y, z) -> (x'/w, y'/w, z'/w)
where
(x', y', z', w') = mat * x y z 1
and
w = w' if w' != 0; infty otherwise
Here a 3D vector transformation is shown. In case of a 2D vector
transformation, the z
component is omitted.
Note: The function transforms a sparse set of 2D or 3D vectors. If you want to transform an image using perspective transformation, use "warpPerspective". If you have an inverse problem, that is, you want to compute the most probable perspective transformation out of several pairs of corresponding points, you can use "getPerspectiveTransform" or "findHomography".
src
- input two-channel or three-channel floating-point array; each
element is a 2D/3D vector to be transformed.dst
- output array of the same size and type as src
.m
- 3x3
or 4x4
floating-point transformation
matrix.Calib3d.findHomography(org.opencv.core.MatOfPoint2f, org.opencv.core.MatOfPoint2f, int, double, org.opencv.core.Mat)
,
Imgproc.warpPerspective(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Size, int, int, org.opencv.core.Scalar)
,
transform(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.getPerspectiveTransform(org.opencv.core.Mat, org.opencv.core.Mat)
public static void phase(Mat x, Mat y, Mat angle)
Calculates the rotation angle of 2D vectors.
The function phase
calculates the rotation angle of each 2D
vector that is formed from the corresponding elements of x
and
y
:
angle(I) = atan2(y(I), x(I))
The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0
,
the corresponding angle(I)
is set to 0.
x
- input floating-point array of x-coordinates of 2D vectors.y
- input array of y-coordinates of 2D vectors; it must have the same
size and the same type as x
.angle
- output array of vector angles; it has the same size and same
type as x
.public static void phase(Mat x, Mat y, Mat angle, boolean angleInDegrees)
Calculates the rotation angle of 2D vectors.
The function phase
calculates the rotation angle of each 2D
vector that is formed from the corresponding elements of x
and
y
:
angle(I) = atan2(y(I), x(I))
The angle estimation accuracy is about 0.3 degrees. When x(I)=y(I)=0
,
the corresponding angle(I)
is set to 0.
x
- input floating-point array of x-coordinates of 2D vectors.y
- input array of y-coordinates of 2D vectors; it must have the same
size and the same type as x
.angle
- output array of vector angles; it has the same size and same
type as x
.angleInDegrees
- when true, the function calculates the angle in
degrees, otherwise, they are measured in radians.public static void polarToCart(Mat magnitude, Mat angle, Mat x, Mat y)
Calculates x and y coordinates of 2D vectors from their magnitude and angle.
The function polarToCart
calculates the Cartesian coordinates of
each 2D vector represented by the corresponding elements of magnitude
and angle
:
x(I) = magnitude(I) cos(angle(I)) y(I) = magnitude(I) sin(angle(I))
The relative accuracy of the estimated coordinates is about 1e-6
.
magnitude
- input floating-point array of magnitudes of 2D vectors; it
can be an empty matrix (=Mat()
), in this case, the function
assumes that all the magnitudes are =1; if it is not empty, it must have the
same size and type as angle
.angle
- input floating-point array of angles of 2D vectors.x
- output array of x-coordinates of 2D vectors; it has the same size
and type as angle
.y
- output array of y-coordinates of 2D vectors; it has the same size
and type as angle
.log(org.opencv.core.Mat, org.opencv.core.Mat)
,
cartToPolar(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
pow(org.opencv.core.Mat, double, org.opencv.core.Mat)
,
sqrt(org.opencv.core.Mat, org.opencv.core.Mat)
,
magnitude(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
exp(org.opencv.core.Mat, org.opencv.core.Mat)
,
phase(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
public static void polarToCart(Mat magnitude, Mat angle, Mat x, Mat y, boolean angleInDegrees)
Calculates x and y coordinates of 2D vectors from their magnitude and angle.
The function polarToCart
calculates the Cartesian coordinates of
each 2D vector represented by the corresponding elements of magnitude
and angle
:
x(I) = magnitude(I) cos(angle(I)) y(I) = magnitude(I) sin(angle(I))
The relative accuracy of the estimated coordinates is about 1e-6
.
magnitude
- input floating-point array of magnitudes of 2D vectors; it
can be an empty matrix (=Mat()
), in this case, the function
assumes that all the magnitudes are =1; if it is not empty, it must have the
same size and type as angle
.angle
- input floating-point array of angles of 2D vectors.x
- output array of x-coordinates of 2D vectors; it has the same size
and type as angle
.y
- output array of y-coordinates of 2D vectors; it has the same size
and type as angle
.angleInDegrees
- when true, the input angles are measured in degrees,
otherwise, they are measured in radians.log(org.opencv.core.Mat, org.opencv.core.Mat)
,
cartToPolar(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
pow(org.opencv.core.Mat, double, org.opencv.core.Mat)
,
sqrt(org.opencv.core.Mat, org.opencv.core.Mat)
,
magnitude(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
exp(org.opencv.core.Mat, org.opencv.core.Mat)
,
phase(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
public static void polylines(Mat img, java.util.List<MatOfPoint> pts, boolean isClosed, Scalar color)
Draws several polygonal curves.
The function polylines
draws one or more polygonal curves.
img
- Image.pts
- Array of polygonal curves.isClosed
- Flag indicating whether the drawn polylines are closed or
not. If they are closed, the function draws a line from the last vertex of
each curve to its first vertex.color
- Polyline color.public static void polylines(Mat img, java.util.List<MatOfPoint> pts, boolean isClosed, Scalar color, int thickness)
Draws several polygonal curves.
The function polylines
draws one or more polygonal curves.
img
- Image.pts
- Array of polygonal curves.isClosed
- Flag indicating whether the drawn polylines are closed or
not. If they are closed, the function draws a line from the last vertex of
each curve to its first vertex.color
- Polyline color.thickness
- Thickness of the polyline edges.public static void polylines(Mat img, java.util.List<MatOfPoint> pts, boolean isClosed, Scalar color, int thickness, int lineType, int shift)
Draws several polygonal curves.
The function polylines
draws one or more polygonal curves.
img
- Image.pts
- Array of polygonal curves.isClosed
- Flag indicating whether the drawn polylines are closed or
not. If they are closed, the function draws a line from the last vertex of
each curve to its first vertex.color
- Polyline color.thickness
- Thickness of the polyline edges.lineType
- Type of the line segments. See the "line" description.shift
- Number of fractional bits in the vertex coordinates.public static void pow(Mat src, double power, Mat dst)
Raises every array element to a power.
The function pow
raises every element of the input array to
power
:
dst(I) = src(I)^(power) if power is integer; |src(I)|^(power)
otherwise<BR>So, for a non-integer power exponent, the absolute values of
input array elements are used. However, it is possible to get true values for
negative values using some extra operations. In the example below, computing
the 5th root of array src
shows: <BR><code>
// C++ code:
Mat mask = src < 0;
pow(src, 1./5, dst);
subtract(Scalar.all(0), dst, dst, mask);
For some values of power
, such as integer values, 0.5 and -0.5,
specialized faster algorithms are used.
Special values (NaN, Inf) are not handled.
src
- input array.power
- exponent of power.dst
- output array of the same size and type as src
.cartToPolar(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
polarToCart(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, boolean)
,
exp(org.opencv.core.Mat, org.opencv.core.Mat)
,
sqrt(org.opencv.core.Mat, org.opencv.core.Mat)
,
log(org.opencv.core.Mat, org.opencv.core.Mat)
public static void putText(Mat img, java.lang.String text, Point org, int fontFace, double fontScale, Scalar color)
Draws a text string.
The function putText
renders the specified text string in the
image.
Symbols that cannot be rendered using the specified font are replaced by
question marks. See "getTextSize" for a text rendering code example.
img
- Image.text
- Text string to be drawn.org
- Bottom-left corner of the text string in the image.fontFace
- Font type. One of FONT_HERSHEY_SIMPLEX
,
FONT_HERSHEY_PLAIN
, FONT_HERSHEY_DUPLEX
,
FONT_HERSHEY_COMPLEX
, FONT_HERSHEY_TRIPLEX
,
FONT_HERSHEY_COMPLEX_SMALL
, FONT_HERSHEY_SCRIPT_SIMPLEX
,
or FONT_HERSHEY_SCRIPT_COMPLEX
, where each of the font ID's can
be combined with FONT_ITALIC
to get the slanted letters.fontScale
- Font scale factor that is multiplied by the font-specific
base size.color
- Text color.public static void putText(Mat img, java.lang.String text, Point org, int fontFace, double fontScale, Scalar color, int thickness)
Draws a text string.
The function putText
renders the specified text string in the
image.
Symbols that cannot be rendered using the specified font are replaced by
question marks. See "getTextSize" for a text rendering code example.
img
- Image.text
- Text string to be drawn.org
- Bottom-left corner of the text string in the image.fontFace
- Font type. One of FONT_HERSHEY_SIMPLEX
,
FONT_HERSHEY_PLAIN
, FONT_HERSHEY_DUPLEX
,
FONT_HERSHEY_COMPLEX
, FONT_HERSHEY_TRIPLEX
,
FONT_HERSHEY_COMPLEX_SMALL
, FONT_HERSHEY_SCRIPT_SIMPLEX
,
or FONT_HERSHEY_SCRIPT_COMPLEX
, where each of the font ID's can
be combined with FONT_ITALIC
to get the slanted letters.fontScale
- Font scale factor that is multiplied by the font-specific
base size.color
- Text color.thickness
- Thickness of the lines used to draw a text.public static void putText(Mat img, java.lang.String text, Point org, int fontFace, double fontScale, Scalar color, int thickness, int lineType, boolean bottomLeftOrigin)
Draws a text string.
The function putText
renders the specified text string in the
image.
Symbols that cannot be rendered using the specified font are replaced by
question marks. See "getTextSize" for a text rendering code example.
img
- Image.text
- Text string to be drawn.org
- Bottom-left corner of the text string in the image.fontFace
- Font type. One of FONT_HERSHEY_SIMPLEX
,
FONT_HERSHEY_PLAIN
, FONT_HERSHEY_DUPLEX
,
FONT_HERSHEY_COMPLEX
, FONT_HERSHEY_TRIPLEX
,
FONT_HERSHEY_COMPLEX_SMALL
, FONT_HERSHEY_SCRIPT_SIMPLEX
,
or FONT_HERSHEY_SCRIPT_COMPLEX
, where each of the font ID's can
be combined with FONT_ITALIC
to get the slanted letters.fontScale
- Font scale factor that is multiplied by the font-specific
base size.color
- Text color.thickness
- Thickness of the lines used to draw a text.lineType
- Line type. See the line
for details.bottomLeftOrigin
- When true, the image data origin is at the
bottom-left corner. Otherwise, it is at the top-left corner.public static void randn(Mat dst, double mean, double stddev)
Fills the array with normally distributed random numbers.
The function randn
fills the matrix dst
with
normally distributed random numbers with the specified mean vector and the
standard deviation matrix. The generated random numbers are clipped to fit
the value range of the output array data type.
dst
- output array of random numbers; the array must be pre-allocated
and have 1 to 4 channels.mean
- mean value (expectation) of the generated random numbers.stddev
- standard deviation of the generated random numbers; it can be
either a vector (in which case a diagonal standard deviation matrix is
assumed) or a square matrix.randu(org.opencv.core.Mat, double, double)
public static void randShuffle(Mat dst)
public static void randShuffle(Mat dst, double iterFactor)
public static void randu(Mat dst, double low, double high)
Generates a single uniformly-distributed random number or an array of random numbers.
The template functions randu
generate and return the next
uniformly-distributed random value of the specified type. randu
is an equivalent to (int)theRNG();
, and so on. See "RNG"
description.
The second non-template variant of the function fills the matrix
dst
with uniformly-distributed random numbers from the specified
range:
low _c <= dst(I)_c < high _c
dst
- output array of random numbers; the array must be pre-allocated.low
- inclusive lower boundary of the generated random numbers.high
- exclusive upper boundary of the generated random numbers.randn(org.opencv.core.Mat, double, double)
public static void rectangle(Mat img, Point pt1, Point pt2, Scalar color)
Draws a simple, thick, or filled up-right rectangle.
The function rectangle
draws a rectangle outline or a filled
rectangle whose two opposite corners are pt1
and
pt2
, or r.tl()
and r.br()-Point(1,1)
.
img
- Image.pt1
- Vertex of the rectangle.pt2
- Vertex of the rectangle opposite to pt1
.color
- Rectangle color or brightness (grayscale image).public static void rectangle(Mat img, Point pt1, Point pt2, Scalar color, int thickness)
Draws a simple, thick, or filled up-right rectangle.
The function rectangle
draws a rectangle outline or a filled
rectangle whose two opposite corners are pt1
and
pt2
, or r.tl()
and r.br()-Point(1,1)
.
img
- Image.pt1
- Vertex of the rectangle.pt2
- Vertex of the rectangle opposite to pt1
.color
- Rectangle color or brightness (grayscale image).thickness
- Thickness of lines that make up the rectangle. Negative
values, like CV_FILLED
, mean that the function has to draw a
filled rectangle.public static void rectangle(Mat img, Point pt1, Point pt2, Scalar color, int thickness, int lineType, int shift)
Draws a simple, thick, or filled up-right rectangle.
The function rectangle
draws a rectangle outline or a filled
rectangle whose two opposite corners are pt1
and
pt2
, or r.tl()
and r.br()-Point(1,1)
.
img
- Image.pt1
- Vertex of the rectangle.pt2
- Vertex of the rectangle opposite to pt1
.color
- Rectangle color or brightness (grayscale image).thickness
- Thickness of lines that make up the rectangle. Negative
values, like CV_FILLED
, mean that the function has to draw a
filled rectangle.lineType
- Type of the line. See the "line" description.shift
- Number of fractional bits in the point coordinates.public static void reduce(Mat src, Mat dst, int dim, int rtype)
Reduces a matrix to a vector.
The function reduce
reduces the matrix to a vector by treating
the matrix rows/columns as a set of 1D vectors and performing the specified
operation on the vectors until a single row/column is obtained. For example,
the function can be used to compute horizontal and vertical projections of a
raster image. In case of CV_REDUCE_SUM
and CV_REDUCE_AVG
,
the output may have a larger element bit-depth to preserve accuracy. And
multi-channel arrays are also supported in these two reduction modes.
src
- input 2D matrix.dst
- output vector. Its size and type is defined by dim
and dtype
parameters.dim
- dimension index along which the matrix is reduced. 0 means that
the matrix is reduced to a single row. 1 means that the matrix is reduced to
a single column.rtype
- reduction operation that could be one of the following:
repeat(org.opencv.core.Mat, int, int, org.opencv.core.Mat)
public static void reduce(Mat src, Mat dst, int dim, int rtype, int dtype)
Reduces a matrix to a vector.
The function reduce
reduces the matrix to a vector by treating
the matrix rows/columns as a set of 1D vectors and performing the specified
operation on the vectors until a single row/column is obtained. For example,
the function can be used to compute horizontal and vertical projections of a
raster image. In case of CV_REDUCE_SUM
and CV_REDUCE_AVG
,
the output may have a larger element bit-depth to preserve accuracy. And
multi-channel arrays are also supported in these two reduction modes.
src
- input 2D matrix.dst
- output vector. Its size and type is defined by dim
and dtype
parameters.dim
- dimension index along which the matrix is reduced. 0 means that
the matrix is reduced to a single row. 1 means that the matrix is reduced to
a single column.rtype
- reduction operation that could be one of the following:
dtype
- when negative, the output vector will have the same type as the
input matrix, otherwise, its type will be CV_MAKE_TYPE(CV_MAT_DEPTH(dtype),
src.channels())
.repeat(org.opencv.core.Mat, int, int, org.opencv.core.Mat)
public static void repeat(Mat src, int ny, int nx, Mat dst)
Fills the output array with repeated copies of the input array.
The functions "repeat" duplicate the input array one or more times along each of the two axes:
dst _(ij)= src _(i mod src.rows, j mod src.cols)
The second variant of the function is more convenient to use with "MatrixExpressions".
src
- input array to replicate.ny
- Flag to specify how many times the src
is repeated
along the vertical axis.nx
- Flag to specify how many times the src
is repeated
along the horizontal axis.dst
- output array of the same type as src
.reduce(org.opencv.core.Mat, org.opencv.core.Mat, int, int, int)
public static void scaleAdd(Mat src1, double alpha, Mat src2, Mat dst)
Calculates the sum of a scaled array and another array.
The function scaleAdd
is one of the classical primitive linear
algebra operations, known as DAXPY
or SAXPY
in BLAS
(http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms). It
calculates the sum of a scaled array and another array:
dst(I)= scale * src1(I) + src2(I)<BR>The function can also be emulated with a matrix expression, for example: <BR><code>
// C++ code:
Mat A(3, 3, CV_64F);...
A.row(0) = A.row(1)*2 + A.row(2);
src1
- first input array.alpha
- a alphasrc2
- second input array of the same size and type as src1
.dst
- output array of the same size and type as src1
.Mat.dot(org.opencv.core.Mat)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
,
addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
subtract(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
public static void setErrorVerbosity(boolean verbose)
public static void setIdentity(Mat mtx)
Initializes a scaled identity matrix.
The function "setIdentity" initializes a scaled identity matrix:
mtx(i,j)= value if i=j; 0 otherwise<BR>The function can also be emulated using the matrix initializers and the matrix expressions: <BR><code>
// C++ code:
Mat A = Mat.eye(4, 3, CV_32F)*5;
// A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]]
mtx
- matrix to initialize (not necessarily square).Mat.setTo(org.opencv.core.Scalar)
,
Mat.ones(int, int, int)
,
Mat.zeros(int, int, int)
public static void setIdentity(Mat mtx, Scalar s)
Initializes a scaled identity matrix.
The function "setIdentity" initializes a scaled identity matrix:
mtx(i,j)= value if i=j; 0 otherwise<BR>The function can also be emulated using the matrix initializers and the matrix expressions: <BR><code>
// C++ code:
Mat A = Mat.eye(4, 3, CV_32F)*5;
// A will be set to [[5, 0, 0], [0, 5, 0], [0, 0, 5], [0, 0, 0]]
mtx
- matrix to initialize (not necessarily square).s
- a sMat.setTo(org.opencv.core.Scalar)
,
Mat.ones(int, int, int)
,
Mat.zeros(int, int, int)
public static void setNumThreads(int nthreads)
OpenCV will try to set the number of threads for the next parallel region.
If threads == 0
, OpenCV will disable threading optimizations and
run all its functions sequentially. Passing threads < 0
will
reset threads number to system default.
This function must be called outside of parallel region.
OpenCV will try to run its functions with specified threads number, but some behaviour differs from framework:
threads == 1
, OpenCV will disable
threading optimizations and run its functions sequentially.
nthreads
- Number of threads used by OpenCV.getThreadNum()
,
getNumThreads()
public static void setRNGSeed(int seed)
public static boolean solve(Mat src1, Mat src2, Mat dst)
Solves one or more linear systems or least-squares problems.
The function solve
solves a linear system or least-squares
problem (the latter is possible with SVD or QR methods, or by specifying the
flag DECOMP_NORMAL
):
dst = arg min _X|src1 * X - src2|
If DECOMP_LU
or DECOMP_CHOLESKY
method is used, the
function returns 1 if src1
(or src1^Tsrc1) is
non-singular. Otherwise, it returns 0. In the latter case, dst
is not valid. Other methods find a pseudo-solution in case of a singular
left-hand side part.
Note: If you want to find a unity-norm solution of an under-defined singular
system src1*dst=0, the function solve
will not do the
work. Use "SVD.solveZ" instead.
src1
- input matrix on the left-hand side of the system.src2
- input matrix on the right-hand side of the system.dst
- output solution.invert(org.opencv.core.Mat, org.opencv.core.Mat, int)
,
eigen(org.opencv.core.Mat, boolean, org.opencv.core.Mat, org.opencv.core.Mat)
public static boolean solve(Mat src1, Mat src2, Mat dst, int flags)
Solves one or more linear systems or least-squares problems.
The function solve
solves a linear system or least-squares
problem (the latter is possible with SVD or QR methods, or by specifying the
flag DECOMP_NORMAL
):
dst = arg min _X|src1 * X - src2|
If DECOMP_LU
or DECOMP_CHOLESKY
method is used, the
function returns 1 if src1
(or src1^Tsrc1) is
non-singular. Otherwise, it returns 0. In the latter case, dst
is not valid. Other methods find a pseudo-solution in case of a singular
left-hand side part.
Note: If you want to find a unity-norm solution of an under-defined singular
system src1*dst=0, the function solve
will not do the
work. Use "SVD.solveZ" instead.
src1
- input matrix on the left-hand side of the system.src2
- input matrix on the right-hand side of the system.dst
- output solution.flags
- solution (matrix inversion) method.
src1
must be symmetrical and positively defined.
src1
must
be symmetrical.
src1
can be singular.
src1
can be singular.
invert(org.opencv.core.Mat, org.opencv.core.Mat, int)
,
eigen(org.opencv.core.Mat, boolean, org.opencv.core.Mat, org.opencv.core.Mat)
public static int solveCubic(Mat coeffs, Mat roots)
Finds the real roots of a cubic equation.
The function solveCubic
finds the real roots of a cubic
equation:
coeffs
is a 4-element vector:
coeffs [0] x^3 + coeffs [1] x^2 + coeffs [2] x + coeffs [3] = 0
coeffs
is a 3-element vector:
x^3 + coeffs [0] x^2 + coeffs [1] x + coeffs [2] = 0
The roots are stored in the roots
array.
coeffs
- equation coefficients, an array of 3 or 4 elements.roots
- output array of real roots that has 1 or 3 elements.public static double solvePoly(Mat coeffs, Mat roots)
Finds the real or complex roots of a polynomial equation.
The function solvePoly
finds real and complex roots of a
polynomial equation:
coeffs [n] x^(n) + coeffs [n-1] x^(n-1) +... + coeffs [1] x + coeffs [0] = 0
coeffs
- array of polynomial coefficients.roots
- output (complex) array of roots.public static double solvePoly(Mat coeffs, Mat roots, int maxIters)
Finds the real or complex roots of a polynomial equation.
The function solvePoly
finds real and complex roots of a
polynomial equation:
coeffs [n] x^(n) + coeffs [n-1] x^(n-1) +... + coeffs [1] x + coeffs [0] = 0
coeffs
- array of polynomial coefficients.roots
- output (complex) array of roots.maxIters
- maximum number of iterations the algorithm does.public static void sort(Mat src, Mat dst, int flags)
Sorts each row or each column of a matrix.
The function sort
sorts each matrix row or each matrix column in
ascending or descending order. So you should pass two operation flags to get
desired behaviour. If you want to sort matrix rows or columns
lexicographically, you can use STL std.sort
generic function
with the proper comparison predicate.
src
- input single-channel array.dst
- output array of the same size and type as src
.flags
- operation flags, a combination of the following values:
randShuffle(org.opencv.core.Mat, double)
,
sortIdx(org.opencv.core.Mat, org.opencv.core.Mat, int)
public static void sortIdx(Mat src, Mat dst, int flags)
Sorts each row or each column of a matrix.
The function sortIdx
sorts each matrix row or each matrix column
in the ascending or descending order. So you should pass two operation flags
to get desired behaviour. Instead of reordering the elements themselves, it
stores the indices of sorted elements in the output array. For example:
// C++ code:
Mat A = Mat.eye(3,3,CV_32F), B;
sortIdx(A, B, CV_SORT_EVERY_ROW + CV_SORT_ASCENDING);
// B will probably contain
// (because of equal elements in A some permutations are possible):
// [[1, 2, 0], [0, 2, 1], [0, 1, 2]]
src
- input single-channel array.dst
- output integer array of the same size as src
.flags
- operation flags that could be a combination of the following
values:
sort(org.opencv.core.Mat, org.opencv.core.Mat, int)
,
randShuffle(org.opencv.core.Mat, double)
public static void split(Mat m, java.util.List<Mat> mv)
Divides a multi-channel array into several single-channel arrays.
The functions split
split a multi-channel array into separate
single-channel arrays:
mv [c](I) = src(I)_c
If you need to extract a single channel or do some other sophisticated channel permutation, use "mixChannels".
m
- a mmv
- output array or vector of arrays; in the first variant of the
function the number of arrays must match src.channels()
; the
arrays themselves are reallocated, if needed.merge(java.util.List<org.opencv.core.Mat>, org.opencv.core.Mat)
,
Imgproc.cvtColor(org.opencv.core.Mat, org.opencv.core.Mat, int, int)
,
mixChannels(java.util.List<org.opencv.core.Mat>, java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt)
public static void sqrt(Mat src, Mat dst)
Calculates a square root of array elements.
The functions sqrt
calculate a square root of each input array
element. In case of multi-channel arrays, each channel is processed
independently. The accuracy is approximately the same as of the built-in
std.sqrt
.
src
- input floating-point array.dst
- output array of the same size and type as src
.pow(org.opencv.core.Mat, double, org.opencv.core.Mat)
,
magnitude(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
public static void subtract(Mat src1, Mat src2, Mat dst)
Calculates the per-element difference between two arrays or array and a scalar.
The function subtract
calculates:
dst(I) = saturate(src1(I) - src2(I)) if mask(I) != 0
src2
is
constructed from Scalar
or has the same number of elements as
src1.channels()
:
dst(I) = saturate(src1(I) - src2) if mask(I) != 0
src1
is
constructed from Scalar
or has the same number of elements as
src2.channels()
:
dst(I) = saturate(src1 - src2(I)) if mask(I) != 0
SubRS
:
dst(I) = saturate(src2 - src1(I)) if mask(I) != 0
where I
is a multi-dimensional index of array elements. In case
of multi-channel arrays, each channel is processed independently.
The first function in the list above can be replaced with matrix expressions:
// C++ code:
dst = src1 - src2;
dst -= src1; // equivalent to subtract(dst, src1, dst);
The input arrays and the output array can all have the same or different
depths. For example, you can subtract to 8-bit unsigned arrays and store the
difference in a 16-bit signed array. Depth of the output array is determined
by dtype
parameter. In the second and third cases above, as well
as in the first case, when src1.depth() == src2.depth()
,
dtype
can be set to the default -1
. In this case
the output array will have the same depth as the input array, be it
src1
, src2
or both.
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array or a scalar.src2
- second input array or a scalar.dst
- output array of the same size and the same number of channels as
the input array.addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
public static void subtract(Mat src1, Mat src2, Mat dst, Mat mask)
Calculates the per-element difference between two arrays or array and a scalar.
The function subtract
calculates:
dst(I) = saturate(src1(I) - src2(I)) if mask(I) != 0
src2
is
constructed from Scalar
or has the same number of elements as
src1.channels()
:
dst(I) = saturate(src1(I) - src2) if mask(I) != 0
src1
is
constructed from Scalar
or has the same number of elements as
src2.channels()
:
dst(I) = saturate(src1 - src2(I)) if mask(I) != 0
SubRS
:
dst(I) = saturate(src2 - src1(I)) if mask(I) != 0
where I
is a multi-dimensional index of array elements. In case
of multi-channel arrays, each channel is processed independently.
The first function in the list above can be replaced with matrix expressions:
// C++ code:
dst = src1 - src2;
dst -= src1; // equivalent to subtract(dst, src1, dst);
The input arrays and the output array can all have the same or different
depths. For example, you can subtract to 8-bit unsigned arrays and store the
difference in a 16-bit signed array. Depth of the output array is determined
by dtype
parameter. In the second and third cases above, as well
as in the first case, when src1.depth() == src2.depth()
,
dtype
can be set to the default -1
. In this case
the output array will have the same depth as the input array, be it
src1
, src2
or both.
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array or a scalar.src2
- second input array or a scalar.dst
- output array of the same size and the same number of channels as
the input array.mask
- optional operation mask; this is an 8-bit single channel array
that specifies elements of the output array to be changed.addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
public static void subtract(Mat src1, Mat src2, Mat dst, Mat mask, int dtype)
Calculates the per-element difference between two arrays or array and a scalar.
The function subtract
calculates:
dst(I) = saturate(src1(I) - src2(I)) if mask(I) != 0
src2
is
constructed from Scalar
or has the same number of elements as
src1.channels()
:
dst(I) = saturate(src1(I) - src2) if mask(I) != 0
src1
is
constructed from Scalar
or has the same number of elements as
src2.channels()
:
dst(I) = saturate(src1 - src2(I)) if mask(I) != 0
SubRS
:
dst(I) = saturate(src2 - src1(I)) if mask(I) != 0
where I
is a multi-dimensional index of array elements. In case
of multi-channel arrays, each channel is processed independently.
The first function in the list above can be replaced with matrix expressions:
// C++ code:
dst = src1 - src2;
dst -= src1; // equivalent to subtract(dst, src1, dst);
The input arrays and the output array can all have the same or different
depths. For example, you can subtract to 8-bit unsigned arrays and store the
difference in a 16-bit signed array. Depth of the output array is determined
by dtype
parameter. In the second and third cases above, as well
as in the first case, when src1.depth() == src2.depth()
,
dtype
can be set to the default -1
. In this case
the output array will have the same depth as the input array, be it
src1
, src2
or both.
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array or a scalar.src2
- second input array or a scalar.dst
- output array of the same size and the same number of channels as
the input array.mask
- optional operation mask; this is an 8-bit single channel array
that specifies elements of the output array to be changed.dtype
- optional depth of the output array (see the details below).addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
public static void subtract(Mat src1, Scalar src2, Mat dst)
Calculates the per-element difference between two arrays or array and a scalar.
The function subtract
calculates:
dst(I) = saturate(src1(I) - src2(I)) if mask(I) != 0
src2
is
constructed from Scalar
or has the same number of elements as
src1.channels()
:
dst(I) = saturate(src1(I) - src2) if mask(I) != 0
src1
is
constructed from Scalar
or has the same number of elements as
src2.channels()
:
dst(I) = saturate(src1 - src2(I)) if mask(I) != 0
SubRS
:
dst(I) = saturate(src2 - src1(I)) if mask(I) != 0
where I
is a multi-dimensional index of array elements. In case
of multi-channel arrays, each channel is processed independently.
The first function in the list above can be replaced with matrix expressions:
// C++ code:
dst = src1 - src2;
dst -= src1; // equivalent to subtract(dst, src1, dst);
The input arrays and the output array can all have the same or different
depths. For example, you can subtract to 8-bit unsigned arrays and store the
difference in a 16-bit signed array. Depth of the output array is determined
by dtype
parameter. In the second and third cases above, as well
as in the first case, when src1.depth() == src2.depth()
,
dtype
can be set to the default -1
. In this case
the output array will have the same depth as the input array, be it
src1
, src2
or both.
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array or a scalar.src2
- second input array or a scalar.dst
- output array of the same size and the same number of channels as
the input array.addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
public static void subtract(Mat src1, Scalar src2, Mat dst, Mat mask)
Calculates the per-element difference between two arrays or array and a scalar.
The function subtract
calculates:
dst(I) = saturate(src1(I) - src2(I)) if mask(I) != 0
src2
is
constructed from Scalar
or has the same number of elements as
src1.channels()
:
dst(I) = saturate(src1(I) - src2) if mask(I) != 0
src1
is
constructed from Scalar
or has the same number of elements as
src2.channels()
:
dst(I) = saturate(src1 - src2(I)) if mask(I) != 0
SubRS
:
dst(I) = saturate(src2 - src1(I)) if mask(I) != 0
where I
is a multi-dimensional index of array elements. In case
of multi-channel arrays, each channel is processed independently.
The first function in the list above can be replaced with matrix expressions:
// C++ code:
dst = src1 - src2;
dst -= src1; // equivalent to subtract(dst, src1, dst);
The input arrays and the output array can all have the same or different
depths. For example, you can subtract to 8-bit unsigned arrays and store the
difference in a 16-bit signed array. Depth of the output array is determined
by dtype
parameter. In the second and third cases above, as well
as in the first case, when src1.depth() == src2.depth()
,
dtype
can be set to the default -1
. In this case
the output array will have the same depth as the input array, be it
src1
, src2
or both.
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array or a scalar.src2
- second input array or a scalar.dst
- output array of the same size and the same number of channels as
the input array.mask
- optional operation mask; this is an 8-bit single channel array
that specifies elements of the output array to be changed.addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
public static void subtract(Mat src1, Scalar src2, Mat dst, Mat mask, int dtype)
Calculates the per-element difference between two arrays or array and a scalar.
The function subtract
calculates:
dst(I) = saturate(src1(I) - src2(I)) if mask(I) != 0
src2
is
constructed from Scalar
or has the same number of elements as
src1.channels()
:
dst(I) = saturate(src1(I) - src2) if mask(I) != 0
src1
is
constructed from Scalar
or has the same number of elements as
src2.channels()
:
dst(I) = saturate(src1 - src2(I)) if mask(I) != 0
SubRS
:
dst(I) = saturate(src2 - src1(I)) if mask(I) != 0
where I
is a multi-dimensional index of array elements. In case
of multi-channel arrays, each channel is processed independently.
The first function in the list above can be replaced with matrix expressions:
// C++ code:
dst = src1 - src2;
dst -= src1; // equivalent to subtract(dst, src1, dst);
The input arrays and the output array can all have the same or different
depths. For example, you can subtract to 8-bit unsigned arrays and store the
difference in a 16-bit signed array. Depth of the output array is determined
by dtype
parameter. In the second and third cases above, as well
as in the first case, when src1.depth() == src2.depth()
,
dtype
can be set to the default -1
. In this case
the output array will have the same depth as the input array, be it
src1
, src2
or both.
Note: Saturation is not applied when the output array has the depth
CV_32S
. You may even get result of an incorrect sign in the case
of overflow.
src1
- first input array or a scalar.src2
- second input array or a scalar.dst
- output array of the same size and the same number of channels as
the input array.mask
- optional operation mask; this is an 8-bit single channel array
that specifies elements of the output array to be changed.dtype
- optional depth of the output array (see the details below).addWeighted(org.opencv.core.Mat, double, org.opencv.core.Mat, double, double, org.opencv.core.Mat, int)
,
add(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, int)
,
scaleAdd(org.opencv.core.Mat, double, org.opencv.core.Mat, org.opencv.core.Mat)
,
Mat.convertTo(org.opencv.core.Mat, int, double, double)
public static Scalar sumElems(Mat src)
Calculates the sum of array elements.
The functions sum
calculate and return the sum of array
elements, independently for each channel.
src
- a srcmeanStdDev(org.opencv.core.Mat, org.opencv.core.MatOfDouble, org.opencv.core.MatOfDouble, org.opencv.core.Mat)
,
reduce(org.opencv.core.Mat, org.opencv.core.Mat, int, int, int)
,
minMaxLoc(org.opencv.core.Mat, org.opencv.core.Mat)
,
countNonZero(org.opencv.core.Mat)
,
norm(org.opencv.core.Mat, int, org.opencv.core.Mat)
,
mean(org.opencv.core.Mat, org.opencv.core.Mat)
public static Scalar trace(Mat mtx)
Returns the trace of a matrix.
The function trace
returns the sum of the diagonal elements of
the matrix mtx
.
tr(mtx) = sum _i mtx(i,i)
mtx
- a mtxpublic static void transform(Mat src, Mat dst, Mat m)
Performs the matrix transformation of every array element.
The function transform
performs the matrix transformation of
every element of the array src
and stores the results in
dst
:
dst(I) = m * src(I)
(when m.cols=src.channels()
), or
dst(I) = m * [ src(I); 1]
(when m.cols=src.channels()+1
)
Every element of the N
-channel array src
is
interpreted as N
-element vector that is transformed using the
M x N
or M x (N+1)
matrix m
to
M
-element vector - the corresponding element of the output array
dst
.
The function may be used for geometrical transformation of N
-dimensional points, arbitrary linear color space transformation (such as
various kinds of RGB to YUV transforms), shuffling the image channels, and so
forth.
src
- input array that must have as many channels (1 to 4) as
m.cols
or m.cols-1
.dst
- output array of the same size and depth as src
; it
has as many channels as m.rows
.m
- transformation 2x2
or 2x3
floating-point
matrix.Imgproc.warpAffine(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Size, int, int, org.opencv.core.Scalar)
,
perspectiveTransform(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat)
,
Imgproc.warpPerspective(org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.Size, int, int, org.opencv.core.Scalar)
,
Imgproc.getAffineTransform(org.opencv.core.MatOfPoint2f, org.opencv.core.MatOfPoint2f)
,
Video.estimateRigidTransform(org.opencv.core.Mat, org.opencv.core.Mat, boolean)
public static void transpose(Mat src, Mat dst)
Transposes a matrix.
The function "transpose" transposes the matrix src
:
dst(i,j) = src(j,i)
Note: No complex conjugation is done in case of a complex matrix. It it should be done separately if needed.
src
- input array.dst
- output array of the same type as src
.


Reference
Documentation (in Greek) for Plugs
(zipped MS-Word file, 776ÊÂ, Version: 26Feb2002)
English documentation to be available soon... (can check the Greek documentation for screenshots and the end of it for sample MATLAB etc. programs)