Skip to content

Commit

Permalink
Upgrade JavaCV from 0.8 to 1.0, fixes #363
Browse files Browse the repository at this point in the history
  • Loading branch information
sarxos committed Jul 13, 2015
1 parent 1a8501f commit d50521d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion webcam-capture-drivers/driver-javacv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>0.8</version>
<version>1.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit d50521d

Please sign in to comment.