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));
}
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;
}
}
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;
}
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);
}
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);
}
Aggregations