private void updateHueImage() { hsvList.clear(); hsvList.add(hsv); // hue初始化为与hsv大小深度一样的矩阵,色调的度量是用角度表示的,红绿蓝之间相差120度,反色相差180度 hue.create(hsv.size(), hsv.depth()); hueList.clear(); hueList.add(hue); MatOfInt from_to = new MatOfInt(0, 0); // 将hsv第一个通道(也就是色调)的数复制到hue中,0索引数组 Core.mixChannels(hsvList, hueList, from_to); }
@Override public Result process(CvPipeline pipeline) throws Exception { Mat mat = pipeline.getWorkingImage(); Imgproc.Laplacian(mat, mat, mat.depth()); return null; } }
public BufferedImage toBufferedImage() { Integer type = null; if (mat.type() == CvType.CV_8UC1) { type = BufferedImage.TYPE_BYTE_GRAY; } else if (mat.type() == CvType.CV_8UC3) { type = BufferedImage.TYPE_3BYTE_BGR; } else if (mat.type() == CvType.CV_32F) { type = BufferedImage.TYPE_BYTE_GRAY; Mat tmp = new Mat(); mat.convertTo(tmp, CvType.CV_8UC1, 255); mat = tmp; } if (type == null) { throw new Error(String.format("Unsupported Mat: type %d, channels %d, depth %d", mat.type(), mat.channels(), mat.depth())); } BufferedImage image = new BufferedImage(mat.cols(), mat.rows(), type); mat.get(0, 0, ((DataBufferByte) image.getRaster().getDataBuffer()).getData()); return image; }
static boolean isEqual(Frame frame, org.opencv.core.Mat mat) { return mat != null && frame != null && frame.image != null && frame.image.length > 0 && frame.imageWidth == mat.cols() && frame.imageHeight == mat.rows() && frame.imageChannels == mat.channels() && getMatDepth(frame.imageDepth) == mat.depth() && new Pointer(frame.image[0].position(0)).address() == mat.dataAddr(); } public org.opencv.core.Mat convertToOrgOpenCvCoreMat(Frame frame) {
public static BufferedImage toBufferedImage(Mat m) { Integer type = null; if (m.type() == CvType.CV_8UC1) { type = BufferedImage.TYPE_BYTE_GRAY; } else if (m.type() == CvType.CV_8UC3) { type = BufferedImage.TYPE_3BYTE_BGR; } else if (m.type() == CvType.CV_32F) { type = BufferedImage.TYPE_BYTE_GRAY; Mat tmp = new Mat(); m.convertTo(tmp, CvType.CV_8UC1, 255); // Copy the results into the original Mat and release our temp copy so that when // the caller releases the original Mat there is no memory leak. tmp.copyTo(m); tmp.release(); } if (type == null) { throw new Error(String.format("Unsupported Mat: type %d, channels %d, depth %d", m.type(), m.channels(), m.depth())); } BufferedImage image = new BufferedImage(m.cols(), m.rows(), type); m.get(0, 0, ((DataBufferByte) image.getRaster().getDataBuffer()).getData()); return image; }
frame.imageWidth = mat.cols(); frame.imageHeight = mat.rows(); frame.imageDepth = getFrameDepth(mat.depth()); frame.imageChannels = mat.channels(); frame.imageStride = (int)mat.step1(); ByteBuffer byteBuffer = new BytePointer() { { address = mat.dataAddr(); } }.capacity(mat.rows() * mat.step1() * mat.elemSize1()).asByteBuffer(); switch (mat.depth()) { case CV_8U: case CV_8S: