java通过jni调用opencv处理图像的方法
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处理图像的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Spring下token过期时间分平台(web和app)设置方法
本文详细介绍了在Spring环境下,针对web端和APP端实现不同token过期时间的方法,通过整合SpringBoot、springSecurity和JWT框架,文章讲解了登录流程、JWT的基本组成以及token鉴权的核心步骤,需要的朋友可以参考下2024-10-10java中PO、VO、BO、POJO、DAO、DTO、TO、QO、Bean、conn的理解
这篇文章主要介绍了java中PO、VO、BO、POJO、DAO、DTO、TO、QO、Bean、conn的理解,需要的朋友可以参考下2020-02-02
最新评论