怎么在java中使用jni调用opencv对图像进行处理?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
创新互联是一家专业提供颍上企业网站建设,专注与成都网站制作、网站设计、H5响应式网站、小程序制作等业务。10年已为颍上众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。
1. 建立java文件
public class getImageFeature { static{ System.loadLibrary("getImageFeatureDll"); } public native int getImageFeatureByName(String filename); public native int getImageFeatureByMemory(); public 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 <jni.h> /* 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: getImageFeatureByMemory * 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 <opencv2/opencv.hpp> /* * 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
看完上述内容,你们掌握怎么在java中使用jni调用opencv对图像进行处理的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
名称栏目:怎么在java中使用jni调用opencv对图像进行处理
当前网址:https://www.cdcxhl.com/article4/psciie.html
成都网站建设公司_创新互联,为您提供品牌网站制作、全网营销推广、网站建设、企业建站、搜索引擎优化、
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联