org.opencv.core.Core.add()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(243)

本文整理了Java中org.opencv.core.Core.add()方法的一些代码示例,展示了Core.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Core.add()方法的具体详情如下:
包路径:org.opencv.core.Core
类名称:Core
方法名:add

Core.add介绍

[英]Calculates the per-element sum of two arrays or an array and a scalar.

The function add calculates:

  • Sum of two arrays when both input arrays have the same size and the same number of channels:

dst(I) = saturate(src1(I) + src2(I)) if mask(I) != 0

  • Sum of an array and a scalar when 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

  • Sum of a scalar and an array when 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

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 add(dst, src1, dst);

The input arrays and the output array can all have the same or different depths. For example, you can add a 16-bit unsigned array to a 8-bit signed array and store the sum as a 32-bit floating-point array. Depth of the output array is determined by the 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.
[中]计算两个数组或一个数组和一个标量的每元素和。
函数add计算:
*当两个输入阵列的大小和通道数相同时,两个阵列的总和:
dst(I)=如果掩码(I)!=0
*当src2Scalar构造或具有与src1.channels()相同数量的元素时,数组和标量之和:
dst(I)=如果掩码(I)!=0
*当src1Scalar构造或具有与src2.channels()相同数量的元素时,标量和数组之和:
dst(I)=如果掩码(I)!=0
其中I是数组元素的多维索引。对于多通道阵列,每个通道都是独立处理的。上面列表中的第一个函数可以替换为矩阵表达式:``
//C++代码:
dst=src1+src2;
dst+=src1;//等同于add(dst、src1、dst);
输入数组和输出数组可以具有相同或不同的深度。例如,可以将16位无符号数组添加到8位有符号数组中,并将总和存储为32位浮点数组。输出数组的深度由dtype参数确定。在上述第二种和第三种情况下,以及在第一种情况下,当src1.depth() == src2.depth()时,dtype可以设置为默认值-1。在这种情况下,输出数组将具有与输入数组相同的深度,可以是src1src2或两者兼有。
注意:当输出数组的深度为CV_32S时,不应用饱和度。在溢出的情况下,您甚至可能会得到错误符号的结果。

代码示例

代码示例来源:origin: ytai/IOIOPlotter

  1. Core.add(procImage_, new Scalar(192, 192, 192), procImage_);

代码示例来源:origin: openpnp/openpnp

  1. @Override
  2. public Result process(CvPipeline pipeline) throws Exception {
  3. if (firstStageName == null) {
  4. return null;
  5. }
  6. if (secondStageName == null) {
  7. return null;
  8. }
  9. // TODO STOPSHIP memory?
  10. Mat first = pipeline.getResult(firstStageName).image;
  11. Mat second = pipeline.getResult(secondStageName).image;
  12. Mat out = new Mat();
  13. Core.add(first, second, out);
  14. return new Result(out);
  15. }
  16. }

代码示例来源:origin: ytai/IOIOPlotter

  1. Core.add(previewImage_, new Scalar(threshold * 255), previewImage_);
  2. } else {

代码示例来源:origin: nroduit/Weasis

  1. private static void exludePaddingValue(Mat src, Mat mask, int paddingValue, int paddingLimit) {
  2. Mat dst = new Mat();
  3. Core.inRange(src, new Scalar(paddingValue), new Scalar(paddingLimit), dst);
  4. Core.bitwise_not(dst, dst);
  5. Core.add(dst, mask, mask);
  6. }

代码示例来源:origin: nroduit/Weasis

  1. add(histogram, hist, histogram);

代码示例来源:origin: JavaOpenCVBook/code

  1. private void addNoise() {
  2. image = originalImage.clone();
  3. Mat grayRnd = new Mat(image.rows(), image.cols(), image.type());
  4. double noise = 128;
  5. grayRnd.setTo(new Scalar(noise/2, noise/2, noise/2));
  6. Core.subtract(image, grayRnd, image);
  7. Core.randu(grayRnd, 0, noise);
  8. Core.add(image, grayRnd, image);
  9. processOperation();
  10. updateView();
  11. }

代码示例来源:origin: JavaOpenCVBook/code

  1. Mat magnitude = new Mat();
  2. Core.magnitude(splitted.get(0),splitted.get(1), magnitude);
  3. Core.add(Mat.ones(magnitude.size(), CvType.CV_32F), magnitude, magnitude);

代码示例来源:origin: openpnp/openpnp

  1. Core.add(roberts1, roberts2, roberts);

代码示例来源:origin: openpnp/openpnp

  1. @Override
  2. public Result process(CvPipeline pipeline) throws Exception {
  3. Mat mat = pipeline.getWorkingImage();
  4. Mat kernel = Mat.eye(new Size(2, 2), CvType.CV_32FC1);
  5. kernel.put(0, 0, 0, 1, -1, 0);
  6. Mat roberts1 = new Mat();
  7. Imgproc.filter2D(mat, roberts1, CvType.CV_32FC1, kernel);
  8. Core.convertScaleAbs(roberts1, roberts1);
  9. kernel.put(0, 0, 1, 0, 0, -1);
  10. Mat roberts2 = new Mat();
  11. Imgproc.filter2D(mat, roberts2, CvType.CV_32FC1, kernel);
  12. Core.convertScaleAbs(roberts2, roberts2);
  13. Mat roberts = new Mat();
  14. Core.add(roberts1, roberts2, roberts);
  15. kernel.release();
  16. roberts1.release();
  17. roberts2.release();
  18. return new Result(roberts);
  19. }
  20. }

相关文章

Core类方法