opencv 如何在Kotlin中提高运行so文件的速度?

evrscar2  于 2023-08-06  发布在  Kotlin
关注(0)|答案(1)|浏览(148)

我有两个人脸检测项目。一个是Java项目,另一个是Kotlin。这两个项目都使用mlkit进行人脸检测,使用opencv c引擎进行人脸识别。C引擎在两个项目中完全相同。在构建了两个项目之后,当我运行它们时,它们的c++引擎运行时是不同的。Java项目比Kotlin更快。

  1. JNIEXPORT jfloat JNICALL
  2. FACE_ENGINE_METHOD(nativeExtractLiveFeature)(JNIEnv *env, jobject instance,
  3. jobject bmp, jint left, jint top, jint right, jint bottom,
  4. jfloatArray landmarksX, jfloatArray landmarksY, jfloatArray features)

字符串
这是我想称之为C++代码。我把它导入到这样的项目中。

  1. @Keep
  2. private native static float nativeExtractLiveFeature(Bitmap bmp, int leftFace, int topFace, int rightFace, int bottomFace, float[] landmarksX, float[] landmarksY, float[] features); // java
  3. @Keep
  4. private external fun nativeExtractLiveFeature(bmp: Bitmap, leftFace: Int, topFace: Int, rightFace: Int, bottomFace: Int, landmarksX: FloatArray, landmarksY: FloatArray, features: FloatArray): Float //kotlin


Java项目现在比Kotlin快2倍。请告诉我是什么原因造成的。我需要提高Kotlin项目的速度,使其与Java项目一样快。我想知道任何可能的方法。请帮帮我- 谢谢-谢谢

ztmd8pv5

ztmd8pv51#

看看我如何保存文件,然后打开它,然后找到脸。下面是如何实现的代码:

  1. import cv2
  2. face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
  3. # Path to video file
  4. cap = cv2.VideoCapture(1)
  5. # Used as counter variable
  6. count = 1
  7. # checks whether frames were extracted
  8. success = 1
  9. while success:
  10. # get each frame from the video
  11. # '_' is a flag to show if the frame was read correctly or not
  12. # 'img' is the frame itself
  13. _, image = cap.read()
  14. if count <= 1:
  15. # Saves the frames with frame-count
  16. cv2.imwrite("frame_%d.jpg" % count, image)
  17. count += 1
  18. if count == 2:
  19. count = 1
  20. frame = cv2.imread('frame_1.jpg')
  21. # use the frames below
  22. if cv2.waitKey(1) & 0xFF == ord('q'):
  23. break
  24. # When everything done, release the capture
  25. cap.release()
  26. cv2.destroyAllWindows()

字符串

展开查看全部

相关问题