image_tools.h 1.58 KB
Newer Older
姜天宇's avatar
姜天宇 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//
// Created by dizi on 2024/7/12.
//

#ifndef CATERINGDETECT_IMAGE_TOOLS_H
#define CATERINGDETECT_IMAGE_TOOLS_H

#include <jni.h>
#include <string>
#include "android/log.h"
#include <unistd.h>
#include <vector>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <android/bitmap.h>
16
#include "data_type_convert_tools.h"
姜天宇's avatar
姜天宇 committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

#define TAG "opencv_tools -jni"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,  TAG, __VA_ARGS__)
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)

/**
 * 生成一个空的ARGB8888的Bitmap
 * @param env
 * @param width
 * @param height
 * @return
 */
jobject generate_empty_argb8888_bitmap(JNIEnv *env, int width, int height);
/**
 * 将Bitmap转化为Mat
 * @param env
 * @param bitmap
 * @return
 */
cv::Mat convert_bitmap_to_mat(JNIEnv *env, jobject bitmap);
/**
 * 将Mat转化成Bitmap
 * @param env
 * @param mat
 * @return
 */
jobject convert_mat_to_bitmap(JNIEnv *env, cv::Mat mat);

/**
 * 在MAT上绘制框
 * @param mat
 * @param left_top_x
 * @param left_top_y
 * @param right_bottom_x
 * @param right_bottom_y
 * @return
 */
cv::Mat draw_rect_on_mat(cv::Mat mat, int left_top_x, int left_top_y, int right_bottom_x, int right_bottom_y);

57 58 59 60 61 62 63 64 65 66 67 68
/**
 * 在mat上绘制框和文字
 * @param mat
 * @param left_top_x
 * @param left_top_y
 * @param right_bottom_x
 * @param right_bottom_y
 * @param text
 * @return
 */
cv::Mat draw_rect_text_on_mat(cv::Mat mat, int left_top_x, int left_top_y, int right_bottom_x, int right_bottom_y, char* text);

姜天宇's avatar
姜天宇 committed
69
#endif