Java Code Examples for org.opencv.highgui.VideoCapture

The following examples show how to use org.opencv.highgui.VideoCapture. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: ShootOFF   Source File: SarxosCaptureCamera.java    License: GNU General Public License v3.0 6 votes vote down vote up
public SarxosCaptureCamera(final String cameraName) {
	final List<Webcam> webcams = Webcam.getWebcams();
	int cameraIndex = -1;

	for (int i = 0; i < webcams.size(); i++) {
		if (webcams.get(i).getName().equals(cameraName)) {
			cameraIndex = i;
			break;
		}
	}

	if (cameraIndex < 0) throw new IllegalArgumentException("Camera not found: " + cameraName);

	camera = new VideoCapture();
	this.cameraIndex = cameraIndex;

}
 
Example 2
public static void loop (CascadeClassifier classifier, Mat mat, ImgWindow window, VideoCapture video) {
	video.read(mat);
	System.out.println(mat);
	if (!mat.empty()) {
		MatOfRect rects = new MatOfRect();
		long start = System.nanoTime();
		classifier.detectMultiScale(mat, rects);
		System.out.println((System.nanoTime()-start)/1000000000.0);
		window.setImage(mat);
		Graphics2D g = window.begin();
		g.setColor(Color.RED);
		for(Rect r: rects.toArray()) {
			g.drawRect(r.x, r.y, r.width, r.height);
		}
		window.end();
	}
}
 
Example 3
Source Project: HadoopCV   Source File: VideoReaderTest.java    License: Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	
	System.out.println(System.getProperty("java.class.path"));
 System.out.println(System.getProperty("java.library.path"));
 
 
	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	VideoCapture camera = new VideoCapture("data/bike.avi");
	MatOfByte frame = new MatOfByte();
	int i = 0;
	
 
	while(true){
        if (camera.read(frame)){
            System.out.println("Frame Obtained");
            System.out.println("Captured Frame Width " +
            frame.width() + " Height " + frame.height());
            System.out.println(frame.dump());
            Highgui.imwrite("tmp\\image\\camera"+(i++)+".jpg", frame);
            //Highgui.imencode(ext, img, buf)
        }else{
        	break;
        }
    }
	camera.release();
	
}
 
Example 4
public static void main (String[] args) {
	CVLoader.load();
	
	VideoCapture video = new VideoCapture(0);

	ImgWindow window = ImgWindow.newWindow();
	if (video.isOpened()) {
		Mat mat = new Mat();
		while (!window.closed) {
			loop(mat, window, video);
		}
	}
	video.release();
}
 
Example 5
public static void main (String[] args) {
	CVLoader.load();
	
	VideoCapture video = new VideoCapture(0);

	ImgWindow window = ImgWindow.newWindow();
	if (video.isOpened()) {
		Mat mat = new Mat();
		while (!window.closed) {
			loop(mat, window, video);
		}
	}
	video.release();
}
 
Example 6
public static void loop (Mat mat, ImgWindow window, VideoCapture video) {
	video.read(mat);
	if (!mat.empty()) {
		boolean result = detector.detect(mat);
		if(result) System.out.println("motion detected, " + System.nanoTime());
		window.setImage(detector.getMask());
	}
}
 
Example 7
Source Project: opencv-fun   Source File: Canny.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main (String[] args) {
	CVLoader.load();

	VideoCapture video = new VideoCapture(0);
	ImgWindow wnd = ImgWindow.newWindow();

	Mat img = new Mat();
	while (video.isOpened()) {
		video.read(img);
		loop(img, wnd);
	}
}
 
Example 8
public static void main (String[] args) {
	CVLoader.load();
	VideoCapture video = new VideoCapture(0);

	CascadeClassifier classifier = new CascadeClassifier("data/haarcascade_frontalface_alt.xml");
	ImgWindow window = ImgWindow.newWindow();
	if (video.isOpened()) {
	 	Mat mat = new Mat();
		while (!window.closed) {
			loop(classifier, mat, window, video);
		}
	}
	video.release();
}
 
Example 9
Source Project: SoftwarePilot   Source File: NativeCameraView.java    License: MIT License 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example 10
Source Project: android-object-distance   Source File: NativeCameraView.java    License: Apache License 2.0 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example 11
Source Project: marvel   Source File: NativeCameraView.java    License: MIT License 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example 12
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example 13
Source Project: ResistorScanner   Source File: NativeCameraView.java    License: MIT License 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example 14
public OpenCVCamera() {
	CVLoader.load();
	capture = new VideoCapture(0);
	while(!capture.isOpened());
}
 
Example 15
public static void loop (Mat mat, ImgWindow window, VideoCapture video) {
	video.read(mat);
	if (!mat.empty()) {
		window.setImage(mat);
	}
}
 
Example 16
Source Project: ImShow-Java-OpenCV   Source File: example.java    License: Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	/*
	 * Declare a New Frame Here -------------------------
	 */
	Imshow im = new Imshow("Video Preview");
	// This create a Window with Title Video Preview and is autoSized to the image it contains
	// or
	// new Imshow("Title",int Height,int Width); to set custom height and width 
	
	  
	 
	/* You can even Customise the ImShow Frame or Window 
	 * The image is loaded onto a JFrame which is a public member 
	 * so that anyone could customise it
	 * Imshow.Window is the JFrame that one could customise
	 * For example : 
	 * By default the Window is not Resizable so to make it resizable:
	 */
		im.Window.setResizable(true);
	// -------------------------
	Mat m = new Mat();
	VideoCapture vcam = new VideoCapture(0);
	
	// loop until VideoCamera is Available
	while (vcam.isOpened() == false)
		;

	// Bug Fix: Loop until initial image frames are empty
	while (m.empty()) {
		vcam.retrieve(m);
		
	}

	while (true) {
		
		vcam.retrieve(m);
		/***
		 * Show the image
		 */
		//System.out.println(m.dump());
		im.showImage(m);
		/************/
	}
}
 
Example 17
Source Project: effective_android_sample   Source File: NativeCameraView.java    License: Apache License 2.0 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example 18
Source Project: ShootOFF   Source File: SarxosCaptureCamera.java    License: GNU General Public License v3.0 3 votes vote down vote up
public SarxosCaptureCamera(final String cameraName, int cameraIndex) {
	if (cameraIndex < 0) throw new IllegalArgumentException("Camera not found: " + cameraName);

	camera = new VideoCapture();
	this.cameraIndex = cameraIndex;

}