opencv java使用教程_Java OpenCV convertScaleAbs()使用详解

这篇博客详细介绍了OpenCV中的convertScaleAbs函数,通过Java示例展示了如何对图像数组元素进行缩放和绝对值转换。通过alpha和beta参数控制图像处理过程,提供了不同参数组合下的实际应用效果。

函数说明

用于实现对整个图像数组中的每一个元素,进行如下操作:

dstrow,coldst_{row,col}dstrow,col​ = ∣alpha∗srcrow,col+beta∣|alpha*src_{row,col} + beta|∣alpha∗srcrow,col​+beta∣

参数说明

Core.convertScaleAbs(src, dst, alpha, 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

标签:Java,mat,0.0,OpenCV,convertScaleAbs,1.0,2.0,col,row

来源: https://blog.youkuaiyun.com/wangwenjie1997/article/details/101058024

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值