Search in sources :

Example 1 with Mat

use of org.bytedeco.opencv.opencv_core.Mat in project javacv by bytedeco.

the class Similarity method main.

public static void main(String[] args) {
    Mat img1 = opencv_imgcodecs.imread("face.jpg");
    Mat img2 = img1.clone();
    opencv_imgproc.GaussianBlur(img2, img2, new Size(15, 15), 10);
    double psnr = getPSNR(img1, img2);
    Scalar mssim = getMSSIM(img1, img2);
    System.out.println("PSNR: " + psnr);
    System.out.printf("SSIM: %f, %f, %f\n", mssim.get(0), mssim.get(1), mssim.get(2));
}
Also used : Mat(org.bytedeco.opencv.opencv_core.Mat) Size(org.bytedeco.opencv.opencv_core.Size) Scalar(org.bytedeco.opencv.opencv_core.Scalar)

Example 2 with Mat

use of org.bytedeco.opencv.opencv_core.Mat in project javacv by bytedeco.

the class Similarity method getPSNR.

private static double getPSNR(Mat I1, Mat I2) {
    Mat s1 = new Mat();
    // |I1 - I2|
    opencv_core.absdiff(I1, I2, s1);
    // cannot make a square on 8 bits
    s1.convertTo(s1, opencv_core.CV_32F);
    // |I1 - I2|^2
    s1 = s1.mul(s1).asMat();
    // sum elements per channel
    Scalar s = opencv_core.sumElems(s1);
    // sum channels
    double sse = s.get(0) + s.get(1) + s.get(2);
    if (sse <= 1e-10) {
        // for small values return zero
        return 0;
    } else {
        double mse = sse / (double) (I1.channels() * I1.total());
        double psnr = 10.0 * Math.log10((255 * 255) / mse);
        return psnr;
    }
}
Also used : Mat(org.bytedeco.opencv.opencv_core.Mat) Scalar(org.bytedeco.opencv.opencv_core.Scalar)

Example 3 with Mat

use of org.bytedeco.opencv.opencv_core.Mat in project javacpp-presets by bytedeco.

the class RealSense2Show method toColorMap.

private static Mat toColorMap(Mat depth, double max, double min) {
    Mat out = new Mat();
    if (max < 0 || min < 0) {
        double[] minVal = new double[1];
        double[] maxVal = new double[1];
        opencv_core.minMaxLoc(depth, minVal, maxVal, null, null, null);
        min = minVal[0];
        max = maxVal[0];
    }
    double scale = 255 / (max - min);
    depth.convertTo(out, opencv_core.CV_8UC1, scale, -min * scale);
    opencv_imgproc.applyColorMap(out, out, opencv_imgproc.COLORMAP_JET);
    return out;
}
Also used : Mat(org.bytedeco.opencv.opencv_core.Mat)

Example 4 with Mat

use of org.bytedeco.opencv.opencv_core.Mat in project javacpp-presets by bytedeco.

the class openpose method main.

public static void main(String[] args) {
    // Parse command arguments
    boolean doHands = false;
    boolean doFace = false;
    String[] pargs = new String[2];
    int pargsIdx = 0;
    for (String arg : args) {
        if (arg.startsWith("-")) {
            if (arg.equals("--hands")) {
                doHands = true;
            }
            if (arg.equals("--face")) {
                doFace = true;
            } else {
                System.err.println("Usage: <openpose sample> [--hands] [--face] IMAGE_IN IMAGE_OUT");
                System.exit(-1);
            }
        } else {
            pargs[pargsIdx] = arg;
            pargsIdx += 1;
        }
    }
    // Configure OpenPose
    OpWrapper opWrapper = new OpWrapper(ThreadManagerMode.Asynchronous);
    opWrapper.disableMultiThreading();
    opWrapper.configure(mkWrapperStructPose());
    if (doFace) {
        WrapperStructFace face = new WrapperStructFace();
        face.enable(true);
        opWrapper.configure(face);
    }
    if (doHands) {
        WrapperStructHand hand = new WrapperStructHand();
        hand.enable(true);
        opWrapper.configure(hand);
    }
    // Start OpenPose
    opWrapper.start();
    Mat ocvIm = imread(pargs[0]);
    Matrix opIm = OP_CV2OPCONSTMAT(ocvIm);
    Datum dat = new Datum();
    dat.cvInputData(opIm);
    Datums dats = new Datums();
    dats.put(dat);
    opWrapper.emplaceAndPop(dats);
    dat = dats.get(0);
    // Print keypoints
    FloatArray poseArray = dat.poseKeypoints();
    IntPointer dimSizes = poseArray.getSize();
    int numPeople = dimSizes.get(0);
    int numJoints = dimSizes.get(1);
    for (int i = 0; i < numPeople; i++) {
        System.out.printf("Person %d\n", i);
        for (int j = 0; j < numJoints; j++) {
            System.out.printf("Limb %d\tx: %f\ty: %f\t: %f\n", j, poseArray.get(new int[] { i, j, 0 })[0], poseArray.get(new int[] { i, j, 1 })[0], poseArray.get(new int[] { i, j, 2 })[0]);
        }
    }
    // Save output
    Mat ocvMatOut = OP_OP2CVCONSTMAT(dat.cvOutputData());
    imwrite(pargs[1], ocvMatOut);
}
Also used : OpWrapper(org.bytedeco.openpose.OpWrapper) Mat(org.bytedeco.opencv.opencv_core.Mat) WrapperStructFace(org.bytedeco.openpose.WrapperStructFace) OpString(org.bytedeco.openpose.OpString) Matrix(org.bytedeco.openpose.Matrix) WrapperStructHand(org.bytedeco.openpose.WrapperStructHand)

Example 5 with Mat

use of org.bytedeco.opencv.opencv_core.Mat in project karate by karatelabs.

the class OpenCvUtils method show.

public static void show(byte[] bytes, String title) {
    Mat mat = read(bytes);
    show(toBufferedImage(mat), title);
}
Also used : Mat(org.bytedeco.opencv.opencv_core.Mat)

Aggregations

Mat (org.bytedeco.opencv.opencv_core.Mat)76 Point (org.bytedeco.opencv.opencv_core.Point)23 ArrayList (java.util.ArrayList)15 MatVector (org.bytedeco.opencv.opencv_core.MatVector)15 PointerScope (org.bytedeco.javacpp.PointerScope)14 FloatIndexer (org.bytedeco.javacpp.indexer.FloatIndexer)14 BufferedImage (java.awt.image.BufferedImage)12 IntIndexer (org.bytedeco.javacpp.indexer.IntIndexer)10 Scalar (org.bytedeco.opencv.opencv_core.Scalar)10 Test (org.junit.jupiter.api.Test)10 DoubleIndexer (org.bytedeco.javacpp.indexer.DoubleIndexer)9 Size (org.bytedeco.opencv.opencv_core.Size)9 UByteIndexer (org.bytedeco.javacpp.indexer.UByteIndexer)8 List (java.util.List)7 org.bytedeco.opencv.global.opencv_core (org.bytedeco.opencv.global.opencv_core)7 WritableRaster (java.awt.image.WritableRaster)6 IOException (java.io.IOException)6 Arrays (java.util.Arrays)6 Collections (java.util.Collections)6 Collectors (java.util.stream.Collectors)6