ImageBlurDetection.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Created by 阳坤 on 2022/2/23.
  3. //
  4. #include "ImageBlurDetection.h"
  5. static jint Java_JNI_OpenCV_ImagePathBlurDetection(JNIEnv *env, jobject obj, jstring filepath) {
  6. const char *image_path = env->GetStringUTFChars(filepath, 0);
  7. int ret = image_blur_detection(image_path);
  8. env->ReleaseStringUTFChars(filepath, image_path);
  9. return ret;
  10. }
  11. static jint
  12. Java_JNI_OpenCV_ImageBytesBlurDetection(JNIEnv *env, jobject obj, jbyteArray data) {
  13. jbyte *image_bytes = env->GetByteArrayElements(data, 0);
  14. int ret = bytes_blur_detection((uint8_t *) image_bytes,env->GetArrayLength(data));
  15. env->ReleaseByteArrayElements(data, image_bytes, 0);
  16. return ret;
  17. }
  18. static const JNINativeMethod configMethods[] = {
  19. {"blurDetectionFromImagePath", "(Ljava/lang/String;)I", (void **) Java_JNI_OpenCV_ImagePathBlurDetection},
  20. {"blurDetectionFromImageBytes", "([B)I", (void **) Java_JNI_OpenCV_ImageBytesBlurDetection},
  21. };
  22. /**
  23. * System.load(xxx.so) ִ
  24. * @param vm
  25. * @param pVoid
  26. * @return
  27. */
  28. int JNI_OnLoad(JavaVM *vm, void *pVoid) {
  29. JNIEnv *jniEnv;
  30. if (vm->GetEnv(reinterpret_cast<void **>(&jniEnv), JNI_VERSION_1_6) != JNI_OK)
  31. return JNI_ERR;
  32. jclass jcls = jniEnv->FindClass(JAVA_JNI_CLASS_PATH);
  33. if (jniEnv->RegisterNatives(jcls, configMethods, NELEM(configMethods)) != JNI_OK) {
  34. return JNI_ERR;
  35. }
  36. printf(" JNI_OnLoad ok.\n");
  37. return JNI_VERSION_1_6;
  38. };