diff --git a/webcam-capture-drivers/driver-javacv/pom.xml b/webcam-capture-drivers/driver-javacv/pom.xml index f1c0962a..92f81943 100644 --- a/webcam-capture-drivers/driver-javacv/pom.xml +++ b/webcam-capture-drivers/driver-javacv/pom.xml @@ -23,7 +23,7 @@ org.bytedeco javacv - 0.8 + 1.0 diff --git a/webcam-capture-drivers/driver-javacv/src/example/java/JavaCvDriverExample.java b/webcam-capture-drivers/driver-javacv/src/example/java/JavaCvDriverExample.java index d1779c1a..bba34cc9 100644 --- a/webcam-capture-drivers/driver-javacv/src/example/java/JavaCvDriverExample.java +++ b/webcam-capture-drivers/driver-javacv/src/example/java/JavaCvDriverExample.java @@ -13,7 +13,13 @@ public class JavaCvDriverExample { public static void main(String[] args) { JFrame frame = new JFrame("JavaCV Webcam Capture Driver Example"); - frame.add(new WebcamPanel(Webcam.getDefault())); + + WebcamPanel panel = new WebcamPanel(Webcam.getDefault()); + panel.setFPSDisplayed(true); + panel.setFitArea(true); + panel.setImageSizeDisplayed(true); + + frame.add(panel); frame.pack(); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); diff --git a/webcam-capture-drivers/driver-javacv/src/main/java/com/github/sarxos/webcam/ds/javacv/JavaCvDevice.java b/webcam-capture-drivers/driver-javacv/src/main/java/com/github/sarxos/webcam/ds/javacv/JavaCvDevice.java index 2d4e94b9..6d62c0ce 100644 --- a/webcam-capture-drivers/driver-javacv/src/main/java/com/github/sarxos/webcam/ds/javacv/JavaCvDevice.java +++ b/webcam-capture-drivers/driver-javacv/src/main/java/com/github/sarxos/webcam/ds/javacv/JavaCvDevice.java @@ -5,7 +5,9 @@ import java.io.File; import org.bytedeco.javacpp.videoInputLib.videoInput; +import org.bytedeco.javacv.Frame; import org.bytedeco.javacv.FrameGrabber; +import org.bytedeco.javacv.Java2DFrameConverter; import com.github.sarxos.webcam.WebcamDevice; import com.github.sarxos.webcam.WebcamException; @@ -78,11 +80,18 @@ public BufferedImage getImage() { throw new WebcamException("Cannot grab image - webcam device is not open"); } + Frame frame = null; try { - return grabber.grab().getBufferedImage(); + frame = grabber.grab(); } catch (Exception e) { - throw new WebcamException("Cannot grab image..."); + throw new WebcamException("OpenCV cannot grab image frame"); } + if (frame == null) { + throw new WebcamException("OpenCV image frame is null"); + } + + return new Java2DFrameConverter().getBufferedImage(frame); + } private FrameGrabber buildGrabber() throws FrameGrabber.Exception {