org.bytedeco.javacpp.Loader类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(555)

本文整理了Java中org.bytedeco.javacpp.Loader类的一些代码示例,展示了Loader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Loader类的具体详情如下:
包路径:org.bytedeco.javacpp.Loader
类名称:Loader

Loader介绍

[英]The Loader contains functionality to load native libraries, but also has a bit of everything that does not fit anywhere else. In addition to its library loading features, it also has utility methods to get the platform name, to load properties from Java resources and from Class annotations, to extract file resources to the temporary directory, and to get the offsetof() or sizeof() a native struct, class, or union with its Pointer peer class and a HashMap initialized by the native libraries inside JNI_OnLoad().
[中]加载程序包含加载本机库的功能,但也有一些其他地方不适合的东西。除了库加载功能外,它还具有实用程序方法,用于获取平台名称、从Java资源和类注释加载属性、将文件资源提取到临时目录,以及获取本机结构、类的offsetof()或sizeof(),或与其指针对等类和由JNI_OnLoad()内的本机库初始化的哈希映射进行联合。

代码示例

代码示例来源:origin: bytedeco/javacpp

/** Returns {@code load(getCallerClass(2), loadProperties(), Loader.pathsFirst)}. */
public static String load() {
  return load(getCallerClass(2), loadProperties(), Loader.pathsFirst);
}
/**

代码示例来源:origin: bytedeco/javacpp

if (!isLoadLibraries() || cls == null) {
  return null;
if (!checkPlatform(cls, properties)) {
  throw new UnsatisfiedLinkError("Platform \"" + properties.getProperty("platform") + "\" not supported by " + cls);
cls = getEnclosingClass(cls);
ClassProperties p = loadProperties(cls, properties, true);
  cacheDir = getCacheDir().getCanonicalPath();
} catch (IOException e) {
for (String preload : preloads) {
  try {
    URL[] urls = findLibrary(cls, p, preload, pathsFirst);
    String filename = loadLibrary(urls, preload);
    if (filename != null) {
      preloaded.add(filename);
      createLibraryLink(filename, p, preload);
    URL[] urls = findLibrary(cls, p, library, pathsFirst);
    String filename = loadLibrary(urls, library, preloaded.toArray(new String[preloaded.size()]));
    if (cacheDir != null && filename != null && filename.startsWith(cacheDir)) {
      createLibraryLink(filename, p, library);

代码示例来源:origin: bytedeco/javacpp

/**
 * Extracts a resource using the {@link ClassLoader} of the caller class,
 * and returns the cached {@link File}.
 *
 * @param name the name of the resource passed to {@link Class#getResource(String)}
 * @see #cacheResource(Class, String)
 */
public static File cacheResource(String name) throws IOException {
  Class cls = getCallerClass(2);
  return cacheResource(cls, name);
}
/**

代码示例来源:origin: bytedeco/javacpp

/**
 * Extracts by name a resource using the {@link ClassLoader} of the caller.
 *
 * @param name the name of the resource passed to {@link Class#getResource(String)}
 * @see #extractResource(URL, File, String, String)
 */
public static File extractResource(String name, File directory,
    String prefix, String suffix) throws IOException {
  Class cls = getCallerClass(2);
  return extractResource(cls, name, directory, prefix, suffix);
}
/**

代码示例来源:origin: org.nd4j/nd4j-cuda-10.0

@Name("std::vector<std::vector<int> >") public static class IntVectorVector extends Pointer {
  static { Loader.load(); }

代码示例来源:origin: stackoverflow.com

public void clientCode(Loader loader) {
  try{
   string s = loader.load();
  catch (NotFoundException ex){
   // handle it
  }     
}

代码示例来源:origin: org.bytedeco/javacv

public static void tryLoad() throws Exception {
  if (loadingException != null) {
    throw loadingException;
  } else {
    try {
      Loader.load(org.bytedeco.javacpp.avutil.class);
      Loader.load(org.bytedeco.javacpp.swresample.class);
      Loader.load(org.bytedeco.javacpp.avcodec.class);
      Loader.load(org.bytedeco.javacpp.avformat.class);
      Loader.load(org.bytedeco.javacpp.swscale.class);
      /* initialize libavcodec, and register all codecs and formats */
      av_jni_set_java_vm(Loader.getJavaVM(), null);
      avcodec_register_all();
      av_register_all();
      avformat_network_init();
      Loader.load(org.bytedeco.javacpp.avdevice.class);
      avdevice_register_all();
    } catch (Throwable t) {
      if (t instanceof Exception) {
        throw loadingException = (Exception)t;
      } else {
        throw loadingException = new Exception("Failed to load " + FFmpegFrameRecorder.class, t);
      }
    }
  }
}

代码示例来源:origin: bytedeco/javacpp

/** Returns {@code load(cls, loadProperties(), Loader.pathsFirst)}. */
public static String load(Class cls) {
  return load(cls, loadProperties(), Loader.pathsFirst);
}
/**

代码示例来源:origin: bytedeco/javacpp

boolean match = platform.extension().length == 0 || (Loader.isLoadLibraries() && platformExtension == null);
for (String s : platform.extension()) {
  if (platformExtension != null && platformExtension.length() > 0 && platformExtension.endsWith(s)) {

代码示例来源:origin: bytedeco/javacpp

String[] resources = properties.get("platform.preloadresource").toArray(new String[0]);
String libpath = System.getProperty("java.library.path", "");
if (libpath.length() > 0 && (pathsFirst || !isLoadLibraries() || reference)) {
             + (extension == null ? "" : extension) + "/";
      try {
        URL u = findResource(cls, subdir + styles[i]);
        if (u != null) {
          if (reference) {

代码示例来源:origin: bytedeco/javacpp

if (!isLoadLibraries()) {
  return null;
    } catch (Exception exc) {
      File f = cacheResource(url, filename);
      try {
        if (f != null) {

代码示例来源:origin: bytedeco/javacpp

public void load(Class cls, boolean inherit) {
  Class<?> c = Loader.getEnclosingClass(cls);
  List<Class> classList = new ArrayList<Class>();
  classList.add(0, c);
      boolean match = p.extension().length == 0 || (Loader.isLoadLibraries() && platformExtension == null);
      for (String s : p.extension()) {
        if (platformExtension != null && platformExtension.length() > 0 && platformExtension.endsWith(s)) {

代码示例来源:origin: org.sikuli/sikuli-core

static public List<CvRect> detectBlobs(IplImage input){
  IplImage clone = input.clone();
  CvMemStorage storage = CvMemStorage.create();
  CvSeq contour = new CvSeq(null);
  cvFindContours(clone, storage, contour, Loader.sizeof(CvContour.class),
      CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
  //vlog(crossMask);
  List<CvRect> rects = Lists.newArrayList(); 
  while (contour != null && !contour.isNull()) {
    if (contour.elem_size() > 0) {
      CvRect boundingRect = cvBoundingRect(contour,0);
      rects.add(boundingRect);
    }
    contour = contour.h_next();
  }
  return rects;
}

代码示例来源:origin: bytedeco/javacpp

/**
 * Extracts resources using the {@link ClassLoader} of the caller class,
 * and returns the cached {@link File} objects.
 *
 * @param name of the resources passed to {@link #findResources(Class, String)}
 * @see #cacheResources(Class, String)
 */
public static File[] cacheResources(String name) throws IOException {
  Class cls = getCallerClass(2);
  return cacheResources(cls, name);
}
/**

代码示例来源:origin: bytedeco/javacpp

/**
 * Extracts by name resources using the {@link ClassLoader} of the caller.
 *
 * @param name of the resources passed to {@link #findResources(Class, String)}
 * @see #extractResources(Class, String, File, String, String)
 */
public static File[] extractResources(String name, File directory,
    String prefix, String suffix) throws IOException {
  Class cls = getCallerClass(2);
  return extractResources(cls, name, directory, prefix, suffix);
}
/**

代码示例来源:origin: org.bytedeco/javacv

public CLKernel buildKernel(String resourceNames, String kernelName) {
  return buildKernels(fastCompilerOptions, Loader.getCallerClass(2), resourceNames, kernelName)[0];
}
public CLKernel buildKernel(String compilerOptions, String resourceNames, String kernelName) {

代码示例来源:origin: org.nd4j/nd4j-cuda-10.0

@Name("std::vector<std::vector<Nd4jLong> >") public static class LongVectorVector extends Pointer {
  static { Loader.load(); }

代码示例来源:origin: com.github.hageldave.ezfftw/ezfftw

/**
 * Loads the native fftw3 library.
 * This method has to be called before using any of the bindings to fftw or cpp
 * (i.e. {@link DoublePointer} or {@link fftw_plan} and the like).
 */
public static void initFFTW(){
  if(!setupDone){
    synchronized (FFTW_Initializer.class) {
      if(!setupDone){
        String loadedlib = Loader.load(fftw3.class);
        setupDone = true;
        System.out.format("Loaded FFTW library [%s]%n",loadedlib);
      }
    }
  }
}

代码示例来源:origin: org.bytedeco/javacv

public static void tryLoad() throws Exception {
  if (loadingException != null) {
    throw loadingException;
  } else {
    try {
      Loader.load(org.bytedeco.javacpp.avutil.class);
      Loader.load(org.bytedeco.javacpp.swresample.class);
      Loader.load(org.bytedeco.javacpp.avcodec.class);
      Loader.load(org.bytedeco.javacpp.avformat.class);
      Loader.load(org.bytedeco.javacpp.swscale.class);
      // Register all formats and codecs
      av_jni_set_java_vm(Loader.getJavaVM(), null);
      avcodec_register_all();
      av_register_all();
      avformat_network_init();
      Loader.load(org.bytedeco.javacpp.avdevice.class);
      avdevice_register_all();
    } catch (Throwable t) {
      if (t instanceof Exception) {
        throw loadingException = (Exception)t;
      } else {
        throw loadingException = new Exception("Failed to load " + FFmpegFrameGrabber.class, t);
      }
    }
  }
}

代码示例来源:origin: org.bytedeco.javacpp-presets/tensorrt

@Override public void init(ClassProperties properties) {
  String platform = properties.getProperty("platform");
  List<String> preloads = properties.get("platform.preload");
  // Only apply this at load time since we don't want to copy the CUDA libraries here
  if (!Loader.isLoadLibraries() || !platform.equals("linux-x86_64")) {
    return;
  }
  int i = 0;
  String[] libs = {"cudart", "cublas", "cudnn"};
  for (String lib : libs) {
    lib += lib.equals("cudnn") ? "@.7" : "@.10.0";
    if (!preloads.contains(lib)) {
      preloads.add(i++, lib);
    }
  }
}

相关文章