「java调用mtcnn」JAVA调用dll

博主:adminadmin 2023-01-22 04:57:07 392

本篇文章给大家谈谈java调用mtcnn,以及JAVA调用dll对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java能调用matlab神经网络吗

一、matlab版本必须支持java

在command 模式下面运行deploytool,如果支持该命令即可使用

二、matlab中function的书写

%定义一个函数operation(a,b),求a与b的加减乘除运算,并返回结果

%函数定义function 输出变量列表[s,m,...] 函数名(输入变量列表)sum,sub,mul,div中

function [sum,sub,mul,div] = operation(a,b);

sum = a + b;

sub = a - b;

mul = a * b;

div = a / b;

end

PS:上面function后中括号部分与java中调用该operation的返回值有关系,在java中调用的 Object result[] = XXX.operation(4,a,b); 4表示有4个返回值,分别存放在result[0]到result[4]中。

三、使用matlab编译生成jar

在matlab命令窗口下输入 deploytool,就会弹出一个编译窗口,

然后点击,file,选择new-deployment project,

然后选择matlab builder jave。

name的地方填写工程名,

ocation填写该工程的存储位置。

点击ok。

然后,把m文件添加到工程中,先new一个class,这个class的名字就是你将来在java中需要new的class的名字,也就是matlab中operation所在的class名字然后将你的m文件添加到这个class目录下,然后直接build即可。

四、在java中使用matlab的函数

现在eclipse下面new一个新的java工程,然后将第三部build成功后产生的文件夹下面的distrib目录中的XXX.jar 以及你matlab安装目录下/toolbox/javabuilder/jar/javabuilder.jar加入你的java工程extend lib 中去。

然后你可以清晰的看到XXX.jar中包含的函数和类

五、可能碰到的问题

Exception in thread "main" java.lang.UnsatisfiedLinkError: Failed to find the library libmwmclmcrrt.so.7.13, required by MATLAB Builder JA, on java.library.path.

This library is typically installed along with MATLAB or the MCR, its absence may indicate an issue with that installation or the current path configuration.

The MCR version that this component is trying to use is: 7.13.

Failed to find the library mclmcrrt710.dll,required by MATLAB Builder JA, on java.library.path

原因是2009a要对应安装mclmcrrt7.10。在MATLAB安装目录下查找:\toolbox\compiler\deploy\win32,找到MCRInstaller.exe 安装,重启Eclipse即可。

java如何解决跨服务调用token不一致问题

1、session保存在服务端,客户端访问高并发时,服务端压力大。

2、扩展性差,服务器集群,就需要session数据共享。Java是一门面向对象编程语言,不仅吸收了C++语言的各种优点,还摒弃了C++里难以理解的多继承、指针等概念,因此Java语言具有功能强大和简单易用两个特征。

java 里面怎么调用本地媒体播放器

楼主,帮你写了个,调用windows的Media Player的,你看下,大概方法就是用

Runtime.getRuntime().exec(String cmd);

import java.io.IOException;

public class TestExecPlayer {

public static void main(String args[]){

String thePlayerPath = "C:\\Program Files\\Windows Media Player\\wmplayer.exe"; /*播放器的路径*/

try{

Process ps = Runtime.getRuntime().exec(thePlayerPath);

}catch (IOException e){

e.printStackTrace();

}

}

}

程序很简单,只是给你展示下,要怎么弄

如何通过JAVA代码调用网络打印机使其打印接收到的文件

用java实现本地打印:java.awt中提供了一些打印的API,要实现打印,首先要获得打印对象,然后继承Printable实现接口方法print,以便打印机进行打印,最后用用Graphics2D直接输出直接输出。下面代码实现了简单的打印功能:

java 如何调用一个已经存在的静态库,并输入和获取参数! 例如:静态库中已经存在函数 ret=ys_tpcall(aa);

给出一个windows下dll的实例。linux下.a的静态库只是头文件和编译有所不同,另外需要将编译后的动态库文件放入/usr/lib下,使用ldconfig载入。

一 先制作一个系统中有的DLL文件(cpp给出的sdk接口)

既然是测试我们就把我们这个dll叫做testDll吧,为了简单其间,我只写一个add方法,就是简单的2个数字相加,对于真正的开发中我们肯定会遇到其他类型,java到c/cpp中类型需要转换,具体类型转换对应关系g一下就能得到,我也不在列举。c/cpp中一个class一般包含2个文件,一个头文件定义(*.h),一个文件主体(*.c/*.cpp)。啰嗦了这么多还是直接动手吧,先在vs2008中建立一个工程(当然你也可以直接编写不用这些IDE工具,gcc g++的命令自己g。下同,不在注释不在废话),选取win32工程

键入工程名字testDll,点击next选取DLL,然后点击完成

打开我们的testdll.cpp,添加进我们的add方法

C++代码

1.int add(int a,int b){

2. return a+b;

3.}

int add(int a,int b){

return a+b;

}

注意到文件列表里并没有testDll.h,因为我们要给出调用者一个接口,如果不给头文件,人家就没办法调用,所以我们就必须添加一个头文件testDll.h。

C++代码

1.#ifdef TEST_DLL

2.#define TEST_API __declspec(dllexport)

3.#else

4.#define TEST_API __declspec(dllimport)

5.#endif

6.

7./* Set up for C function definitions, even when using C++ */

8.#ifdef __cplusplus

9.extern "C" {

10.#endif

11.

12.TEST_API int add(int,int);

13.

14./* Ends C function definitions when using C++ */

15.#ifdef __cplusplus

16.}

17.#endif

#ifdef TEST_DLL

#define TEST_API __declspec(dllexport)

#else

#define TEST_API __declspec(dllimport)

#endif

/* Set up for C function definitions, even when using C++ */

#ifdef __cplusplus

extern "C" {

#endif

TEST_API int add(int,int);

/* Ends C function definitions when using C++ */

#ifdef __cplusplus

}

#endif

在这个头文件中我们把我们的add方法给定义了进去。注意到testdll.cpp中#include "stdafx.h",所以我们就把这个testDll.h include进stdafx.h里面。

按道理说我们的这个dll已经完成了,但是一般c/cpp给接口SDK的时候大都给.h和.lib,为了一步生成dll和lib,我们添加进一个testDll.def,有了这个文件就可以一步生成dll和lib。在source file里右键add new item ,选择Module-Definition File

键入testDll,OK了,我们可以直接build了。生成testDll.dll和testDll.lib。

把testDll.dll扔到system32目录里等待我们高大威猛的java jni调用。

二 JNI

2.1 编写java文件

为了显示我们的与众相同,我们就把我们的这个java文件命名为Demo.java顺便直接带上包名

,因为我们知道人家给我们的接口里有个add方法,所以我们就直接来个调用吧。

Java代码

1.package com.testJni.testDemo;

2.

3.public class Demo {

4. static

5. {

6. //System.out.println(System.getProperty("java.library.path"));

7. System.loadLibrary("testDll");

8. System.loadLibrary("jniDll");

9. }

10. public native static int add(int a,int b);

11.

12.}

package com.testJni.testDemo;

public class Demo {

static

{

//System.out.println(System.getProperty("java.library.path"));

System.loadLibrary("testDll");

System.loadLibrary("jniDll");

}

public native static int add(int a,int b);

}

demo.java代码暂时如此,我们把将要生成的jni的dll叫做jniDll,有童鞋讲,我不想用你这个烂名字jniDll多俗啊,没关系,你可以换,随你换,生成文件后你再换也可以,现在换也可以。

2.2 生成.h头文件

javah命令,不多讲。生成的文件com_testJni_testDemo_Demo.h这个文件的命名规则我就不多讲了,一目了然。

C++代码

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

2.#include jni.h

3./* Header for class com_testJni_testDemo_Demo */

4.

5.#ifndef _Included_com_testJni_testDemo_Demo

6.#define _Included_com_testJni_testDemo_Demo

7.#ifdef __cplusplus

8.extern "C" {

9.#endif

10./*

11. * Class: com_testJni_testDemo_Demo

12. * Method: add

13. * Signature: (II)I

14. */

15.JNIEXPORT jint JNICALL Java_com_testJni_testDemo_Demo_add

16. (JNIEnv *, jclass, jint, jint);

17.

18.#ifdef __cplusplus

19.}

20.#endif

21.#endif

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

#include jni.h

/* Header for class com_testJni_testDemo_Demo */

#ifndef _Included_com_testJni_testDemo_Demo

#define _Included_com_testJni_testDemo_Demo

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class: com_testJni_testDemo_Demo

* Method: add

* Signature: (II)I

*/

JNIEXPORT jint JNICALL Java_com_testJni_testDemo_Demo_add

(JNIEnv *, jclass, jint, jint);

#ifdef __cplusplus

}

#endif

#endif

2.3 用c/cpp实现这个头文件

c/cpp中已经实现了这个add方法,我们只需要调用就可以啦。所以直接vs2008中建立一个dll工程,工程名我们就叫jniDll,具体过程不再多讲,方法同上面testDll的建立一样。在这个工程里kimmking把需要引用的包、文件等已经讲的很清楚了。打开jniDll.cpp,添加下面代码

C++代码

1.JNIEXPORT jint JNICALL Java_com_testJni_testDemo_Demo_add

2.(JNIEnv *env,jclass jobject,jint a,jint b){

3.

4. return add(a,b);

5.}

JNIEXPORT jint JNICALL Java_com_testJni_testDemo_Demo_add

(JNIEnv *env,jclass jobject,jint a,jint b){

return add(a,b);

}因为int对应的类型就刚好是jint,所以就不需要转换,其他需要转换的类型自己g对应关系转换,注意释放。

这个工程里我们还需要打开 stdafx.h添加

C++代码

1.#include jni.h

2.

3.#include "testDll.h"

4.#include "com_testJni_testDemo_Demo.h"

#include jni.h

#include "testDll.h"

#include "com_testJni_testDemo_Demo.h"

在编译这个jniDll工程的时候需要引入testDll.h,com_testJni_testDemo_Demo.h,另外添加testDll.lib这个依赖。

好了做好这些后,build下,生成了我们期待已久的jniDll.dll,把这个dll同样扔到system32下。

三 测试

本人特懒,不想写多余的class,所以直接修改Demo.java 这也是刚才为什么讲暂时如此的原因

Java代码

1.package com.testJni.testDemo;

2.

3.public class Demo {

4. static

5. {

6. //System.out.println(System.getProperty("java.library.path"));

7. System.loadLibrary("testDll");

8. System.loadLibrary("jniDll");

9. }

10. public native static int add(int a,int b);

11. public static void main(String[] args) {

12. System.out.println(add(7,2));

13. }

14.}

package com.testJni.testDemo;

public class Demo {

static

{

//System.out.println(System.getProperty("java.library.path"));

System.loadLibrary("testDll");

System.loadLibrary("jniDll");

}

public native static int add(int a,int b);

public static void main(String[] args) {

System.out.println(add(7,2));

}

}

四 最后补充

如果系统已经加载过c/cpp的dll,我们就不用再System.loadLibrary("testDll")了,加载一遍就可以了,因为我们刚才写的testDll系统没有加载,所以我就加载了一下。对于多个dll可以写多个System.loadLibrary去加载,修改static{}里面的内容不需要重新生成dll,除非你多加了一个调用方法,如果你看清楚规则,就不用javah命令就可以直接编写头文件,用javah太麻烦了。

java调用mtcnn的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于JAVA调用dll、java调用mtcnn的信息别忘了在本站进行查找喔。