Skip to content

Commit

Permalink
Webcam Capture Handbook continuation, refs #102
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jul 10, 2013
1 parent 26165f2 commit 2cd6daa
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 18 deletions.
Expand Up @@ -54,7 +54,7 @@ public static void main(String[] args) throws MalformedURLException {
WebcamPanel panel = new WebcamPanel(webcam, new Dimension(256, 144), false);
panel.setFillArea(true);
panel.setFPSLimited(true);
panel.setFPS(0.2); // 0.2 FPS = 1 frame per 5 seconds
panel.setFPSLimit(0.2); // 0.2 FPS = 1 frame per 5 seconds
panel.setBorder(BorderFactory.createEmptyBorder());

f.add(panel);
Expand Down
Expand Up @@ -31,7 +31,7 @@ public static void main(String[] args) throws MalformedURLException {
IpCamDeviceRegistry.register("Lignano", "http://88.37.116.138/mjpg/video.mjpg", IpCamMode.PUSH);

WebcamPanel panel = new WebcamPanel(Webcam.getWebcams().get(0));
panel.setFPS(1);
panel.setFPSLimit(1);

JFrame f = new JFrame("Live Views From Lignano Beach");
f.add(panel);
Expand Down
Expand Up @@ -53,7 +53,7 @@ public FacePainterExample() throws IOException {
panel.setPainter(this);
panel.setFPSDisplayed(true);
panel.setFPSLimited(true);
panel.setFPS(20);
panel.setFPSLimit(20);
panel.setPainter(this);
panel.start();

Expand Down
Binary file added webcam-capture/src/etc/resources/faces.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified webcam-capture/src/etc/resources/webcam-capture-handbook.doc
Binary file not shown.
10 changes: 4 additions & 6 deletions webcam-capture/src/example/java/WebcamPanelExample.java
Expand Up @@ -8,18 +8,16 @@ public class WebcamPanelExample {

public static void main(String[] args) throws InterruptedException {

JFrame window = new JFrame("Test webcam panel");

Webcam webcam = Webcam.getDefault();

WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true); // display FPS on screen
panel.setFPSLimited(false); // no FPS limit
panel.setFillArea(true); // image will be resized with window
panel.setFPSDisplayed(true);

JFrame window = new JFrame("Test webcam panel");
window.add(panel);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
23 changes: 23 additions & 0 deletions webcam-capture/src/example/java/WebcamPanelFillAreaExample.java
@@ -0,0 +1,23 @@
import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;


public class WebcamPanelFillAreaExample {

public static void main(String[] args) throws InterruptedException {

Webcam webcam = Webcam.getDefault();

WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setFillArea(true);

JFrame window = new JFrame("Test webcam panel");
window.add(panel);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
}
}
Expand Up @@ -372,13 +372,15 @@ private void update() {
*/
private AtomicBoolean started = new AtomicBoolean(false);

private Painter defaultPainter = new DefaultPainter();

/**
* Painter used to draw image in panel.
*
* @see #setPainter(Painter)
* @see #getPainter()
*/
private Painter painter = new DefaultPainter();
private Painter painter = defaultPainter;

/**
* Preferred panel size.
Expand Down Expand Up @@ -612,24 +614,24 @@ public void setFPSLimited(boolean frequencyLimit) {
*
* @return Rendering frequency
*/
public double getFPS() {
public double getFPSLimit() {
return frequency;
}

/**
* Set rendering frequency (in Hz or FPS). Minimum frequency is 0.016 (1
* frame per minute) and maximum is 25 (25 frames per second).
*
* @param frequency the frequency
* @param fps the frequency
*/
public void setFPS(double frequency) {
if (frequency > MAX_FREQUENCY) {
frequency = MAX_FREQUENCY;
public void setFPSLimit(double fps) {
if (fps > MAX_FREQUENCY) {
fps = MAX_FREQUENCY;
}
if (frequency < MIN_FREQUENCY) {
frequency = MIN_FREQUENCY;
if (fps < MIN_FREQUENCY) {
fps = MIN_FREQUENCY;
}
this.frequency = frequency;
this.frequency = fps;
}

public boolean isFPSDisplayed() {
Expand Down Expand Up @@ -686,4 +688,8 @@ public void propertyChange(PropertyChangeEvent evt) {
rb = WebcamUtils.loadRB(WebcamPanel.class, lc);
}
}

public Painter getDefaultPainter() {
return defaultPainter;
}
}

0 comments on commit 2cd6daa

Please sign in to comment.