public static void main(String[] args) { UEyeCameraInfo[] uEyeCameraInfoArray = {new UEyeCameraInfo(), new UEyeCameraInfo()}; UEyeCameraList uEyeCameraList = new UEyeCameraList(uEyeCameraInfoArray); // write struct to native memory uEyeCameraList.write(); int result = UEyeCapturerLibrary.GetCameraNames(uEyeCameraList.getPointer()); System.out.println("GetCameraNames result: " + result); uEyeCameraList.read(); final IntByReference cameraHandle = new IntByReference(0); char[] windowName = null; for (int i = 0; i < uEyeCameraList.dwCount; i++) { UEyeCameraInfo ueye_CAMERA_INFO = uEyeCameraList.uci[i]; windowName = Native.toCharArray(ueye_CAMERA_INFO.getModelInfo()); System.out.println("WindowName returned: " + windowName); cameraHandle.setValue(ueye_CAMERA_INFO.dwCameraID); } uEyeCameraList.clear(); String settingsFile = "C:/Documents and Settings/Administrator/My Documents/uEye/1495LE3.90.ini"; result = UEyeCapturerLibrary.InitializeCamera(cameraHandle); System.out.println("initCamera result: " + result); System.out.println("Camera handle returned: " + cameraHandle.getValue()); IntByReference monitorId = new IntByReference(WindowManager.getDefaultMonitorId()); UEyeCapturerLibrary.OnWndShowCallback onWndShowCallback = new UEyeCapturerLibrary.OnWndShowCallback() { public void invoke(boolean visible) { System.out.println("Window visibility set to " + visible); } }; Frame frame = new Frame(String.valueOf(windowName)); Canvas canvas = new Canvas(); frame.add(canvas); frame.setIgnoreRepaint(true); frame.setBackground(Color.black); frame.setSize(1440, 900); frame.setVisible(true); frame.pack(); Pointer newPointer = Native.getComponentPointer(canvas); result = UEyeCapturerLibrary.StartRunning( cameraHandle, settingsFile, monitorId, onWndShowCallback, newPointer); try { Thread.sleep(5000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } result = UEyeCapturerLibrary.StopRunning(cameraHandle); frame.remove(canvas); frame.validate(); try { Thread.sleep(2000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } frame.add(canvas); frame.validate(); Pointer otherPointer = Native.getComponentPointer(canvas); assert (otherPointer.equals(newPointer)); result = UEyeCapturerLibrary.StartRunning( cameraHandle, settingsFile, monitorId, onWndShowCallback, otherPointer); try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(UEyeCapturerLibrary.Dispose(cameraHandle)); }
public void testGetCameras() { UEyeCameraList.ByValue uEyeCameraList = new UEyeCameraList.ByValue(); // write struct to native memory uEyeCameraList.write(); int result = UEyeCapturerLibrary.GetCameraNames(uEyeCameraList.getPointer()); System.out.println("GetCameraNames result: " + result); uEyeCameraList.read(); final IntByReference cameraHandle = new IntByReference(0); String windowName = null; for (int i = 0; i < uEyeCameraList.dwCount; i++) { UEyeCameraInfo ueye_CAMERA_INFO = uEyeCameraList.uci[i]; windowName = ueye_CAMERA_INFO.getModelInfo(); System.out.println("WindowName returned: " + windowName); cameraHandle.setValue(ueye_CAMERA_INFO.dwCameraID); } uEyeCameraList.clear(); // open camera /* String settingsFile = "C:/Documents and Settings/Administrator/My Documents/uEye/1495LE2.ini"; result = UEyeCapturerLibrary.InitializeCamera(cameraHandle); System.out.println("initCamera result: " + result); System.out.println("Camera handle returned: " + cameraHandle.getValue()); IntByReference monitorId = new IntByReference(WindowManager.getDefaultMonitorId()); UEyeCapturerLibrary.OnWndShowCallback onWndShowCallback = new UEyeCapturerLibrary.OnWndShowCallback() { public void invoke(boolean visible) { System.out.println("Window visibility set to " + visible); } }; result = UEyeCapturerLibrary.StartRunning(cameraHandle, settingsFile, monitorId, onWndShowCallback, Pointer.NULL); int aviResult = UEyeCapturerLibrary.StartRecording(cameraHandle, "C:/test2.avi", 66.8); System.out.println("startRecording result: "+ aviResult); Thread thread = new Thread(new Runnable() { public void run() { while(true) { long[] frameDropInfo = {0L, 0L}; UEyeCapturerLibrary.GetFrameDropInfo(cameraHandle, frameDropInfo); System.out.println("captured: " + (frameDropInfo[0] & 0xFFFFFFF0L) + " dropped: "+ (frameDropInfo[1] & 0xFFFFFFF0L)); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("thread interrupted"); } } } }, "FrameDropInfoThread"); thread.start(); try { // wait for the camera thread to die //cameraThread.join(); Thread.sleep(100000); } catch (InterruptedException e) { e.printStackTrace(); } result = UEyeCapturerLibrary.StopRecording(cameraHandle); System.out.println("stopRecording result: "+ result); UEyeCapturerLibrary.StopRunning(cameraHandle); System.out.println("Camera stopped running");*/ }