Java Code Examples for org.opencv.videoio.VideoCapture#isOpened()

The following examples show how to use org.opencv.videoio.VideoCapture#isOpened() . 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: VideoFaceTests.java    From super-cloudops with Apache License 2.0 6 votes vote down vote up
/**
 * OpenCV-4.0.0 实时人脸识fF别
 * 
 * @return: void
 * @throws IOException
 * @date: 2019年5月7日12:16:55
 */
public static void videoFace() throws IOException {
	VideoCapture capture = new VideoCapture(0);
	Mat image = new Mat();
	int index = 0;
	if (capture.isOpened()) {
		while (true) {
			capture.read(image);
			HighGui.imshow("实时人脸识别", getFace(image));
			index = HighGui.waitKey(1);
			if (index == 27) {
				break;
			}
		}
	}
	return;
}
 
Example 2
Source File: Webcam.java    From ResCan with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String args[]) {

		System.out.println("Hello, OpenCV");
		// Load the native library.
		System.loadLibrary("opencv_java411");

		listAllVoices();
		System.setProperty("freetts.voices", "com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
		VoiceManager voiceManager = VoiceManager.getInstance();
		voice = voiceManager.getVoice("kevin16");
		voice.allocate();

		camera = new VideoCapture(0);

		if (!camera.isOpened()) {
			System.out.println("Camera Error");
			}
		else {
			System.out.println("Camera OK?");
		}


		while (camera.isOpened()) {
			Mat frame = new Mat();



			// camera.grab();
			// System.out.println("Frame Grabbed");
			// camera.retrieve(frame);
			// System.out.println("Frame Decoded");

			camera.read(frame);
			Core.flip(frame, frame, -1);

			/*
			 * No difference camera.release();
			 */

			// System.out.println("Captured Frame Width " + frame.width());

			doMagic(frame);
			showResult(toBufferedImage(frame));

			/*
			 * try { Thread.sleep(10); } catch (InterruptedException e) { //
			 * TODO Auto-generated catch block e.printStackTrace(); }
			 */
		}
	}