【发布时间】:2017-07-19 16:13:31
【问题描述】:
我正在尝试在名为 Processing 的程序中使用 OpenCV 的均值偏移函数,该程序是一种基于 Java 的语言。到目前为止,我知道该函数需要两个 mat 和两个 double,[ pyrMeanShiftFiltering( Mat, Mat, Double, Double) ] 并且 mat 需要是 8 位和 3 个通道。但是,当我运行它时,它似乎只对图像的上 3/4 起作用,而将其余部分剪掉。
有谁知道如何让这个函数在整个图像上运行?
示例图片:cat.jpg
import gab.opencv.*;
import java.nio.*;
import org.opencv.imgproc.Imgproc;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Core;
OpenCV opencv;
Imgproc imgproc;
PImage canny;
PImage src, out;
Mat one, two;
double a = 20.0;
double b = 10.0;
void setup() {
src = loadImage("cat.jpg");
size( 429, 360);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
one = new Mat( width, height, CvType.CV_8UC3);
two = new Mat( width, height, CvType.CV_8UC3);
one = toMat(src);
imgproc.pyrMeanShiftFiltering( one, two, a, b);
out = toPImage(two);
}
void draw() {
image(out, 0, 0, width, height);
}
Mat toMat(PImage image) {
int w = image.width;
int h = image.height;
Mat mat = new Mat(h, w, CvType.CV_8UC3);
byte[] data8 = new byte[w*h*4];
int[] data32 = new int[w*h];
arrayCopy(image.pixels, data32);
ByteBuffer bBuf = ByteBuffer.allocate(w*h*4);
IntBuffer iBuf = bBuf.asIntBuffer();
iBuf.put(data32);
bBuf.get(data8);
mat.put(0, 0, data8);
return mat;
}
PImage toPImage(Mat mat) {
int w = mat.width();
int h = mat.height();
PImage image = createImage(w, h, ARGB);
byte[] data8 = new byte[w*h*4];
int[] data32 = new int[w*h];
mat.get(0, 0, data8);
ByteBuffer.wrap(data8).asIntBuffer().get(data32);
arrayCopy(data32, image.pixels);
return image;
}
【问题讨论】:
标签: java opencv matrix processing pixels