ClEyeMulticam.dll有时加载有时不加载

时间:2015-04-06 15:39:12

标签: java dll camera processing ps3

我为PS3eye摄像头安装了Cleye驱动程序(驱动程序5.3.0.0341和SDK 1.6.4.0028),我正在尝试在Cl-eye Platform SDK中运行Processing example(java)。问题是处理库,更具体地说ClEyeMulticam.dll没有加载但偶尔(如8次中的1次)加载成功。为什么dll有时会加载,有时不加载?我正在使用处理2.2.1 32位,我已经尝试在处理中指定路径manualy但它不起作用:“CLCamera.loadLibrary(”C:/CLEyeMulticam.dll“);”

Java代码示例:

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This file is part of CL-EyeMulticam SDK
//
// Java Processing CLEyeProcessingTest Sketch
//
// It allows the use of multiple CL-Eye cameras in your own Java Processing applications
//
// For updates and file downloads go to: http://codelaboratories.com/about/product/eye
//
// Copyright 2008-2012 (c) Code Laboratories, Inc. All rights reserved.
//
// Dependancies: CLEyeMulticam.dll - CL-Eye Platform Multicam API
//               CLEyeMulticam.jar - For processing.org move this into your libraries folder
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Imports
import cl.eye.*;

// Camera Variables
int numCams;
CLCamera myCameras[] = new CLCamera[2];
PImage myImages[] = new PImage[2];
int cameraWidth = 640;
int cameraHeight = 480;
int cameraRate = 30;

// Animation Variables (not required)
boolean animate = true; 
float zoomVal, zoomDelta;
float rotateVal, rotateDelta;

void setup(){
  // Library loading via native interface (JNI)
  // If you see "UnsatisfiedLinkError" then target the library path otherwise leave it commented out.
  // CLCamera.loadLibrary("C://PATH//TO//CL-EYE SDK FOLDER//Bin/CLEyeMulticam.dll");

  // Verifies the native library loaded
  if(!setupCameras()) exit();
  // Setups animated variables 
  if(animate) setupAnimation();
}

void draw(){ 
  // Loops through available cameras and updates
  for(int i = 0; i < numCams; i++)
  {
    // ---------------------   (image destination, wait timeout)
    myCameras[i].getCameraFrame(myImages[i].pixels, (i==0) ? 1000 : 0);
    myImages[i].updatePixels();
    image(myImages[i], cameraWidth*i, 0);   
  }
  // Updates the animation
  if(animate)updateAnimation();
}

boolean setupCameras(){
  println("Getting number of cameras");
  // Checks available cameras
  numCams = CLCamera.cameraCount();
  println("Found " + numCams + " cameras");
  if(numCams == 0)  return false;
  // create cameras and start capture
  for(int i = 0; i < numCams; i++)
  {
    // Prints Unique Identifier per camera
    println("Camera " + (i+1) + " UUID " + CLCamera.cameraUUID(i));
    // New camera instance per camera
    myCameras[i] = new CLCamera(this);
    // ----------------------(i, CLEYE_GRAYSCALE/COLOR, CLEYE_QVGA/VGA, Framerate)
    myCameras[i].createCamera(i, CLCamera.CLEYE_COLOR_PROCESSED, CLCamera.CLEYE_VGA, cameraRate);
    // Starts camera captures
    myCameras[i].startCamera();
    myImages[i] = createImage(cameraWidth, cameraHeight, RGB); 
  }
  // resize the output window
  size(cameraWidth*numCams, cameraHeight);
  println("Complete Initializing Cameras");  
  return true;
}

void setupAnimation(){
   // General Animation Variables
   zoomVal = 0;
   zoomDelta = TWO_PI/75.0;
   rotateVal = 0;
   rotateDelta = TWO_PI/125.0;
}

void updateAnimation(){
   myCameras[0].setCameraParam(CLCamera.CLEYE_HKEYSTONE, (int)(150 * sin(rotateVal))); 
   myCameras[0].setCameraParam(CLCamera.CLEYE_VKEYSTONE, (int)(200 * cos(rotateVal)));
   //myCameras[0].setCameraParam(Multicam.CLEYE_LENSCORRECTION1, (int)(75 * sin(rotateVal)));
   if(numCams>1)
   {
     myCameras[1].setCameraParam(CLCamera.CLEYE_ZOOM, (int)(200 * sin(zoomVal)));
   }
   rotateVal += rotateDelta;
   zoomVal += zoomDelta;
}

处理库的源代码:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// This file is part of CL-EyeMulticam SDK
//
// Java JNI CLEyeMulticam wrapper
//
// It allows the use of multiple CL-Eye cameras in your own Java applications
//
// For updates and file downloads go to: http://codelaboratories.com/research/view/cl-eye-muticamera-sdk
//
// Copyright 2008-2012 (c) Code Laboratories, Inc. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package cl.eye;
import processing.core.*;

public class CLCamera
{
    // camera color mode
    public static int CLEYE_MONO_PROCESSED  = 0;
    public static int CLEYE_COLOR_PROCESSED = 1;
    public static int CLEYE_MONO_RAW            = 2;
    public static int CLEYE_COLOR_RAW           = 3;
    public static int CLEYE_BAYER_RAW           = 4;

    // camera resolution
    public static int CLEYE_QVGA        = 0;
    public static int CLEYE_VGA         = 1;

    // camera sensor parameters
    public static int CLEYE_AUTO_GAIN       = 0;    // [0, 1]
    public static int CLEYE_GAIN        = 1;    // [0, 79]
    public static int CLEYE_AUTO_EXPOSURE   = 2;    // [0, 1]
    public static int CLEYE_EXPOSURE        = 3;    // [0, 511]
    public static int CLEYE_AUTO_WHITEBALANCE   = 4;    // [0, 1]
    public static int CLEYE_WHITEBALANCE_RED    = 5;    // [0, 255]
    public static int CLEYE_WHITEBALANCE_GREEN  = 6;    // [0, 255]
    public static int CLEYE_WHITEBALANCE_BLUE   = 7;    // [0, 255]
    // camera linear transform parameters
    public static int CLEYE_HFLIP       = 8;    // [0, 1]
    public static int CLEYE_VFLIP       = 9;    // [0, 1]
    public static int CLEYE_HKEYSTONE       = 10;   // [-500, 500]
    public static int CLEYE_VKEYSTONE       = 11;   // [-500, 500]
    public static int CLEYE_XOFFSET     = 12;   // [-500, 500]
    public static int CLEYE_YOFFSET     = 13;   // [-500, 500]
    public static int CLEYE_ROTATION        = 14;   // [-500, 500]
    public static int CLEYE_ZOOM        = 15;   // [-500, 500]
    // camera non-linear transform parameters
    public static int CLEYE_LENSCORRECTION1 = 16;   // [-500, 500]
    public static int CLEYE_LENSCORRECTION2 = 17;   // [-500, 500]
    public static int CLEYE_LENSCORRECTION3 = 18;   // [-500, 500]
    public static int CLEYE_LENSBRIGHTNESS  = 19;   // [-500, 500]

    native static int CLEyeGetCameraCount();
    native static String CLEyeGetCameraUUID(int index);
    native static int CLEyeCreateCamera(int cameraIndex, int mode, int resolution, int framerate);
    native static boolean CLEyeDestroyCamera(int cameraIndex);
    native static boolean CLEyeCameraStart(int cameraInstance);
    native static boolean CLEyeCameraStop(int cameraInstance);
    native static boolean CLEyeSetCameraParameter(int cameraInstance, int param, int val);
    native static int CLEyeGetCameraParameter(int cameraInstance, int param);
    native static boolean CLEyeCameraGetFrame(int cameraInstance, int[] imgData, int waitTimeout);

    private int cameraInstance = 0;
    private PApplet parent;
    private static boolean libraryLoaded = false;
    private static String dllpathx32 = "C://Program Files//Code Laboratories//CL-Eye Platform SDK//Bin//CLEyeMulticam.dll";
    private static String dllpathx64 = "C://Program Files (x86)//Code Laboratories//CL-Eye Platform SDK//Bin//CLEyeMulticam.dll";

    // static methods
    static
    {
        try
        {
            System.load(dllpathx32);
            libraryLoaded = true;
            System.out.println("CLEyeMulticam.dll loaded");
        }
        catch(UnsatisfiedLinkError e1)
        {
            System.out.println("(1) Could not find the CLEyeMulticam.dll");
            try
            {
                System.load(dllpathx64);
                libraryLoaded = true;
                System.out.println("CLEyeMulticam.dll loaded");
            }
            catch(UnsatisfiedLinkError e2)
            {
                System.out.println("(2) Could not find the CLEyeMulticam.dll");
            }
        }
    }
    public static boolean IsLibraryLoaded()
    {
        return libraryLoaded;
    }
    public static void loadLibrary(String libraryPath)
    {
        if(libraryLoaded)   return;
        try
        {
            System.load(libraryPath);
            System.out.println("CLEyeMulticam.dll loaded");
        }
        catch(UnsatisfiedLinkError e1)
        {
            System.out.println("(3) Could not find the CLEyeMulticam.dll (Custom Path)");
        }
    }
    public static int cameraCount()
    {
        return CLEyeGetCameraCount();
    }
    public static String cameraUUID(int index)
    {
        return CLEyeGetCameraUUID(index);
    }
    // public methods
    public CLCamera(PApplet parent)
    {
        this.parent = parent;
        parent.registerDispose(this);
    }
    public void dispose()
    {
        stopCamera();
        destroyCamera();
    }
    public boolean createCamera(int cameraIndex, int mode, int resolution, int framerate)
    {
        cameraInstance = CLEyeCreateCamera(cameraIndex, mode, resolution, framerate);
        return cameraInstance != 0;
    }
    public boolean destroyCamera()
    {
        return CLEyeDestroyCamera(cameraInstance);
    }
    public boolean startCamera()
    {
        return CLEyeCameraStart(cameraInstance);
    }
    public boolean stopCamera()
    {
        return CLEyeCameraStop(cameraInstance);
    }
    public boolean getCameraFrame(int[] imgData, int waitTimeout)
    {
        return CLEyeCameraGetFrame(cameraInstance, imgData, waitTimeout);
    }
    public boolean setCameraParam(int param, int val)
    {
        return CLEyeSetCameraParameter(cameraInstance, param, val);
    }
    public int getCameraParam(int param)
    {
        return CLEyeGetCameraParameter(cameraInstance, param);
    }
}

0 个答案:

没有答案