java通过jni调用opencv处理图像的方法

网友投稿 225 2023-07-23

java通过jni调用opencv处理图像的方法

1. 建立java文件

public class getImageFeature {

static{

System.loadLibrary("getImageFeatureDll");

}

public native int getImageFeatureByName(String filename);

public native int getImageFeatureByMemory();

publihttp://c static void main(String[] args) {

getImageFeature test=new getImageFeature();

String filename = "D:/testpic/6af1399a64d10a399ad3247c01656bb7.jpg";

System.out.println(test.getImageFeatureByName(filename));

}

}

2. 切换到工程src文件夹

javac getImageFeature.java

javah getImageFeature

生成 getImageFeature.h 文件

/* DO NOT EDIT THIS FILE - it is machine generated */

#include

/* Header for class getImageFeature */

#ifndef _Included_getImageFeature

#define _Included_getImageFeature

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class: getImageFeature

* Method: getImageFeatureByName

* Signature: (Ljava/lang/String;)I

*/

JNIEXPORT jint JNICALL Java_getImageFeature_getImageFeatureByName

(JNIEnv *, jobject, jstring);

/*

* Class: getImageFeature

* Method: getImageFeatureByMemorxJcQJMOpgcy

* Signature: ()I

*/

JNIEXPORT jint JNICALL Java_getImageFeature_getImageFeatureByMemory

(JNIEnv *, jobject);

#ifdef __cplusplus

}

#endif

#endif

3. VS2013建立dll工程

添加getImageFeature.h 头文件,再添加getImageFeature.cpp文件,实现对应函数(工程属性中需包含jdk下的include目录)

C:\Program Files\Java\jdk1.8.0_20\include

C:\Program Files\Java\jdk1.8.0_20\include\win32

#include "getImageFeatureDll.h"

#include

/*

* Class: getImageFeature

* Method: getImageFeatureByName

* Signature: (Ljava/lang/String;)I

*/

JNIEXPORT jint JNICALL Java_getImageFeature_getImageFeatureByName

(JNIEnv *env, jobject obj, jstring filename)

{

const char *str_filename;

str_filename = env->GetStringUTFChars(filename, false);

cv::Mat image = cv::imread(str_filename);

cv::imshow("test", image);

cv::waitKey(20000);

return 0;

}

/*

* Class: getImageFeature

* Method: getImageFeatureByMemory

* Signature: ()I

*/

JNIEXPORT jint JNICALL Java_getImageFeature_getImageFeatureByMemory

(JNIEnv *, jobject)

{

return 0;

}

编译生成对应的dll

4. 执行java程序

将生成dll复制到java工程src文件夹下,java XX 运行程序

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:java类的加载过程以及类加载器的分析
下一篇:RestTemplate集成Ribbbon的示例代码
相关文章

 发表评论

暂时没有评论,来抢沙发吧~