org.opencv.highgui.VideoCapture Java Examples

The following examples show how to use org.opencv.highgui.VideoCapture. 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 check out the related API usage on the sidebar.
Example #1
Source File: SarxosCaptureCamera.java    From ShootOFF with 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
Source File: FaceDetectionTest.java    From opencv-fun with GNU Affero General Public License v3.0 6 votes vote down vote up
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 File: FaceDetectionTest.java    From opencv-fun with 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);

	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 #4
Source File: VideoReaderTest.java    From HadoopCV with 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 #5
Source File: Canny.java    From opencv-fun with 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 #6
Source File: MotionDetectionTest.java    From opencv-fun with GNU Affero General Public License v3.0 5 votes vote down vote up
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 File: CaptureVideo.java    From opencv-fun with 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 window = ImgWindow.newWindow();
	if (video.isOpened()) {
		Mat mat = new Mat();
		while (!window.closed) {
			loop(mat, window, video);
		}
	}
	video.release();
}
 
Example #8
Source File: MotionDetectionTest.java    From opencv-fun with 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 window = ImgWindow.newWindow();
	if (video.isOpened()) {
		Mat mat = new Mat();
		while (!window.closed) {
			loop(mat, window, video);
		}
	}
	video.release();
}
 
Example #9
Source File: NativeCameraView.java    From effective_android_sample with Apache License 2.0 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example #10
Source File: NativeCameraView.java    From SoftwarePilot with MIT License 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example #11
Source File: example.java    From ImShow-Java-OpenCV with 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 #12
Source File: CaptureVideo.java    From opencv-fun with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void loop (Mat mat, ImgWindow window, VideoCapture video) {
	video.read(mat);
	if (!mat.empty()) {
		window.setImage(mat);
	}
}
 
Example #13
Source File: OpenCVCamera.java    From opencv-fun with GNU Affero General Public License v3.0 4 votes vote down vote up
public OpenCVCamera() {
	CVLoader.load();
	capture = new VideoCapture(0);
	while(!capture.isOpened());
}
 
Example #14
Source File: NativeCameraView.java    From ResistorScanner with MIT License 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example #15
Source File: NativeCameraView.java    From Android-Car-duino with GNU General Public License v2.0 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example #16
Source File: NativeCameraView.java    From marvel with MIT License 4 votes vote down vote up
public NativeCameraFrame(VideoCapture capture) {
    mCapture = capture;
    mGray = new Mat();
    mRgba = new Mat();
}
 
Example #17
Source File: NativeCameraView.java    From android-object-distance with 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 File: SarxosCaptureCamera.java    From ShootOFF with 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;

}