函数说明
用于实现对整个图像数组中的每一个元素,进行如下操作:
d
s
t
r
o
w
,
c
o
l
dst_{row,col}
dstrow,col =
∣
a
l
p
h
a
∗
s
r
c
r
o
w
,
c
o
l
+
b
e
t
a
∣
|alpha*src_{row,col} + beta|
∣alpha∗srcrow,col+beta∣
参数说明
Core.convertScaleAbs(Mat src, Mat dst, double alpha, double beta);
src – 原图
dst – 目标图
alpha – 乘数因子
beta – 偏移量
测试代码
import org.opencv.core.*;
public class OpenCVTest {
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
public static void main(String[] args) {
Mat mat = new Mat(new Size(3,3), CvType.CV_8UC1, new Scalar(0));
mat.put(0, 0, 0);
mat.put(0, 1, 1);
mat.put(0, 2, 2);
mat.put(1, 0, 0);
mat.put(1, 1, 1);
mat.put(1, 2, 2);
mat.put(2, 0, 0);
mat.put(2, 1, 1);
mat.put(2, 2, 2);
Mat dst = new Mat();
Core.convertScaleAbs(mat, dst, 1, 0);
System.out.println("----------原图-----------");
for (int row = 0; row < mat.rows(); row++) {
for (int col = 0; col < mat.cols(); col++) {
System.out.print(mat.get(row, col)[0] + " ");
}
System.out.println();
}
System.out.println("----------处理结果-----------");
for (int row = 0; row < dst.rows(); row++) {
for (int col = 0; col < dst.cols(); col++) {
System.out.print(dst.get(row, col)[0] + " ");
}
System.out.println();
}
}
}
结果输出
alpha = 1, beta = 0
----------原图-----------
0.0 1.0 2.0
0.0 1.0 2.0
0.0 1.0 2.0
----------处理结果-----------
0.0 1.0 2.0
0.0 1.0 2.0
0.0 1.0 2.0
alpha = 2, beta = -1
----------原图-----------
0.0 1.0 2.0
0.0 1.0 2.0
0.0 1.0 2.0
----------处理结果-----------
1.0 1.0 3.0
1.0 1.0 3.0
1.0 1.0 3.0