本文整理汇总了Java中org.opencv.videoio.VideoCapture.open方法的典型用法代码示例。如果您正苦于以下问题:Java VideoCapture.open方法的具体用法?Java VideoCapture.open怎么用?Java VideoCapture.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.opencv.videoio.VideoCapture
的用法示例。
在下文中一共展示了VideoCapture.open方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startDetecting
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
public void startDetecting() {
capture = new VideoCapture();
capture.open(0);
Runnable frameGrabber = new Runnable() {
@Override
public void run() {
// effectively grab and process a single frame
grabFrame();
// convert and show the frame
//TODO trigger listener up here
}
};
this.timer = Executors.newSingleThreadScheduledExecutor();
this.timer.scheduleAtFixedRate(frameGrabber, 0, 20, TimeUnit.MILLISECONDS);
}
示例2: init
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
@Override
protected void init(final ProcessorInitializationContext context) {
final List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
// descriptors.add(CAMERA);
descriptors.add(FRAME_WIDTH);
descriptors.add(FRAME_HEIGHT);
this.descriptors = Collections.unmodifiableList(descriptors);
final Set<Relationship> relationships = new HashSet<Relationship>();
relationships.add(REL_SUCCESS);
this.relationships = Collections.unmodifiableSet(relationships);
OpenCV.loadShared();
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
camera = new VideoCapture();
camera.open(0);
}
示例3: USBCamera
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
/**
* Constructs a new <code>USBCamera</code>
* @param number the port number for the camera
* @param fov the field of view of the camera in degrees
*/
public USBCamera(int number, double fov) {
super(fov);
this.number = number;
vc = new VideoCapture();
vc.open(this.number);
}
示例4: main
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
public static void main(String[] args)
{
System.out.println("Hello, OpenCV");
// Load the native library.
System.loadLibrary("opencv_java244");
VideoCapture camera = new VideoCapture(0);
camera.open(0); //Useless
if(!camera.isOpened()){
System.out.println("Camera Error");
}
else{
System.out.println("Camera OK?");
}
Mat frame = new Mat();
//camera.grab();
//System.out.println("Frame Grabbed");
//camera.retrieve(frame);
//System.out.println("Frame Decoded");
camera.read(frame);
System.out.println("Frame Obtained");
/* No difference
camera.release();
*/
System.out.println("Captured Frame Width " + frame.width());
Imgcodecs.imwrite("camera.jpg", frame);
System.out.println("OK");
}
示例5: CvMultiCamera
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
/**
* Opens a new camera using openCV with a given frame width and height,
* and a compression quality.
* <p>
* Checks all available devices up to index 10 and adds them using
* {@link CameraView#add(Camera)}.
* </p>
*
* @param name the name of the camera
* @param current the device index from 0.
* @param width the frame width
* @param height the frame height
* @param quality the compression quality
*
* @throws RuntimeException if the camera could not be opened
*/
public CvMultiCamera(String name, int current, int width, int height, int quality) {
super(name, null);
capture = new VideoCapture();
cams = checkCameras(capture, 10);
if(current >= 0){
capture.open(current);
camIndex = current;
}
image = new Mat();
buffer = new MatOfByte();
compressParams = new MatOfInt(Imgcodecs.CV_IMWRITE_JPEG_QUALITY, quality);
capture.set(Videoio.CAP_PROP_FRAME_WIDTH, width);
capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, height);
this.height = height;
this.width = width;
this.quality = quality;
Camera nullcam = null;
for (int i = 0; i < cams.length; i++) {
if(cams[i] >= 0){
add(nullcam);
}
}
}
示例6: checkCameras
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
private static int[] checkCameras(VideoCapture cap, int max){
int[] cams = new int[max];
boolean end = false;
for (int i = 0; i < max; i++) {
if(!end){
if(!cap.open(i)){
cams[i] = -1;
end = true;
}else cams[i] = i;
cap.release();
}else cams[i] = -1;
}
return cams;
}
示例7: CvCamera
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
/**
* Opens a new camera using openCV at a certain device index with
* a given frame width and height, and a compression quality.
*
* @param cam the device index from 0.
* @param width the frame width
* @param height the frame height
* @param quality the compression quality
*
* @throws RuntimeException if the camera could not be opened
*/
public CvCamera(int cam, int width, int height, int quality){
capture = new VideoCapture();
capture.open(cam);
if(!capture.isOpened())
throw new RuntimeException("Unable to open camera " + cam);
image = new Mat();
buffer = new MatOfByte();
compressParams = new MatOfInt(Imgcodecs.CV_IMWRITE_JPEG_QUALITY, quality);
capture.set(Videoio.CAP_PROP_FRAME_WIDTH, width);
capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, height);
camIndex = cam;
this.quality = quality;
}
示例8: startCamera
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
private void startCamera() {
currentFrame = new Mat();
modifiedFrame = new Mat();
matOfByte = new MatOfByte();
videoCapture = new VideoCapture();
videoCapture.open(0);
startFrameGrabbing();
}
示例9: VideoCap
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
VideoCap(){
cap = new VideoCapture();
cap.open(0);
}
示例10: calibration
import org.opencv.videoio.VideoCapture; //导入方法依赖的package包/类
public void calibration(VideoCapture capture, EyeDetection e) {
initializeEvetything();
/*
System.out.println("Calibration time!");
System.out.println("Open both your eyes for 2 seconds");
*/
pressAnyKeyToContinue("Calibration time!\nOpen both your eyes for 2 seconds");
boolean first_capture;
first_capture = true;
//capture.open(0); not sure may need
/*
if(capture.isOpened()) {
capture.set(io.CV_CAP_PROP_FRAME_WIDTH, width);
capture.set(io.CV_CAP_PROP_FRAME_HEIGHT, height);
}
*/
while(openEyesList.size() < 2) {
if(!first_capture) {
//System.out.println("Can you please repeat?");
pressAnyKeyToContinue("Can you please repeat?");
} else {
first_capture = false;
}
if(capture.read(openEyesMat)) {
openEyesList = e.eyeDetect(openEyesMat);
}
}
e.filter(openEyesList);
//System.out.println();
pressAnyKeyToContinue("Nice, Now close your eyes for 2 seconds");
capture.release();
capture.open(0);
first_capture = true;
while(closedEyesList.size() < 2) {
if(!capture.isOpened())
capture.open(0);
if(first_capture) {
first_capture = false;
} else {
//System.out.println("Can you please repeat?");
pressAnyKeyToContinue("Can you please repeat?");
}
if(capture.read(closedEyesMat)) {
closedEyesList = e.eyeDetect(closedEyesMat);
}
}
e.filter(closedEyesList);
System.out.println();
capture.release();
}