Guest User

Untitled

a guest
Dec 12th, 2019
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // JAVA
  2.  
  3. final Capturer sf_capturer = service.createCapturer(service.new Config("common_capturer4_singleface.xml"));
  4.  
  5. // get original data
  6. final RawImage original_rgb = readImage("data/depth_liveness/original_rgb.bmp", "bmp");
  7.  
  8. original_depth_ptr = readDepthMap("data/depth_liveness/original_depth.tiff"); // native function in JNI
  9.  
  10. final float zpd = 575.5f;
  11. final float h_fov = (float) (2*Math.atan((float)original_rgb.width / 2 / zpd) / Math.PI * 180);
  12. final float v_fov = (float) (2*Math.atan((float)original_rgb.height / 2 / zpd) / Math.PI * 180);
  13.  
  14. DepthMapRaw original_depth_map = new DepthMapRaw();
  15. original_depth_map.depth_map_rows = original_rgb.height;
  16. original_depth_map.depth_map_cols = original_rgb.width;
  17. original_depth_map.depth_map_2_image_offset_x = 0;
  18. original_depth_map.depth_map_2_image_offset_y = 0;
  19. original_depth_map.depth_map_2_image_scale_x = 1;
  20. original_depth_map.depth_map_2_image_scale_y = 1;
  21. original_depth_map.horizontal_fov = h_fov;
  22. original_depth_map.vertical_fov = v_fov;
  23. original_depth_map.depth_unit_in_millimeters = 1;
  24. original_depth_map.depth_data_ptr = original_depth_ptr;
  25. original_depth_map.depth_data_stride_in_bytes = 2*original_rgb.width;
  26.  
  27. // create depth liveness estimator
  28. final DepthLivenessEstimator dl_estimator = service.createDepthLivenessEstimator(service.new Config("depth_liveness_estimator_cnn.xml"));
  29.  
  30. DepthLivenessEstimator.Liveness original_liveness = dl_estimator.estimateLiveness(original_sample, original_depth_map);
  31.  
  32.  
  33. RawImage readImage(final String filename, final String format)
  34. {
  35. try {
  36. final File file = new File(filename);
  37. final BufferedImage img = ImageIO.read(file);
  38.  
  39. assertEquals(img.getType(), BufferedImage.TYPE_3BYTE_BGR);
  40.  
  41. final byte[] pixels = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
  42. return new RawImage(img.getWidth(), img.getHeight(), RawImage.Format.FORMAT_BGR, pixels);
  43. }
  44. catch (IOException e) {
  45. System.out.println("Error read '" + filename + "': " + e);
  46. }
  47. return null;
  48. }
  49.  
  50. // JNI
  51.  
  52. #include <jni.h>
  53. #include <opencv2/opencv.hpp>
  54.  
  55. extern "C"
  56. JNIEXPORT jlong JNICALL Java_testcase_TestEstimators_readDepthMap
  57. (JNIEnv * env, jobject thiz, jstring jfilename)
  58. {
  59. const char * buf = env->GetStringUTFChars(jfilename, NULL);
  60. std::string filename = buf;
  61. env->ReleaseStringUTFChars(jfilename, buf);
  62.  
  63. cv::Mat depth_map = cv::imread(filename, -1);
  64. unsigned char * data = new unsigned char[depth_map.rows * depth_map.cols * depth_map.elemSize()];
  65. memcpy(data, depth_map.data, depth_map.rows * depth_map.cols * depth_map.elemSize());
  66.  
  67. return (jlong) data;
  68. }
RAW Paste Data