mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-05 06:06:53 +08:00
Merge pull request #402 from abankowski/java-interop
Enhance interop with Java
This commit is contained in:
@@ -47,6 +47,14 @@ JNIEXPORT jstring JNICALL Java_com_openalpr_jni_Alpr_native_1recognize__Ljava_la
|
||||
JNIEXPORT jstring JNICALL Java_com_openalpr_jni_Alpr_native_1recognize___3B
|
||||
(JNIEnv *, jobject, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: com_openalpr_jni_Alpr
|
||||
* Method: native_recognize
|
||||
* Signature: (JIII)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_openalpr_jni_Alpr_native_1recognize__JIII
|
||||
(JNIEnv *, jobject, jlong, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_openalpr_jni_Alpr
|
||||
* Method: set_default_region
|
||||
|
@@ -88,6 +88,24 @@ JNIEXPORT jstring JNICALL Java_com_openalpr_jni_Alpr_native_1recognize___3B
|
||||
return env->NewStringUTF(json.c_str());
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_openalpr_jni_Alpr_native_1recognize__JIII
|
||||
(JNIEnv *env, jobject thisObj, jlong data, jint bytesPerPixel, jint width, jint height)
|
||||
{
|
||||
//printf("Recognize data pointer");
|
||||
|
||||
AlprResults results = nativeAlpr->recognize(
|
||||
reinterpret_cast<unsigned char*>(data),
|
||||
static_cast<int>(bytesPerPixel),
|
||||
static_cast<int>(width),
|
||||
static_cast<int>(height),
|
||||
std::vector<AlprRegionOfInterest>());
|
||||
|
||||
std::string json = Alpr::toJson(results);
|
||||
|
||||
return env->NewStringUTF(json.c_str());
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_openalpr_jni_Alpr_set_1default_1region
|
||||
(JNIEnv *env, jobject thisObj, jstring jdefault_region)
|
||||
{
|
||||
|
@@ -15,6 +15,7 @@ public class Alpr {
|
||||
private native boolean is_loaded();
|
||||
private native String native_recognize(String imageFile);
|
||||
private native String native_recognize(byte[] imageBytes);
|
||||
private native String native_recognize(long imageData, int bytesPerPixel, int imgWidth, int imgHeight);
|
||||
|
||||
private native void set_default_region(String region);
|
||||
private native void detect_region(boolean detectRegion);
|
||||
@@ -62,6 +63,18 @@ public class Alpr {
|
||||
}
|
||||
|
||||
|
||||
public AlprResults recognize(long imageData, int bytesPerPixel, int imgWidth, int imgHeight) throws AlprException
|
||||
{
|
||||
try {
|
||||
String json = native_recognize(imageData, bytesPerPixel, imgWidth, imgHeight);
|
||||
return new AlprResults(json);
|
||||
} catch (JSONException e)
|
||||
{
|
||||
throw new AlprException("Unable to parse ALPR results");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setTopN(int topN)
|
||||
{
|
||||
set_top_n(topN);
|
||||
|
Reference in New Issue
Block a user