-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathnative-lib.cpp
More file actions
41 lines (32 loc) · 1.42 KB
/
native-lib.cpp
File metadata and controls
41 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
#include <jni.h>
#include <android/log.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#define TAG "NativeLib"
using namespace std;
using namespace cv;
extern "C" {
/**
* Native function called from Java/Kotlin to process camera frames
* This applies OpenCV adaptive threshold to convert grayscale image to binary
* @param env JNI environment
* @param instance calling object instance
* @param matAddr memory address of OpenCV Mat object from Java
*/
void JNICALL
Java_com_example_nativeopencvandroidtemplate_MainActivity_adaptiveThresholdFromJNI(JNIEnv *env,
jobject instance,
jlong matAddr) {
// Get Mat from memory address passed from Java/Kotlin
Mat &mat = *(Mat *) matAddr;
// Record start time for performance measurement
clock_t begin = clock();
// Apply OpenCV adaptive threshold
// Parameters: input/output mat, max value, adaptive method, threshold type, block size, constant
cv::adaptiveThreshold(mat, mat, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 9, 10);
// Calculate and log processing time
double totalTime = double(clock() - begin) / CLOCKS_PER_SEC;
__android_log_print(ANDROID_LOG_INFO, TAG, "adaptiveThreshold computation time = %f seconds\n",
totalTime);
}
}