Skip to content

Commit

Permalink
Add README.md in screen capture driver
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jan 17, 2018
1 parent cc6087c commit d18bfa9
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 22 deletions.
107 changes: 107 additions & 0 deletions webcam-capture-drivers/driver-screencapture/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# webcam-capture-driver-screencapture

This is capture driver which is able to capture video feed from your screen devices. It uses AWT Robot under
the hood and it's is directly limited by its performance. Every screen device connected to your computer will
be abstracted as a separate webcam device.

## Maven

Stable:

```xml
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-driver-screencapture</artifactId>
<version>0.3.12</version>
</dependency>
```

Snapshot:

```xml
<repository>
<id>Sonatype OSS Snapshot Repository</id>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
```
```xml
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture-driver-screencapture</artifactId>
<version>0.3.13-SNAPSHOT</version>
</dependency>
```

## How To Use

Set capture driver before you start using Webcam class:

```java
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JFrame;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamPanel.DrawMode;
import com.github.sarxos.webcam.WebcamResolution;
import com.github.sarxos.webcam.ds.gstreamer.ScreenCaptureDriver;


public class WebcamPanelExample {

static {
Webcam.setDriver(new ScreenCaptureDriver());
}

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

final JFrame window = new JFrame("Screen Capture Example");
window.setResizable(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setLayout(new FlowLayout());

final Dimension resolution = WebcamResolution.QVGA.getSize();

for (final Webcam webcam : Webcam.getWebcams()) {

webcam.setCustomViewSizes(resolution);
webcam.setViewSize(resolution);
webcam.open();

final WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setDrawMode(DrawMode.FIT);
panel.setImageSizeDisplayed(true);
panel.setPreferredSize(resolution);

window.getContentPane().add(panel);
}

window.pack();
window.setVisible(true);
}
}
```

## Examples

Please check [this](https://github.com/sarxos/webcam-capture/tree/master/webcam-capture-drivers/driver-screencapture/src/example/java) directory for more examples.

## Known Problems

1. I noticed this on my Ubuntu Linux - black regions appears in place where other application (e.g. Cairo Dock)
render OpenGL content. I don't know about any workaround or solution for this problem. Not verified on Mac and Windows.
Please report [new issue](https://github.com/sarxos/webcam-capture/issues/new) if you know how to fix this.

## Capture Driver License

Copyright (C) 2012 - 2018 Bartosz Firyn <https://github.com/sarxos> and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamPanel;
import com.github.sarxos.webcam.WebcamPanel.DrawMode;
import com.github.sarxos.webcam.WebcamResolution;
import com.github.sarxos.webcam.ds.gstreamer.ScreenCaptureDriver;


Expand All @@ -15,20 +16,26 @@ public class WebcamPanelExample {
Webcam.setDriver(new ScreenCaptureDriver());
}

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

final JFrame window = new JFrame("Screen Capture Example");
window.setResizable(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.getContentPane().setLayout(new FlowLayout());

for (Webcam webcam : Webcam.getWebcams()) {
final Dimension resolution = WebcamResolution.QVGA.getSize();

WebcamPanel panel = new WebcamPanel(webcam);
for (final Webcam webcam : Webcam.getWebcams()) {

webcam.setCustomViewSizes(resolution);
webcam.setViewSize(resolution);
webcam.open();

final WebcamPanel panel = new WebcamPanel(webcam);
panel.setFPSDisplayed(true);
panel.setDrawMode(DrawMode.FIT);
panel.setImageSizeDisplayed(true);
panel.setPreferredSize(new Dimension(300, 200));
panel.setPreferredSize(resolution);

window.getContentPane().add(panel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,29 @@ public class WebcamPanelSubViewExample {
Webcam.setDriver(new WebcamCompositeDriver(new WebcamDefaultDriver(), new ScreenCaptureDriver()));
}

private final Dimension size = WebcamResolution.QQVGA.getSize();
private final Webcam webcam = Webcam.getWebcams().get(0);
private final Webcam screen = Webcam.getWebcams().get(1);
private final WebcamPanel panel = new WebcamPanel(screen);
private final Dimension webcamSize = WebcamResolution.QVGA.getSize();
private final Dimension screenSize = WebcamResolution.QHD.getSize();
private final WebcamPanel panel = new WebcamPanel(screen, false);
private final Painter dp = panel.getDefaultPainter();
private final JFrame window = new JFrame("Test");

private final class SubViewPainter implements Painter {

private final Webcam webcam = Webcam.getDefault();
private final int x = 619;
private final int y = 437;
private final int w = size.width;
private final int h = size.height;

public SubViewPainter() {
webcam.setViewSize(size);
webcam.open();
}
private final int x = screenSize.width - webcamSize.width - 5;
private final int y = screenSize.height - webcamSize.height - 21;
private final int w = webcamSize.width;
private final int h = webcamSize.height;

@Override
public void paintImage(WebcamPanel owner, BufferedImage image, Graphics2D g2) {

dp.paintImage(owner, image, g2);

g2.setColor(Color.BLACK);
g2.drawRect(x - 1, y - 1, w + 1, h + 1);
g2.drawImage(webcam.getImage(), x, y, w, h, null);
g2.drawImage(webcam.getImage(), x, y, null);
}

@Override
Expand All @@ -56,21 +54,29 @@ public void paintPanel(WebcamPanel panel, Graphics2D g2) {

public WebcamPanelSubViewExample() {

screen.setCustomViewSizes(screenSize);
screen.setViewSize(screenSize);
screen.open(true);

panel.setFPSLimit(30);
panel.setFPSDisplayed(true);
panel.setDrawMode(DrawMode.FIT);
panel.setDrawMode(DrawMode.NONE);
panel.setImageSizeDisplayed(true);
panel.setFPSDisplayed(true);
panel.setPainter(new SubViewPainter());
panel.setPreferredSize(new Dimension(800, 600));
panel.setPreferredSize(screenSize);

webcam.setViewSize(webcamSize);
webcam.open(true);

window.setResizable(true);
window.setPreferredSize(screenSize);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setLayout(null);
window.setContentPane(panel);
window.pack();
window.setVisible(true);

panel.start();
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public BufferedImage getImage() {
final int height = resolution.height;

if (screen.getWidth() == width && screen.getHeight() == height) {
return screen; // No need for adaption
return screen; // No need for adaptation
}

final BufferedImage img = new BufferedImage(width, height, screen.getType());
Expand Down

0 comments on commit d18bfa9

Please sign in to comment.