/*
有问题可以在www.duyan.top留言。
*/
package UnitTest;
import com.sun.jna.Library;
import com.sun.jna.Native;
import java.io.File;
public class cnnLoadTest {
public static void main(String[] args){
//return version and model,check is 32bit or 64bit,only 32bit by supported.
String version = System.getProperty("java.version") +" "+ System.getProperty("sun.arch.data.model");
System.out.println(version);
cnn.INSTANCE.LoadCnnFromFile(getPath() + "\\discriminate\\cnn\\Caffe.model");
String code = cnn.INSTANCE.GetImageFromFile(getPath()+"\\test.jpg");
System.out.println("result of identification: "+code);
}
//cnn dll called, use jna (and also can use JNative).
private interface cnn extends Library {
cnn INSTANCE = (cnn) Native.loadLibrary(getPath() + "\\discriminate\\cnn\\cnn.dll", cnn.class);//载入dll
boolean LoadCnnFromFile(String FilePath); //载入字库
String GetImageFromFile(String imgPath); //识别图片
}
//get current project path.
private static String getPath() {
try {
File directory = new File("");//参数为空?
String courseFile = directory.getCanonicalPath();
//System.out.println("getPath: "+courseFile);
return courseFile;
} catch (Exception exp) {
exp.printStackTrace();
}
return null;
}
}
评论5
最新资源