package com.bytesflow.opencv.media.test; import com.bytesflow.opencv.media.jni.PQCVMediaProcessor; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class OpenCVImageBlurTest { public static void main(String[] args) { int count = 10; try { PQCVMediaProcessor.initSDK("/Users/devyk/Data/Project/sample/github_code/OpenCVSample/output/lib/libpiaoquan_java_opencv.dylib"); } catch (FileNotFoundException e) { e.printStackTrace(); return; } ExecutorService executorService = Executors.newFixedThreadPool(count); for (; ; ) { CountDownLatch countDownLatch = new CountDownLatch(count); for (int i = 0; i < count; i++) { executorService.execute(new ImageBlurRunable(countDownLatch)); } try { countDownLatch.await(); Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } private static class ImageBlurRunable implements Runnable { private CountDownLatch countDownLatch; public ImageBlurRunable(CountDownLatch countDownLatch) { this.countDownLatch = countDownLatch; } @Override public void run() { blurTest(); countDownLatch.countDown(); } } private static void blurTest() { try { String path = "/Users/devyk/Downloads/black.png"; int ret; ret = PQCVMediaProcessor.blurDetectionFromImagePath(path); System.out.println("PQCVMediaProcessor path = " + ret); File file = new File(path); byte[] images = new byte[(int) file.length()]; FileInputStream fileInputStream = new FileInputStream(file); fileInputStream.read(images); ret = PQCVMediaProcessor.blurDetectionFromImageBytes(images); fileInputStream.close(); System.out.println("PQCVMediaProcessor bytes = " + ret); } catch (Exception e) { e.printStackTrace(); } } }