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

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

本文整理了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

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

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

@Override
  public Result process(CvPipeline pipeline) throws Exception {
    if (firstStageName == null) {
      return null;
    }
    if (secondStageName == null) {
      return null;
    }
    // TODO STOPSHIP memory?
    Mat first = pipeline.getResult(firstStageName).image;
    Mat second = pipeline.getResult(secondStageName).image;
    
    Mat out = new Mat();
    Core.add(first, second, out);
    return new Result(out);
  }
}

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

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

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

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

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

add(histogram, hist, histogram);

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

private void addNoise() {
  image = originalImage.clone();
  Mat grayRnd = new Mat(image.rows(), image.cols(), image.type());
  double noise = 128;
  grayRnd.setTo(new Scalar(noise/2, noise/2, noise/2));
  Core.subtract(image, grayRnd, image);
  Core.randu(grayRnd, 0, noise);
  Core.add(image, grayRnd, image);
  processOperation();
  updateView();
}

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

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

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

Core.add(roberts1, roberts2, roberts);

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

@Override
  public Result process(CvPipeline pipeline) throws Exception {
    Mat mat = pipeline.getWorkingImage();

    Mat kernel = Mat.eye(new Size(2, 2), CvType.CV_32FC1);
    kernel.put(0, 0, 0, 1, -1, 0);
    Mat roberts1 = new Mat();
    Imgproc.filter2D(mat, roberts1, CvType.CV_32FC1, kernel);
    Core.convertScaleAbs(roberts1, roberts1);

    kernel.put(0, 0, 1, 0, 0, -1);
    Mat roberts2 = new Mat();
    Imgproc.filter2D(mat, roberts2, CvType.CV_32FC1, kernel);
    Core.convertScaleAbs(roberts2, roberts2);

    Mat roberts = new Mat();
    Core.add(roberts1, roberts2, roberts);
    
    kernel.release();
    roberts1.release();
    roberts2.release();

    return new Result(roberts);
  }
}

相关文章

Core类方法