Skip to content

Instantly share code, notes, and snippets.

@d-yoshi
Last active September 18, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-yoshi/8a79b16eb02ba6ed70bfaeafc0c9fcc5 to your computer and use it in GitHub Desktop.
Save d-yoshi/8a79b16eb02ba6ed70bfaeafc0c9fcc5 to your computer and use it in GitHub Desktop.
JavaCVでカメラから動画像を取得する
import javafx.concurrent.Service;
import javafx.concurrent.Task;
import org.bytedeco.javacpp.opencv_core.*;
import org.bytedeco.javacpp.opencv_videoio.*;
import static org.bytedeco.javacpp.opencv_videoio.CV_CAP_PROP_FRAME_HEIGHT;
import static org.bytedeco.javacpp.opencv_videoio.CV_CAP_PROP_FRAME_WIDTH;
public class VideoCaptureServiceSample extends Service<Mat> {
private final VideoCapture videoCapture;
public VideoCaptureServiceSample(int cameraIndex, int width, int height) {
this.videoCapture = new VideoCapture(cameraIndex);
videoCapture.set(CV_CAP_PROP_FRAME_WIDTH, width);
videoCapture.set(CV_CAP_PROP_FRAME_HEIGHT, height);
}
public void releaseVideoCapture() {
this.videoCapture.release();
}
@Override
protected Task<Mat> createTask() {
return new Task<Mat>() {
@Override
protected Mat call() throws Exception {
return capture();
}
};
}
private Mat capture() {
Mat capturedImage = new Mat();
this.videoCapture.read(capturedImage);
return capturedImage;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment