123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- 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();
- }
- }
- }
|