protected void layout1024v2() { // Resolution of the camera pictures divided by 2 // 320x240, Creative camera for layout1280 size_x = 320; size_y = 240; sizeCaptureWindow_x = size_x; sizeCaptureWindow_y = size_y; imagepanels = new WebcamCaptureAndFadeImagePanel[1]; imagepanels[0] = new WebcamCaptureAndFadeImagePanel(1, 1, size_x, size_y); setLayout(new BorderLayout()); setSize((4 + 2 + 4) * size_x, (6) * size_y); add(imagepanels[0], BorderLayout.WEST); if ((comp = player.getVisualComponent()) != null) { add(comp, BorderLayout.EAST); } enable_datetext = false; enable_forceNewImage = true; enable_forceNewImageNow = true; captureWindow = false; txt_location_x = txt_location_y = 0; txt_size_x = 18; txt_size_y = size_y; number_of_frames_betweencaptures = 0 * fps; // Number of frame to wait between captures number_of_frames_before_cwopen = 0 * fps; // Number of frames to wait before we allow capturewindow to be opened number_of_frames_showimage = 600 * fps; // Number of frames to hold the image before fading to next number_of_frames_redborder = (int) 0.5 * fps; // Number of frames the red border should last, -1 to disable number_of_second_showcapturetext = 0.1; // Number of seconds to show a text after capture, 0 for none fade_per_frame = 0.50f; // Short fading }
protected void layout1280() { // Resolution of the camera pictures divided by 2 // 320x240, Creative camera for layout1280 size_x = 320 / 2; size_y = 240 / 2; sizeCaptureWindow_x = size_x * 2; sizeCaptureWindow_y = size_y * 2; imagepanels = new WebcamCaptureAndFadeImagePanel[4]; imagepanels[0] = new WebcamCaptureAndFadeImagePanel(3, 8, size_x, size_y); imagepanels[1] = new WebcamCaptureAndFadeImagePanel(2, 3, size_x, size_y); imagepanels[2] = new WebcamCaptureAndFadeImagePanel(2, 3, size_x, size_y); imagepanels[3] = new WebcamCaptureAndFadeImagePanel(3, 8, size_x, size_y); setLayout(new BorderLayout()); setSize((4 + 2 + 4) * size_x, (6) * size_y); add(imagepanels[0], BorderLayout.WEST); JPanel middle = new JPanel(new BorderLayout()); middle.add(imagepanels[1], BorderLayout.NORTH); if ((comp = player.getVisualComponent()) != null) { middle.add(comp, BorderLayout.CENTER); } middle.add(imagepanels[2], BorderLayout.SOUTH); middle.setSize(new Dimension(4 * size_x, 2 * size_y)); add(middle, BorderLayout.CENTER); add(imagepanels[3], BorderLayout.EAST); enable_datetext = false; enable_forceNewImage = false; captureWindow = false; txt_location_x = txt_location_y = 0; txt_size_x = 18; txt_size_y = size_y; }
public WebcamCaptureAndFadePanel(String saveDir, String layout) { System.out.println("Using " + saveDir + " as directory for the images."); saveDirectory = saveDir; getImages(); images_used = new ArrayList<Integer>(); images_lastadded = new ArrayList<Integer>(); images_nevershown = new ArrayList<Integer>(); Vector devices = (Vector) CaptureDeviceManager.getDeviceList(null).clone(); Enumeration enumeration = devices.elements(); System.out.println("- Available cameras -"); ArrayList<String> names = new ArrayList<String>(); while (enumeration.hasMoreElements()) { CaptureDeviceInfo cdi = (CaptureDeviceInfo) enumeration.nextElement(); String name = cdi.getName(); if (name.startsWith("vfw:")) { names.add(name); System.out.println(name); } } // String str1 = "vfw:Logitech USB Video Camera:0"; // String str2 = "vfw:Microsoft WDM Image Capture (Win32):0"; if (names.size() == 0) { JOptionPane.showMessageDialog( null, "Ingen kamera funnet. " + "Du må koble til et kamera for å kjøre programmet.", "Feil", JOptionPane.ERROR_MESSAGE); System.exit(0); } else if (names.size() > 1) { JOptionPane.showMessageDialog( null, "Fant mer enn 1 kamera. " + "Velger da:\n" + names.get(0), "Advarsel", JOptionPane.WARNING_MESSAGE); } String str2 = names.get(0); di = CaptureDeviceManager.getDevice(str2); ml = di.getLocator(); try { player = Manager.createRealizedPlayer(ml); formatControl = (FormatControl) player.getControl("javax.media.control.FormatControl"); /* Format[] formats = formatControl.getSupportedFormats(); for (int i=0; i<formats.length; i++) System.out.println(formats[i].toString()); */ player.start(); } catch (javax.media.NoPlayerException e) { JOptionPane.showMessageDialog( null, "Klarer ikke å starte" + " programmet pga. feil med kamera. Sjekk at det er koblet til.", "IOException", JOptionPane.ERROR_MESSAGE); System.exit(0); } catch (Exception e) { e.printStackTrace(); System.exit(0); } /* * Layout * * Add * - comp * - imagepanels */ if (layout.equals("1024v2")) { layout1024v2(); } else if (layout.equals("1280")) { layout1280(); } else { layout1024(); } // Capture Window if (captureWindow) { cw = new JFrame("Capture from webcam"); cw.setAlwaysOnTop(true); cw.setSize(sizeCaptureWindow_x, sizeCaptureWindow_y); cw.addKeyListener(new captureWindowKeyListner()); cw.setUndecorated(true); // Add webcam if ((comp = player.getVisualComponent()) != null) { cw.add(comp); } // Add panel to window and set location of window cw.setLocation(cwLocation_x, cwLocation_y); } // Text window cwText = new rotatedText(""); /* * Timer for update */ Timer thread = new Timer(); thread.schedule(new frameUpdateTask(), 0, (1000 / fps)); }