[JAVA] Bureau: Manuel OpenCV une prise de vue

Goal
Manually capture webcam preview and save to folder.

TakeAPictureManual.java


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.videoio.VideoCapture;

public class TakeAPictureManual {

	static {
		System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
	}
	
	public static void main(String[] args) {
		VideoCapture camera = new VideoCapture();
		camera.open(0);
		JFrame frame1 = new JFrame("Show image");
		frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame1.setTitle("從 webcam 讀 image image arrivée balançoire Java");
		frame1.setSize(600,480);
		frame1.setBounds(0,0,frame1.getWidth(),frame1.getHeight());
		Panel panel1 = new Panel();
		frame1.setContentPane(panel1);
		frame1.setVisible(true);
		
		JButton btnCapture = new JButton("Battre");
		btnCapture.setEnabled(false);
		btnCapture.setBounds(680,97,87,23);
		frame1.getContentPane().add(btnCapture);
		
		if(camera.isOpened()) {
			final Mat webcam_preview = new Mat();
			camera.read(webcam_preview);
			frame1.setSize(webcam_preview.width()+50,webcam_preview.height()+70);
			btnCapture.setEnabled(true);
			btnCapture.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					Imgcodecs.imwrite("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\manual_take_webcam_frame.jpg ",webcam_preview);
					System.out.println("Rythme manuel");
				}
			});
			
			while (true) {
				
				try {
					camera.read(webcam_preview);
					Thread.sleep(500);
					camera.read(webcam_preview);
					Thread.sleep(500);
					camera.read(webcam_preview);
					Thread.sleep(500);
				} catch (InterruptedException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
			
				System.out.println("Machine d'ombre d'occasion");
				panel1.setimagewithMat(webcam_preview);
				frame1.repaint();
			}
			
		}else {
			System.out.println("Error");
		}
		
		
	}

}

Reault
![manual_take_webcam_frame.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/276243/4d2d58d3-911f-73ce-1529-f8898655adf6.jpeg)

Recommended Posts

Bureau: Manuel OpenCV une prise de vue
Bureau: OpenCV prend une photo
Bureau: OpenCV prend une image claire
Bureau: image de fusion OpenCV
Bureau: seuil OpenCV
Bureau: OpenCV BilateralFilterBlur
Bureau: OpenCV Dilate
Bureau: OpenCV Affine
Bureau: OpenCV Emboss
Bureau: OpenCV CLAHE
Bureau: OpenCV Ellipse2Poly
Bureau: OpenCV HDR
Bureau: OpenCV Denoise
Bureau: OpenCV Concat
Bureau: OpenCV Mosaic
Bureau: OpenCV Erode
Bureau: OpenCV Denoise
Bureau: Rectangle OpenCV
Bureau: OpenCV Watershed
Bureau: OpenCV Inpaint
Bureau: OpenCV NormalizeBlur
Bureau: OpenCV StereoSGBM
Bureau: OpenCV Spot
Bureau: OpenCV Canny
Bureau: OpenCV Denoise3
Bureau: histogramme OpenCV
Bureau: OpenCV Dft
Bureau: OpenCV Decolor
Bureau: OpenCV FaceDetector
Bureau: OpenCV Denoise2
Bureau: OpenCV StereoBM
Bureau: Changement d'éclairage OpenCV
Bureau: OpenCV Add WaterMark
Bureau: OpenCV Fill ConvexPoly
Bureau: OpenCV Grab Cut
Bureau: OpenCV Sharpness Gui
Bureau: Changement de couleur OpenCV
Bureau: Filtre Freichennel OpenCV
Bureau: seuil adaptatif OpenCV
Bureau: OpenCV Draw Circle
Bureau: OpenCV Fill Poly
Bureau: OpenCV Mean Filter
Bureau: référentiel Java OpenCV
Bureau: OpenCV Sobel Filter2
Bureau: OpenCV pyrMeanShift Filter
Bureau: Piano virtuel OpenCV
Bureau: Filtre OpenCV Scharr
Bureau: aperçu de la webcam Opencv
Bureau: Flou médian OpenCV
Bureau: OpenCV Add Broad
Bureau: OpenCV Robinson Filter
Bureau: enregistrement vidéo OpenCV
Bureau: Aplatissement de la texture OpenCV
Bureau: OpenCV Flood Fill
Bureau: espace colorimétrique OpenCV
Bureau: Filtre OpenCV SqrBox
Bureau: redimensionner l'image OpenCV
Bureau: Croquis au crayon OpenCV
Bureau: carte des couleurs OpenCV
Bureau: OpenCV Seamless Clone
Bureau: OpenCV Sobel Filter