Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JAVA
- final Capturer sf_capturer = service.createCapturer(service.new Config("common_capturer4_singleface.xml"));
- // get original data
- final RawImage original_rgb = readImage("data/depth_liveness/original_rgb.bmp", "bmp");
- original_depth_ptr = readDepthMap("data/depth_liveness/original_depth.tiff"); // native function in JNI
- final float zpd = 575.5f;
- final float h_fov = (float) (2*Math.atan((float)original_rgb.width / 2 / zpd) / Math.PI * 180);
- final float v_fov = (float) (2*Math.atan((float)original_rgb.height / 2 / zpd) / Math.PI * 180);
- DepthMapRaw original_depth_map = new DepthMapRaw();
- original_depth_map.depth_map_rows = original_rgb.height;
- original_depth_map.depth_map_cols = original_rgb.width;
- original_depth_map.depth_map_2_image_offset_x = 0;
- original_depth_map.depth_map_2_image_offset_y = 0;
- original_depth_map.depth_map_2_image_scale_x = 1;
- original_depth_map.depth_map_2_image_scale_y = 1;
- original_depth_map.horizontal_fov = h_fov;
- original_depth_map.vertical_fov = v_fov;
- original_depth_map.depth_unit_in_millimeters = 1;
- original_depth_map.depth_data_ptr = original_depth_ptr;
- original_depth_map.depth_data_stride_in_bytes = 2*original_rgb.width;
- // create depth liveness estimator
- final DepthLivenessEstimator dl_estimator = service.createDepthLivenessEstimator(service.new Config("depth_liveness_estimator_cnn.xml"));
- DepthLivenessEstimator.Liveness original_liveness = dl_estimator.estimateLiveness(original_sample, original_depth_map);
- RawImage readImage(final String filename, final String format)
- {
- try {
- final File file = new File(filename);
- final BufferedImage img = ImageIO.read(file);
- assertEquals(img.getType(), BufferedImage.TYPE_3BYTE_BGR);
- final byte[] pixels = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
- return new RawImage(img.getWidth(), img.getHeight(), RawImage.Format.FORMAT_BGR, pixels);
- }
- catch (IOException e) {
- System.out.println("Error read '" + filename + "': " + e);
- }
- return null;
- }
- // JNI
- #include <jni.h>
- #include <opencv2/opencv.hpp>
- extern "C"
- JNIEXPORT jlong JNICALL Java_testcase_TestEstimators_readDepthMap
- (JNIEnv * env, jobject thiz, jstring jfilename)
- {
- const char * buf = env->GetStringUTFChars(jfilename, NULL);
- std::string filename = buf;
- env->ReleaseStringUTFChars(jfilename, buf);
- cv::Mat depth_map = cv::imread(filename, -1);
- unsigned char * data = new unsigned char[depth_map.rows * depth_map.cols * depth_map.elemSize()];
- memcpy(data, depth_map.data, depth_map.rows * depth_map.cols * depth_map.elemSize());
- return (jlong) data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement