java通过jni调用opencv处理图像的方法
程序员文章站
2024-02-20 09:13:10
1. 建立java文件
public class getimagefeature {
static{
system.loadlibrary("geti...
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
4. 执行java程序
将生成dll复制到java工程src文件夹下,java xx 运行程序
以上这篇java通过jni调用opencv处理图像的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
下一篇: 探讨如何计算age的sql函数
推荐阅读
-
java通过jni调用opencv处理图像的方法
-
JNA—JNI终结者,java调用dll、ocx、so最简单的方法 博客分类: C/C++ JNIJavaC#CC++
-
Java通过反射调用其他类的私有属性和私有方法
-
通过JAVA的反射调用类中的公有私有方法
-
解决Java调用BAT批处理不弹出cmd窗口的方法分析
-
Java通过调用C/C++实现的DLL动态库——JNI的方法
-
解决Java调用BAT批处理不弹出cmd窗口的方法分析
-
Java通过调用C/C++实现的DLL动态库——JNI的方法
-
关于通过java调用datax,返回任务执行的方法
-
安卓应用开发通过java调用c++ jni的图文使用方法