mirror of
https://github.com/open-mmlab/mmdeploy.git
synced 2025-01-14 08:09:43 +08:00
* add java classifier detector * add segmentor * fix lint * add ImageRestorer java apis and demo * remove useless count parameter for Segmentor and Restorer, add PoseDetector * add RotatedDetection java api and demo * add Ocr java demo and apis * remove mmrotate ncnn java api and demo * fix lint * sync java api folder after rebase to master * fix include * remove record * fix java apis dir path in cmake * add java demo readme * fix lint mdformat * add test javaapi ci * fix lint * fix flake8 * fix test javaapi ci * refactor readme.md * fix install opencv for ci * fix install opencv : add permission * add all codebases and mmcv install * add torch * install mmdeploy * fix image path * fix picture path * fix import ncnn * fix import ncnn * add submodule of pybind * fix pybind submodule * change download to git clone for submodule * fix ncnn dir * fix README error * simplify the github ci * fix ci * fix yapf * add JNI as required * fix Capitalize * fix Capitalize * fix copyright * ignore .class changed * add OpenJDK installation docs * install target of javaapi * simplify ci * add jar * fix ci * fix ci * fix test java command * debugging what failed * debugging what failed * debugging what failed * add java version info * install openjdk * add java env var * fix export * fix export * fix export * fix export * fix picture path * fix picture path * fix file name * fix file name * fix README * remove java_api strategy * fix python version * format task name * move args position * extract common utils code * show image class result * add detector result * segmentation result format * add ImageRestorer result * add PoseDetection java result format * fix ci * stage ocr * add visualize * move utils * fix lint * fix ocr bugs * fix ci demo * fix java classpath for ci * fix popd * fix ocr demo text garbled * fix ci * fix ci * fix ci * fix path of utils ci
55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
|
|
#ifndef MMDEPLOY_CSRC_APIS_JAVA_NATIVE_COMMON_H_
|
|
#define MMDEPLOY_CSRC_APIS_JAVA_NATIVE_COMMON_H_
|
|
|
|
#include <jni.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "mmdeploy/apis/c/common.h"
|
|
#include "mmdeploy/core/logger.h"
|
|
#include "mmdeploy/core/utils/formatter.h"
|
|
|
|
template <typename F>
|
|
static auto With(JNIEnv *env, jobjectArray imgs, F f) noexcept {
|
|
auto mat_clazz = env->FindClass("mmdeploy/Mat");
|
|
auto shape_field = env->GetFieldID(mat_clazz, "shape", "[I");
|
|
auto format_field = env->GetFieldID(mat_clazz, "format", "I");
|
|
auto type_field = env->GetFieldID(mat_clazz, "type", "I");
|
|
auto data_field = env->GetFieldID(mat_clazz, "data", "[B");
|
|
auto num = env->GetArrayLength(imgs);
|
|
std::vector<mm_mat_t> mats;
|
|
std::vector<jbyteArray> datum;
|
|
|
|
mats.reserve(num);
|
|
datum.reserve(num);
|
|
|
|
for (int i = 0; i < num; ++i) {
|
|
auto obj = env->GetObjectArrayElement(imgs, i);
|
|
auto shape_obj = env->GetObjectField(obj, shape_field);
|
|
auto shape = env->GetIntArrayElements((jintArray)shape_obj, nullptr);
|
|
auto format = env->GetIntField(obj, format_field);
|
|
auto type = env->GetIntField(obj, type_field);
|
|
auto &mat = mats.emplace_back();
|
|
mat.height = shape[0];
|
|
mat.width = shape[1];
|
|
mat.channel = shape[2];
|
|
env->ReleaseIntArrayElements((jintArray)shape_obj, shape, JNI_ABORT);
|
|
mat.format = (mm_pixel_format_t)format;
|
|
mat.type = (mm_data_type_t)type;
|
|
auto data_obj = env->GetObjectField(obj, data_field);
|
|
mat.data = (uint8_t *)env->GetByteArrayElements((jbyteArray)data_obj, nullptr);
|
|
datum.push_back((jbyteArray)data_obj);
|
|
}
|
|
|
|
auto ret = f(mats.data(), mats.size()); // ! f must not throw
|
|
|
|
for (int i = 0; i < num; ++i) {
|
|
env->ReleaseByteArrayElements(datum[i], (jbyte *)mats[i].data, JNI_ABORT);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
#endif // MMDEPLOY_CSRC_APIS_JAVA_NATIVE_COMMON_H_
|