Last active
September 18, 2016 15:37
-
-
Save d-yoshi/8a79b16eb02ba6ed70bfaeafc0c9fcc5 to your computer and use it in GitHub Desktop.
JavaCVでカメラから動画像を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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