Sevak Tadevosyan
09/17/2024, 10:39 AMBitmap
image from ImageAnalyzer
to C++
via JNI
I receive byteArray
from bitmap and pass to C++ function and create CV::Mat
image, here is the code sample:
Java_com_sparsa_android_sdk_ui_camera_ImageAnalyzer_detect_1document_1edges_1ex(
JNIEnv *env,
jobject thiz,
jint width,
jint height,
jint bytes_per_pixel,
jbyteArray img_bytes,
jstring output_image_path
) {
jsize length = env->GetArrayLength(img_bytes);
jbyte* buffer = new jbyte[length];
result = detect_document_edges_ex(
env,
static_cast<int32_t>(width),
static_cast<int32_t>(height),
static_cast<int32_t>(bytes_per_pixel),
reinterpret_cast<u_char *>(img_bytes),
const_cast<char *>(outputPath)
);
...
}
struct DetectionResult* detect_document_edges_ex(
JNIEnv* env,
int32_t width,
int32_t height,
int32_t bytesPerPixel,
u_char *imgBytes,
char* outputImagePath
) {
cv::Mat image = cv::Mat(height, width, bytesPerPixel, imgBytes);
bool result = cv::imwrite(outputImagePath, image); <- This saved image is broken in file system
....
}