当前位置: 首页>>代码示例>>Java>>正文


Java VideoCapture类代码示例

本文整理汇总了Java中org.opencv.videoio.VideoCapture的典型用法代码示例。如果您正苦于以下问题:Java VideoCapture类的具体用法?Java VideoCapture怎么用?Java VideoCapture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


VideoCapture类属于org.opencv.videoio包,在下文中一共展示了VideoCapture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Webcam

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
Webcam() {
    cap = new VideoCapture(0);
    if (!cap.isOpened()) {
        System.out.println("Camera Error");
    } else {
        System.out.println("Camera OK?");
        cap.set(Videoio.CV_CAP_PROP_FRAME_WIDTH, width);
        cap.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT, height);
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
    }
    cap.read(mat);
    System.out.println("width, height = "+mat.cols()+", "+mat.rows());
}
 
开发者ID:TheoreticallyNick,项目名称:Face-Detection-and-Tracking,代码行数:17,代码来源:Webcam.java

示例2: 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);
}
 
开发者ID:kareem2048,项目名称:Asteroids-Laser-Controller,代码行数:18,代码来源:LaserDetector.java

示例3: MainFrame

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public MainFrame()
{
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setPreferredSize(new Dimension(640, 480));

    cap = new VideoCapture(0);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            cap.release();
            System.exit(0);
        }
    });

    p = new DrawPanel();
    add(p);

    setVisible(true);
}
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:22,代码来源:MainFrame.java

示例4: 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);
	
}
 
开发者ID:simonellistonball,项目名称:nifi-OpenCV,代码行数:20,代码来源:GetCameraFrame.java

示例5: patternCapture

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void patternCapture(VideoCapture capture, EyeDetection e, int length, String cmd){
    //Scanner scanner = new Scanner(System.in);
    List<EyeStatus> eyeStatusList = new ArrayList<>();
    Calculation calculation = new Calculation(this);
    Mat frame = new Mat();
    List<Circle> circleList = new ArrayList<>();
    //System.out.println("How big will your pattern be?");
    //length = scanner.nextInt(); //excpetion
    for(int i = 0; i < length; i++) {
        //System.out.println("Do step " + (i + 1));
        pressAnyKeyToContinue("Do step " + (i + 1));
        if(capture.read(frame)) {
            circleList = e.eyeDetect(frame);
            e.filter(circleList);
            //Calculate
            eyeStatusList.add(calculation.calculate(frame, circleList));
        }
    }
    for(EyeStatus eye : eyeStatusList) {
        System.out.println(eye.getLeft() + " " + eye.getRight());
    }
    PatternDatabase.writeNewPattern(eyeStatusList, cmd);
    capture.release();
}
 
开发者ID:Merge-Conflict,项目名称:ICHACK16-ProcrastEnabler,代码行数:25,代码来源:Calibrator.java

示例6: ImageProcessor

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public ImageProcessor(int webcam, VisionNetworkTable visionTable) {
	capture = new VideoCapture(webcam);
	capture.set(Videoio.CAP_PROP_FRAME_WIDTH, 640); // width
	capture.set(Videoio.CAP_PROP_FRAME_HEIGHT, 480); // height
	
	this.visionTable = visionTable;
	this.scheduler = Executors.newScheduledThreadPool(1);
	
	originalImage = new Mat();
	hslImage = new Mat();
	maskImage = new Mat();
	hierarchy = new Mat();
	
	setCameraManualExposure();
	setCameraAbsoluteExposure();
	setCameraBrightness();
	
	System.out.println("ImageProcesser constructor done");
}
 
开发者ID:FRC-1294,项目名称:frc2016vision,代码行数:20,代码来源:ImageProcessor.java

示例7: CamFaceDetector

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public static void CamFaceDetector() {
	try {
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

		final CascadeClassifier objDetector = new CascadeClassifier(CameraFacialRecognition.class
				.getResource("../../../../../opencv/sources/data/lbpcascades/lbpcascade_frontalface_improved.xml")
				.getPath().substring(1));

		final Mat capImg = new Mat();
		final VideoCapture capture = new VideoCapture(0);
		final int height = (int) capture.get(Videoio.CV_CAP_PROP_FRAME_HEIGHT);
		final int width = (int) capture.get(Videoio.CV_CAP_PROP_FRAME_WIDTH);
		if (height == 0 || width == 0) {
			throw new Exception("camera not found");
		}

		final JFrame frame = new JFrame("camera");
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		final CameraFacialRecognition panel = new CameraFacialRecognition();
		frame.setContentPane(panel);
		frame.setVisible(true);
		frame.setSize(width + frame.getInsets().left + frame.getInsets().right,
				height + frame.getInsets().top + frame.getInsets().bottom);

		Mat dst = new Mat();
		while (frame.isShowing()) {
			capture.read(capImg);
			dst = dobj(objDetector, capImg);
			panel.mImg = Mat2BufferedImage.mat2BI(dst);
			panel.repaint();
		}
		capture.release();
	} catch (final Exception e) {
		System.out.println("Exception" + e);
	} finally {
		System.out.println("--done--");
	}
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:39,代码来源:CameraFacialRecognition.java

示例8: 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);
}
 
开发者ID:KHS-Robotics,项目名称:DemonVision,代码行数:14,代码来源:USBCamera.java

示例9: init

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void init() {
    System.out.println("INIT");

    cap = new VideoCapture();
    faceCascade = new CascadeClassifier();

    imageView.setFitWidth(640);
    imageView.setPreserveRatio(true);
    
    faceCascade.load("res/haarcascade_frontalface_alt.xml");
}
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:12,代码来源:Controller.java

示例10: init

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void init() { // external
    System.out.println("[Controller] Initializing controller");
    cap = new VideoCapture();

    // fix imageViews so they don't resize
    imageView.setFitWidth(640);
    imageView.setPreserveRatio(true);
    imageViewAlpha.setFitWidth(320);
    imageViewAlpha.setPreserveRatio(true);
    imageViewBeta.setFitWidth(320);
    imageViewBeta.setPreserveRatio(true);

}
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:14,代码来源:Controller.java

示例11: grabImage

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public void grabImage(){
    Mat frame = new Mat();

    //connect
    videoCapture = new VideoCapture(0);
    isOpened = videoCapture.isOpened();
    System.out.println("connected: " + isOpened);
    //setSetting
    videoCapture.set(Videoio.CV_CAP_PROP_FRAME_WIDTH, 1280);
    videoCapture.set(Videoio.CV_CAP_PROP_FRAME_HEIGHT, 720);
    //startGrab
    isSucceed = videoCapture.grab();
    System.out.println("started: " + String.valueOf(isSucceed));
    if ((!isOpened) || (!isSucceed))
        return;
    System.out.println("------- START GRAB -------");

    //Wait for camera starting
    while (true){
        videoCapture.read(frame);
        if (!frame.empty())
            break;
    }

    int frameNo = 0;
    long startSysMillis = System.currentTimeMillis();
    while (frameNo < 1000){
        videoCapture.read(frame);
        frameNo++;
    }
    System.out.println(frameNo + " frames in " + (System.currentTimeMillis() - startSysMillis) + " millis");

    videoCapture.release(); // release device

    System.out.println('\n' + "Done");
}
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:37,代码来源:Frames.java

示例12: MainFrame

import org.opencv.videoio.VideoCapture; //导入依赖的package包/类
public MainFrame()
{
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    setPreferredSize(new Dimension(640, 480));

    cap = new VideoCapture(0);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            cap.release();
            System.exit(0);
        }
    });

    p = new DrawPanel();
    add(p);

    pack();

    setVisible(true);
}
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:24,代码来源:MainFrame.java

示例13: 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");
}
 
开发者ID:Plasmoxy,项目名称:AquamarineLake,代码行数:35,代码来源:HelloCV.java

示例14: 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);
		}
	}
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:43,代码来源:CvMultiCamera.java

示例15: 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;
}
 
开发者ID:Flash3388,项目名称:FlashLib,代码行数:15,代码来源:CvMultiCamera.java


注:本文中的org.opencv.videoio.VideoCapture类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。